Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Alfonso Ortiz on Mar 06, 2009 08:21
open dhtmlx forum
update grid from XML received from server request (not parse)

Good Day!

Is there any way to update grid from xml received from response sent by server?

I know there are 2 ways:

- mygrid.parse(responseXML);
- mygrid.updateFromXML(url);

I like more the first because can be used with AJAX response generated by the server.
But it does not work for me because it does not preserve the previous status of the grid.
So, if you want to keep the current status of the grid you use updateFromXML(url); BUT it expects an url, not a string with the XML received...

So, is there any way to make updateFromXML works with XML string received instead of passing an url as parameter?
something like mygrid.updateFromXML(responseXML)

Thanks!!!
Answer posted by dhxSupport on Mar 06, 2009 09:05

You can use:

mygrid.clearAll();

mygrid.parse(xmlString);

Please see example here

http://dhtmlx.com/docs/products/dhtmlxGrid/samples/initialization_loading/init_grid_xml.html

Answer posted by Alfonso Ortiz on Mar 06, 2009 09:29
Mmm I think that does not resolve my problem.
The problem is: with parse you LOSE the current status of the grid (selected row, selected cell, etc) because somewhat it is cleared and loaded again.

Let me explain a little bit the context.
I have a grid with some formulas in the rows that are calculated on the server side. So I need to get the reconstructed grid ALWAYS because of that.
No problem, the script on the server that generates the XML string also makes the changes and always answer with the XML string considering the changes.
I use the doOnCellEdit function to make an AJAX call to the server to submit the changes. Then, the server answers with new XML string of the grid and the changes submitted done.

Suppose that I edit a cell and press enter. Then it goes all the way through server and back when ready. Then, I must refresh the grid with the changes made (the recalculated formulas) AND preserve the current selected cell because the user may have pressed ENTER or TAB or something like that.
If I use PARSE, it does everything alright, BUT, there is no more selected row or selected cell... I need to keep the cell selected.

So, using updateFromXML does the update thing alright AND keeps the cell selected and the grid is ready to let the user move freely through the grid again from where it was the last time that made a change.
The problem, is that I must make a new request (go again to the server) to get the XML String because updateFromXML does the things this way...

Is there any workaround for this?

Thanks for answering!!



Answer posted by Support on Mar 09, 2009 05:06
While updateFromXML oriented on loading data from remote url, it can be tricked to load data through  parse command. 
You can use next code

 grid._refresh_mode=[true,insert_new,del_missed]; //2nd and 3rd parameters are the same as in updateFromXML command 
 grid.parse(data);

after setting _refresh_mode structure , any next data loading command will be counted as update operation.
Answer posted by Alfonso Ortiz on Mar 09, 2009 07:57
Great!!!

That did the job!!

I do not know if there are other people with this "problem" so there could be a direct implementation of this parsing thing through updateFromXML in a future version of Grid...
Anyway thanks for the quick trick!