EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: wolfnbasti on April 16, 2014, 09:33:21 PM



Title: How can I capture the cell value from edatagrid?
Post by: wolfnbasti on April 16, 2014, 09:33:21 PM
I need to capture the cell value from an instance of edatagrid so I can save it via javascript to a server side REST process. How can I capture the new row values and the edited existing row values into a var?

Thanks.


Title: Re: How can I capture the cell value from edatagrid?
Post by: stworthy on April 17, 2014, 06:21:06 AM
Please call 'getRows' method to get a specified row.
Code:
var index = ...  // the row index
var row = $('#dg').datagrid('getRows')[index];
console.log(row);  // the row data


Title: Re: How can I capture the cell value from edatagrid?
Post by: wolfnbasti on April 21, 2014, 03:56:29 PM
This is what I did to get the value I needed when adding a new row:

$('#dg').edatagrid('endEdit',newRowIndex);
rowAdd = JSON.parse(JSON.stringify($('#dg').edatagrid('getRows',newRowIndex)));
var newValue =  rowAdd[newRowIndex].columnNameWhatever;

However, when trying something similar for editing an existing row I can't seem to capture the edited row index, let alone any of the changed values. It almost seems that when I click my save feature, which for testing purposes just generates an alert pop-up, it isn't recognizing that I'm ending the edit.

When I first double click a row to edit, I probably I need to capture the row number at that time, and when I'm done editing signal the end edit process and capture the values. Do you have any ideas?

Thanks.


Title: Re: How can I capture the cell value from edatagrid?
Post by: stworthy on April 21, 2014, 05:31:12 PM
If you are using edatagrid plugin to create a basic crud application, you don't care about how to save or edit a row, what you need to do is to set the 'url','saveUrl','updateUrl' and 'destroyUrl' properties.
Code:
$('#tt').edatagrid({
    url: ...,
    saveUrl: ...,
    updateUrl: ...,
    destroyUrl: ...
});


Title: Re: How can I capture the cell value from edatagrid?
Post by: wolfnbasti on April 22, 2014, 06:04:25 AM
I can't use that process because we are using javascript to talk to a server side REST process. So, I need to capture the edited cell index and the edited values and then pass the changes to our established REST process.

I think if I can capture the cell index as soon as editing starts, I'm guessing when a cell is double-clicked I can then capture the changes made to the cell.

Thanks.


Title: Re: How can I capture the cell value from edatagrid?
Post by: stworthy on April 22, 2014, 07:39:17 AM
When double click a row to start editing, the 'onEdit' event fires. You can use it to get the current editing row index.
Code:
$('#dg').edatagrid({
  onEdit: function(index,row){
    console.log(index);
  }
});