3.2.0

example php update database with changed grid information

Hello,

I was searching through the forum, looking for an example how to update the changed information in the grid to the MySQL database.
There was a nice example how to do this using the updateSingeCell.php example.
However, this updates the changed information without giving the user the chance to choose. And you must have a second page that handles the posted information.

So I took some information I found in the forums and wrote a nice example how to update the information after clicking a save button.
This is something many users of AW-grid are looking for, so I hope this will help you a lot.

When a user clicks a save button, through javascript we check first if something has been changed. If not, an alert is raised, to inform the user that nothing has been changed.
If something has been changed, the user gets a question if he wants to save the changes or not. Only if he presses yes, the information is posted to the server.

In fact, it's very simple.
We create an empty javascript array. If a cell is changed in the grid, this information is stored in the array. When the user wants to save the information, this javascript array will be transformed into a hidden form. The elements in the array will be hidden fields. This form will then be posted to the same page, so you can use the posted information like you are used to do with a normal form.
The advantage is that the hidden form is created on the clients pc, so it goed fast and only the updated rows are posted, not the complete grid.

To make it easy, you can download the sample trough : http://applications.softswoon.com/aw/demo_update_grid.zip
Also the sql file is included, to create the demo database that is used in the example.

Have fun with it.
Dries GERIS
Dries GERIS
August 17,
Hi Dries,
Thanks for posting this. Very useful.

One small issue - I could not get the demo to save anything to the db unless at least one of the fields in the "hidden" form was not hidden.

Any idea why this would be?
Giles
September 19,
Hi Dries,
Very very helpful . I have been agonising over this for a while.
October 9,
Hi Dries,
Very very helpful . I have been agonising over this for a while.



Kitonyo
Kitonyo
October 9,
Hello Giles,

When you unhide one of the hidden fields in the form, does it then save all the content in the form, or only the content of the unhided field?

Normaly it should update all the information. This is, when the information is posted correctly.

have you tried to add this on top of the demo page :

if (isset($_POST)){
print_r($_POST);
}

When all the fields are hided, does it send the form (does it execute the javascript)?
If so, then something will be posted and with the code above you can check what is posted. Maybe there something wrong in the posted information.

regards,
Dries
October 22,
Don't work in firefox. in localhost
seba
October 30,

This topic is archived.

See also:


Back to support forum