updateFromXML and UserData

I have a grid which is being reloaded based on row selection in another grid in the same webpage. I’m making use of UserData to track additional required params for each row, but I understand that UserData is NOT refreshed when calling updateFromXML().



My code is something like this right now, but what is the proposed way of getting around this behaviour?



grid2.attachEvent(“onRowSelect”,

        function(src_id) {

            asset.updateFromXML(“load.php?item_id=”+src_id, true, true);

        });



Calling loadXML() again like below doesnt update my grid, and doesn’t alter UserData.



grid2.attachEvent(“onRowSelect”,

        function(src_id) {

            asset.loadXML(“load.php?item_id=”+src_id);

        });



Thanks for your help,

Matt

but I understand that UserData is NOT refreshed when calling updateFromXML().
yes, this is known limitation. Operation purposed to updates cell values, it will not change existing userdata.
Technically, it possible to extend existing functionality with few lines of custom code
dhtmlxgrid.js , line 4711
var rows = xml.doXPath("//row");
for (var i = 0; i < rows.length; i++){

can be replaced with

var rows = xml.doXPath("//row");
for (var i = 0; i < rows.length; i++){
var udCol = xml.doXPath("./userdata", rows[i]);
for (var i = udCol.length-1; i >= 0; i–)
this.setUserData(rows[i].getAttribute(“id”),udCol[i].getAttribute(“name”), udCol[i].firstChild ? udCol[i].firstChild.data : “”);




>>Calling loadXML() again like below doesnt update my grid, and doesn’t alter UserData.
most probably it need to be as
grid2.attachEvent(“onRowSelect”,
function(src_id) {
asset.clearAll();
asset.loadXML(“load.php?item_id=”+src_id);
});

Thanks for your code snippet. I have settled on the following code for anyone who also experiences this problem.

Starting line 4720, ending line 4732:

var rows = xml.doXPath("//row");

this.UserData=[];    //optionally clear current UserData

for (var i = 0; i < rows.length; i++){
    var row = rows[i];

    //include UserData
    var udCol = xml.doXPath("./userdata", row);
    for (var j = udCol.length-1; j >= 0; j–)
        this.setUserData(row.getAttribute(“id”), udCol[j].getAttribute(“name”), (udCol[j].firstChild?udCol[j].firstChild.data:""));

    var id = row.getAttribute(“id”);


As a further extension to this issue, how can I extract the global UserData from incoming XML? The current modification we have detailed will extract row level UserData, but not anything which would end up in “gridglobaluserdata”. Thanks again…

In the same place, one more block of code can be added

var udCol = xml.doXPath("/rows/userdata");
for (var j = udCol.length-1; j >= 0; j–)
this.setUserData("", udCol[j].getAttribute(“name”), (udCol[j].firstChild?udCol[j].firstChild.data:""));
for (var i = 0; i < rows.length; i++){

the only difference - doXPath executed against top “rows” element, instead of “row”

Great, thanks. The trick here is in the XPath syntax - “./” is being applied local to the row object thrown into doXPath(), and then getting global UserData is done with an absolute path… Obvious really!

So again for anyone who finds this thread useful, here’s my full code snippet:

Starts line 4720, ends line 4737.

var rows = xml.doXPath("//row");

this.UserData=[];    //optionally clear current UserData

//mafro- include global UserData
var udCol = xml.doXPath("/rows/userdata");
for (var j = udCol.length-1; j >= 0; j–)
    this.setUserData("", udCol[j].getAttribute(“name”), (udCol[j].firstChild?udCol[j].firstChild.data:""));

for (var i = 0; i < rows.length; i++){
    var row = rows[i];

    //mafro- include UserData
    var udCol = xml.doXPath("./userdata", row);
    for (var j = udCol.length-1; j >= 0; j–)
        this.setUserData(row.getAttribute(“id”), udCol[j].getAttribute(“name”), (udCol[j].firstChild?udCol[j].firstChild.data:""));

    var id = row.getAttribute(“id”);