Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Mike H on Feb 25, 2009 19:32
open dhtmlx forum
User Data is missing in FIRST ROW only

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"?>

    <rows >
        <row id="0" >
            <cell ></cell>
            <cell >smrreport.xml</cell>
            <cell >5K</cell>
            <cell >Delete^javascript:clickLink_defaultForm_manageFilesPage_master_fileInfo_fileSetItems_deleteLink(0)^_self</cell>
            <userdata name="fileId" >10267</userdata>
            <userdata name="fileSetId" ></userdata>
        </row>
        <row id="1" >
            <cell ></cell>
            <cell >testreporta.xml</cell>
            <cell >5K</cell>
            <cell >Delete^javascript:clickLink_defaultForm_manageFilesPage_master_fileInfo_fileSetItems_deleteLink(1)^_self</cell>
            <userdata name="fileId" >10269</userdata>
            <userdata name="fileSetId" ></userdata>
        </row>
        <row id="2" >
            <cell ></cell>
            <cell >the one ii.txt</cell>
            <cell >1K</cell>
            <cell >Delete^javascript:clickLink_defaultForm_manageFilesPage_master_fileInfo_fileSetItems_deleteLink(2)^_self</cell>
            <userdata name="fileId" >10268</userdata>
            <userdata name="fileSetId" ></userdata>
        </row>
    </rows>

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);
}
}
}
Answer posted by dhxSupport on Feb 26, 2009 05:09

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)

Answer posted by Mike H on Feb 26, 2009 05:42
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.
Answer posted by Support on Feb 26, 2009 07:12
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