Hi,
I am setting user data in a grid, and it works fine when I initialize from script and manually set the user data values. However, I subsequently do an ajax call and update the grid like so:
grid.clearAll();
grid.parse(listData.xmlDoc.responseXML);
When i do:
rowFileId= grid.getUserData(0, “fileId”);
The value rowFileId is always empty, but it works fine for all other rows!! Here is the xml that was parsed:
<?xml version="1.0" encoding="utf-8"?>
smrreport.xml
5K
Delete^javascript:clickLink_defaultForm_manageFilesPage_master_fileInfo_fileSetItems_deleteLink(0)^_self
10267
testreporta.xml
5K
Delete^javascript:clickLink_defaultForm_manageFilesPage_master_fileInfo_fileSetItems_deleteLink(1)^_self
10269
the one ii.txt
1K
Delete^javascript:clickLink_defaultForm_manageFilesPage_master_fileInfo_fileSetItems_deleteLink(2)^_self
10268
I even tried manually setting the user data using this code, and I had the same result:
function setUserDataFromXML(gridElem, xmlObj){
var root = xmlObj.getElementsByTagName(‘rows’)[0];
var rows = root.getElementsByTagName(‘row’);
for (var i = 0 ; i < rows.length ; i++) {
var row = rows[i];
var rowId= row.getAttribute(“id”);
var dataVals = row.getElementsByTagName(‘userdata’);
for (var j = 0 ; j < dataVals.length ; j++) {
var dataVal = dataVals[j];
// now we have the item object, time to get the contents
// get the name of the item
var name = dataVal.getAttribute(‘name’);
// get the value
var value = ‘’;
if (dataVal.firstChild) value= dataVal.firstChild.nodeValue.replace(/^\s+|\s+$/g, ‘’);
gridElem.setUserData(rowId,name, value);
alert("Set userdata: " + rowId + ", " + name + ", " + value);
}
}
}
Method getUserData() has parameters: row_id - row id (not row index), name - name of user data.
In you case should be:
rowFileId= grid.getUserData(“0”, “fileId”);
To get row ID by row index you can use: mygrid.getRowId(ind)
Aha, thanks that worked. I WAS passing the rowIds, but as a Number. I was actually passing a variable named ‘id’ to the function, which contained a numeric version of the rowId.
rowFileId= grid.getUserData(id, “fileId”);
I changed it to:
rowFileId= grid.getUserData(String(id), “fileId”);
And it works fine! Thanks again.
JS has no strict type , so 0 can be counted the same as null in some cases, which may cause problem
It will be more safe not use such IDs as 0, null, false