Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tim on Sep 12, 2008 18:27
open dhtmlx forum
Reloading data using updateFromXML

I was reading on refreshing data and came across the thread at http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=4583&ssr=yes&s=reload%20order. It mentions using updateFromXML() instead of clearAll() and loadXML() so the order of the data doesnt change.

The problem Im having is similar. I have data sorted in a particular way, and when a change is made to the data, I need to reload the data with the same ordering. If a row in the data was deleted, though, when I call updateFromXML(), the deleted row doesnt actually get removed from the grid, even though the XML no longer has that row in it. So it looks like updateFromXML() refreshes data for any row in the grid but doesnt remove rows in the grid that are no longer in the XML data?

If that is the case, I can call clearAll() and loadXML(), but is there a way to pass along the *current* orderby setting? I couldnt find a way to get that property.

Tim
Answer posted by Support on Sep 15, 2008 01:44
If you want to delete rows from the grid which are not presented in the "update" xml, you should call updateFromXML method with true as the third parameter (the second one add new rows to the grid):

grid.updateFromXML(url,false,true);

Answer posted by Tim on Sep 15, 2008 06:07
That doesnt seem to work for me. Here is what happens.

My grid loads with 4 rows. I have another button (off grid) that deletes a record (essentially deletes a row that would appear in the grid), and then reloads the grid to reflect the new data. When i changed it to mygrid.updateFromXML(myurl,false,true), the data refreshed, but it did not do so correctly.

Before the deletion, my grid looked like this (one column for brevity):

Andrews, Thom
Smith, John
Tang, Wan

After the delete of Tang, Wan, my grid looks like this:

Andrews, Thom
Smith, John
Smith, John

I looked at the updateXML coming back after the delete, and there are only 2 rows -- Andrews and Smith -- so the third row in the grid is somehow taking on a repeat of the second row. See the attached file -- I deleted the 3rd row in the grid, and when it updated, it had the same information as the 2nd row.

Also, I changed the second argument in the function to true, so it said updateFromXML(url,true,true) to catch any additions to the data, and whenever I added data that should appear in the grid, the XML showed it correctly but the grid never showed the new row.

Attachments (1)
group.gif2.12 Kb
Answer posted by Support on Sep 16, 2008 01:51
Please, check if ids in the new xml are the sample the ids in the original one.

We have sent the sample by e-mail.
Answer posted by Tim on Sep 16, 2008 07:00
I never received an attachment.

Regardless, I corrected the bug in the XML that had wrong row IDs -- thats for catching that.

Is this the expected behavior, though? When a new row is added to the grid (when the data changes and I call updateFromXML(myurl,true,true)), it appears as the last row in the grid, no matter how my grid is currently sorted.

I also get a Javascript error now. Same situation as before... 4 rows in the grid. One row is deleted on the backend. I call updateFromXML(myurl,true.true) to catch any changed data. The data reloads (this time using a GET instead of POST like all other calls have been). The deleted row does not appear, and no rows are duplicated. The XML data contains only 3 rows. BUT... I get a javascript error caused by the updateFromXML call. The error is:  "f is null" in dhtmlxgrid.js line 856. It also looks like my onXLE function did not run. When I comment out all code in my onXLE function, nothing changes--still get the javascript error.

So Im giving up on updateFromXML(). In case anyone else is interested, here is my custom reloadGrid() function that takes into account the current sort order:

function reloadGrid() {
     var prevSort = mygrid.getSortingState();
     mygrid.clearAll();
     if (prevSort.length==2) mygrid.loadXML(myurl+"&orderby="+prevSort[0]+"&direct="+prevSort[1]);
     else mygrid.loadXML(myurl);
}

I am running dhtmlxGrid v.1.6 Professional edition build 80512/80603/60610.

Tim


Answer posted by Support on Sep 18, 2008 02:53
Have you received the sample ?

>>Is this the expected behavior, though? When a new row is added to the grid (when the data changes and I call updateFromXML(myurl,true,true)), it appears as the last row in the grid, no matter how my grid is currently sorted.

You can try to use the following approach to change added row position:

mygrid.updateFromXML('new.xml',true,true,doAfterUpdate)

function doAfterUpdate(){
    var arr=mygrid.getSortingState();
     mygrid.sortRows(arr[0],false,arr[1])
}
getSortingState returns array of sorted column and its state.
>> One row is deleted on the backend. I call updateFromXML(myurl,true.true) to catch any changed data. The data reloads (this time using a GET instead of POST like all other calls have been). The deleted row does not appear, and no rows are duplicated.

The issue can not be reconstructed locally - all "update" requests use GET.
In the problem persists, please, contact us  at the support@dhtmlx.com and provide any sample where we can reconstruct  the issue.