EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: ftmh on February 09, 2014, 05:04:51 AM



Title: how to save inline editing in database
Post by: ftmh on February 09, 2014, 05:04:51 AM
hello every body:
how can save the inline editing ,please refer to this page :

http://jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem=

the accept button just save the data in client side not send to data base! how can i do that?

thanks.....  ;D


Title: Re: how to save inline editing in database
Post by: arma on February 09, 2014, 11:07:36 AM
Hi, this might help:

Code:
var grid = $('#mygrid');

//Commit any row changes
if (grid.datagrid.endEdit()) {
    grid.datagrid('acceptChanges');
}

var items = grid.datagrid('getRows'); //Get all grid rows and submit as array
$.post('url/to/save', {items: items}, function(r){
   if(r=='success'){
     //Response success code here
   }else{
     //Response Error here
   }
});

In php you simply can get the data with $_POST['items']. It's array so you can loop it to save to database.

Code:
$items = $_POST['items'];
foreach ($items as $key => $item) {
 //Process insert to table here $item['product'], $item['price'] and so on
}

echo 'success'; //Inform status back to browser


Title: Re: how to save inline editing in database
Post by: ftmh on February 09, 2014, 11:38:29 PM
thanks, but is hat make JSON code to send data?