EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: neatgadgets on December 19, 2016, 11:02:38 AM



Title: Single field with datagrid
Post by: neatgadgets on December 19, 2016, 11:02:38 AM
I want to have a datagrid where I go through and tick on and off items, than give this selection a name and save it to the database. How can I add a field at the topas a name, with a button to save (insert all the ticked items as rows in a table with the field name)?

Andrew

e.g.

Selection Field Name: MySelection

A          B  C Selected
Fred      0   1 Tick
Barney  1   3 Unticked
Wilma   2   1 Tick


So rows Fred and Wilma are saved with the name "MySelection" into a table


Title: Re: Single field with datagrid
Post by: jarry on December 19, 2016, 04:59:41 PM
If the ticked row is the selected row, you can call 'getSelections' method to get all the selected rows and then post them to the server.
Code:
var rows = $('#dg').datagrid('getSelections');
var datastr = JSON.stringify(rows);
// post them
$.post('...', {fieldname: datastr}, function(result){
});


Title: Re: Single field with datagrid
Post by: neatgadgets on December 20, 2016, 12:46:31 AM
Thanks, does that mean I can include a form on the datagrid and pass the name of the selected list as well?


Title: Re: Single field with datagrid
Post by: jarry on December 20, 2016, 07:46:21 PM
The form field values are combined by name-value pairs. But what you want is to post all the selected rows, so you just need to serialize these rows and post to server. In your server side, you should unserialize to restore the rows.


Title: Re: Single field with datagrid
Post by: neatgadgets on December 22, 2016, 04:25:11 PM
So what I want to do is like this

Code:
			var rows = $('#dg').datagrid('getSelections');
var datastr = JSON.stringify(rows);
var posting = $.post( url, { dg: datastr, charter_type: $('#charter_type').val() } );

Only when I try and read it on the php page called I get Undefined index: dg

Code:
$dg = $_REQUEST['dg'];
$obj = json_decode($dg);
$activity_code = $obj['activity_code'];
$description = $obj['description'];
$amount = $obj['amount'];
$unit_of_measurement = $obj['unit_of_measurement'];
$quantity = $obj['quantity'];
$hours = $obj['hours'];
$charter_type = $_REQUEST['charter_type'];

Yet the charter_type came through