EasyUI Forum
May 06, 2024, 10:26:11 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Single field with datagrid  (Read 4774 times)
neatgadgets
Newbie
*
Posts: 3


View Profile Email
« 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
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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){
});
Logged
neatgadgets
Newbie
*
Posts: 3


View Profile Email
« Reply #2 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?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 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.
Logged
neatgadgets
Newbie
*
Posts: 3


View Profile Email
« Reply #4 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

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!