Hi there
I am trying to keep track of modified rows of the WebDataGrid. The following discussion http://ko.infragistics.com/community/forums/t/67651.aspx implies that IsDirty() method of GridRecord is not going to work. So to keep track of the modified values I have added a hidden data bound column to the grid – bound to ‘Status’ property of the record and implemented EditingClientEvents-CellValueChanging event handler on the client side. The event handler sets a value in the hidden column. On the server side, when a "Save" button is pressed on a form, I iterate trough the WebDataGrid rows, check the value of the ‘Status’ property and save the records that are added or modified.
The event handler for CellValueChanging looks like this:
function updateEntityState_OnChange(sender, eventArgs) {
for (i = 0; i < eventArgs._cell._row._element.cells.length; i++)
{
if (sender._columns._items[i]._key == 'Status') {
var status = eventArgs._cell._row._element.cells[i].firstChild.nodeValue;
if (status == null) {
eventArgs._cell._row._element.cells[i].firstChild.nodeValue = 2/*Added*/;
}
else if (status == 0/*Unchanged*/) {
eventArgs._cell._row._element.cells[i].firstChild.nodeValue = 1/*Modified*/;
break;
The implementation above does not work. When I step though the code in the debugger everything looks fine but the when I check the row on a server a value in “Status” column is always 0.
I have three questions here:
Thank you
Boris
Hello boris_qbf,
First of all you should note that since hidden fields do not render on the client, hence their values are not accessible there and could not be modified. Also using of private properties/methods in the client events is not recommended. I would suggest you in the current scenario if you want to check whether there are changes made to the grid and based on that update the value of the hidden field, to handle RowUpdating server side event. For instance the following code checks if changes are made to the "Name" column in the grid and updates the "Status" column value and also makes this column visible:
protected void WebDataGrid1_RowUpdating(object sender, Infragistics.Web.UI.GridControls.RowUpdatingEventArgs e) { DataTable dt = populateGrid(); if (e.Values["Name"] != e.OldValues["Name"]) { e.Row.Items[2].Column.Hidden = false; dt.Rows[e.Row.Index]["Status"] = "modified"; WebDataGrid1.DataSource = dt; WebDataGrid1.DataBind(); } }
protected void WebDataGrid1_RowUpdating(object sender, Infragistics.Web.UI.GridControls.RowUpdatingEventArgs e)
DataTable dt = populateGrid();
if (e.Values["Name"] != e.OldValues["Name"])
e.Row.Items[2].Column.Hidden = false;
dt.Rows[e.Row.Index]["Status"] = "modified";
WebDataGrid1.DataSource = dt;
WebDataGrid1.DataBind();
Attached is a sample with similar scenario for your reference.
If you have any further questions, feel free to contact me.
Sincerely,
Tsanna
Hi Tsanna
Thank you for the reply. Just for my own testing I have temporarily "un-hide" my Status column - just to get some visual feedback. I did not make any difference. I can't see the value changed neither on the screen nor in the bound data. I don't believe that it is not possible to implement client-side change to a value in some cell when a value in another cell is changing. Just to reiterate - the "Status" column is auto-generated databound column.
We are converting our application from Infragistics 10.3 Ultragrid to 13.2 WebDataGrid and any solution that would require substantial code refactoring is not acceptable as we have more than a 100 quite complex forms in our application. Also if we follow your example we would need to process a postback on every row change. It would require extra database operations and would make roll-back/cancel changes quite hard to implement.
You have mentioned that using private methods in the event handler is not advisable. What is the advisable method then?
So could you please supply a working example of client-side event handler that is updating a value in another cell?
Regards
As per your requirement I modified my previous sample to change the "Status" column cell on changing another cell value in the same row using client side CellValueChanging event.
For preventing postback on every cell update, I would suggest you to use BatchUpdating property of the EditingCore. If you enable it, then all updates will be batched on the client until postback occurs. Please refer to our documentation for more information about BatchUpdating: http://help.infragistics.com/doc/ASPNET/2014.1/CLR4.0/?page=WebHierarchicalDataGrid_Batch_Updating_Enabling.html
I'm attaching you a sample with similar scenario for your reference.
Thank you Tsanna.
It almost worked :). From the code behind I was not able to retrieve cell text set by cell.set_text() on client side. I have changed set_text() to set_value() and it worked. I had to add an extra condition to prevent recursive call of the event handler:
if (eventArgs.get_newValue() != eventArgs.get_currentValue() && eventArgs.get_cell().get_column().get_key() != 'Status')
currentRow.get_cell(statusSelIndex).set_value("1");
The good thing is that this method works even if the column is hidden - which acheives exactly what I was after.
Thanks again
Thank you for your feedback.
If you need any further assistance regarding this matter, please let me know.