This topic is locked

How to update status of record in on click on the List page

5/11/2015 4:42:13 PM
PHPRunner Tips and Tricks
Sergey Kornilov admin

You work with invoices table and need quick visual cues that tell if invoice was paid or not. Besides that, you need to mark invoices as paid quick, without switching to inline edit mode. We'll show ou how to do that with single mouse click. This is how it looks in generated application.


Sample database structure. Table 'invoices'. Fields:

id - int, primary key

amount - decimal

status - varchar (holds values like 'paid' or 'not paid').


Our goal is to display 'paid' invoices with amount in green and also a green icon next in 'Paid' column. Unpaid invoices will feature a red icon which you can click to mark the invoice as paid.

  1. Set 'View as' type of 'status' field to 'Custom' and use the following code there. In this code we check the current value of 'status' field and display either green or red icon. Notice, that red icon is also wrapped into a hyperlink that issues an AJAX call to save-status.php file. This is how we update the status of the record behind the scene.
    Image files need to be stored in 'images' folder under output directory.

if ($data["status"]!='paid')

$value="<a href=# onclick='$.post( \"save-status.php\", { id: ".$data["id"]." } );$(this).children(\"#image\").attr(\"src\",\"images/ok.png\");

$(this).closest(\"td\").prev(\"td\").css(\"background\",\"#CFFFCF\");'>

<img src=images/notok.png id='image'></a>";

else

$value="<img src=images/ok.png id='image'>";


2. AfterRecordProcessed event of Invoices table

if ($data["status"]=='paid')

$record["amount_css"]='background: #CFFFCF;';


In this code we change background of those amount cells that belong to paid invoices.
3. Create a file named save-status.php in the output folder and put the following code there:

<?php
include("include/dbcommon.php");

if ($_POST["id"]) {

CustomQuery("Update invoices set status='paid' where id=".$_POST["id"]);

}

?>


Here is how it looks in action:


And here are sample icons you can download:



O
OLDmrcaseyman 10/26/2015

Using this idea, would it be possible to edit a field directly by clicking it? For example, clicking on the YearofMake field on any row makes that field editable. Changing the model year is automatically saved upon exiting.



You work with invoices table and need quick visual cues that tell if invoice was paid or not. Besides that, you need to mark invoices as paid quick, without switching to inline edit mode. We'll show ou how to do that with single mouse click. This is how it looks in generated application.

Sample database structure. Table 'invoices'. Fields:

id - int, primary key

amount - decimal

status - varchar (holds values like 'paid' or 'not paid').


Our goal is to display 'paid' invoices with amount in green and also a green icon next in 'Paid' column. Unpaid invoices will feature a red icon which you can click to mark the invoice as paid.

  1. Set 'View as' type of 'status' field to 'Custom' and use the following code there. In this code we check the current value of 'status' field and display either green or red icon. Notice, that red icon is also wrapped into a hyperlink that issues an AJAX call to save-status.php file. This is how we update the status of the record behind the scene.
    Image files need to be stored in 'images' folder under output directory.

if ($data["status"]!='paid')

$value="<a href=# onclick='$.post( \"save-status.php\", { id: ".$data["id"]." } );$(this).children(\"#image\").attr(\"src\",\"images/ok.png\");

$(this).closest(\"td\").prev(\"td\").css(\"background\",\"#CFFFCF\");'>

<img src=images/notok.png id='image'></a>";

else

$value="<img src=images/ok.png id='image'>";


2. AfterRecordProcessed event of Invoices table

if ($data["status"]=='paid')

$record["amount_css"]='background: #CFFFCF;';


In this code we change background of those amount cells that belong to paid invoices.
3. Create a file named save-status.php in the output folder and put the following code there:

<?php
include("include/dbcommon.php");

if ($_POST["id"]) {

CustomQuery("Update invoices set status='paid' where id=".$_POST["id"]);

}

?>


Here is how it looks in action:


And here are sample icons you can download:




Tandy 1/14/2016

This does not work for me?

I get the icon to show and I can even edit it and have the other icon to show. But when I click on it in the list page. The page just refreshes and does not get marked as paid? my table is Trips and my field is trip_paid.

My list page code is in view as and custom:

if ($data["trip_paid"]!='paid')

$value="<a href=# onclick='$.post( \"save-status.php\", { id: ".$data["id"]." } );$(this).children(\"#image\").attr(\"src\",\"images/ok.png\");

$(this).closest(\"td\").prev(\"td\").css(\"background\",\"#CFFFCF\");'>

<img src=images/notok.png id='image'></a>";

else

$value="<img src=images/ok.png id='image'>";


My List Page After Record Processed of Trips Table is:

if ($data["trip_paid"]=='paid')

$record["amount_css"]='background: #CFFFCF;';


Then my created a file named save-status.php and located in the output folder is:

<?php
include("include/dbcommon.php");

if ($_POST["id"]) {

CustomQuery("Update trips set trip_paid='paid' where id=".$_POST["id"]);

}

?>


Did I do something wrong?

Thanks for your help..

Sergey Kornilov admin 1/14/2016

Tandy Services,
hard to tell what might be wrong without seeing all project files and database. If you need more help feel free to upload your project to Demo Account and contact support directly.

O
onlline 5/6/2016



Tandy Services,
hard to tell what might be wrong without seeing all project files and database. If you need more help feel free to upload your project to Demo Account and contact support directly.


also does not work for me,
http://demo.asprunner.net/leonardo_onlline_com_br/paids/invoices_list.php#
thank you .

O
onlline 5/7/2016



Tandy Services,
hard to tell what might be wrong without seeing all project files and database. If you need more help feel free to upload your project to Demo Account and contact support directly.


also does not work for me,
http://demo.asprunner.net/leonardo_onlline_com_br/paids/invoices_list.php#
thanks in advanced .

U
ustunsoz 7/28/2019

In my case, my field value "amount" is changing after changing status. But I couldn't refresh the row even I put the refresh grid script in JavaScript on load event. Is there any way to refresh "amount" after changing status???

Tandy 3/9/2021



This does not work for me?

I get the icon to show and I can even edit it and have the other icon to show. But when I click on it in the list page. The page just refreshes and does not get marked as paid? my table is Trips and my field is trip_paid.

My list page code is in view as and custom:

if ($data["trip_paid"]!='paid')

$value="<a href=# onclick='$.post( \"save-status.php\", { id: ".$data["id"]." } );$(this).children(\"#image\").attr(\"src\",\"images/ok.png\");

$(this).closest(\"td\").prev(\"td\").css(\"background\",\"#CFFFCF\");'>

<img src=images/notok.png id='image'></a>";

else

$value="<img src=images/ok.png id='image'>";


My List Page After Record Processed of Trips Table is:

if ($data["trip_paid"]=='paid')

$record["amount_css"]='background: #CFFFCF;';


Then my created a file named save-status.php and located in the output folder is:

<?php
include("include/dbcommon.php");

if ($_POST["id"]) {

CustomQuery("Update trips set trip_paid='paid' where id=".$_POST["id"]);

}

?>


Did I do something wrong?

Thanks for your help..



Ok after coming back to this I got it to work some. It changes but refreshes to the welcome page instead of staying put. Here is my new codes.
I had to change my checkbox I had to varchar and made it a edit as lookup wizard with paid and not paid. My list page code is in view as custom:



if ($data["trip_paid"]!='paid')

$value="<a href=# onclick='$.post( \"save-status.php\", { trip_id: ".$data["trip_id"]." } );

$(this).children(\"#image\").attr(\"src\",\"images/ok.png\");

$(this).closest(\"td\").prev(\"td\").css(\"background\",\"#CFFFCF\");'>

<img src=images/notok.png id='image'></a>";

else

$value="<img src=images/ok.png id='image'>";


My List Page After Record Processed of Trips Table is:



if ($data["trip_paid"]=='paid')

$record["trip_number_css"]='background: #CFFFCF;';


Then my created a file named save-status.php and located in the output folder is:



<?php

include("include/dbcommon.php");

if ($_POST["trip_id"]) {

CustomQuery("Update trip_sheet set trip_paid='paid' where trip_id=".$_POST["trip_id"]);

}

?>



As I said it works but once I click to change to paid it auto loads up as my menu screen in stead of letting me click more.
Thanks for any help..

James

Tandy 3/9/2021

Ok, Think I figured it out. In the List Page Code. I changed the href=# to href=/trip_sheet_list.php and it seems to work right now. I don't know if that is what I was to do, but it does work.

fhumanes 3/9/2021

Hello "Tandy Services",
I suggest you read the solution that facilitated "ACPAN" and that left us in this article:

https://asprunner.com/forums/topic/27641-free-plugins-for-phprunner-10-x/pagest15
I think it fits what you need using the Plgin "switch".
You can see an example at: https://fhumanes.com/switch/prueba_plugin11_list.php
And you can download the example from my portal: https://fhumanes.com/blog/actualizacion-plugin-switch-y-ejemplo/
Greetings,

Fernando.