getUserData

The code of my datagrid follows:

mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setSkin('modern');
mygrid.setImagePath('dhtmlxSuite/dhtmlxGrid/codebase/imgs/');
mygrid.setHeader('Client,Contract,ContractID');
mygrid.attachHeader('#select_filter,#text_filter');
mygrid.setColSorting('str,str,int');
mygrid.attachEvent('onRowSelect',function(rowID, celInd){ var _ContractID = mygrid.getUserData(rowID,'ContractID'); alert(_ContractID); return false; }); 
mygrid.setInitWidths('340,310,0');
mygrid.setColTypes('ro,ro,coro');
mygrid.setColAlign('left,left,center');
mygrid.init();
var datagrid = [[Client1,Contract1,1],[Client2,Contract2,2],[Client3,Contract3,3]];
mygrid.parse(datagrid,"jsarray");

When I click on a row I have an empty alert.

What’s wrong in this code?

mygrid.attachEvent('onRowSelect',function(rowID, celInd){ var _ContractID = mygrid.getUserData(rowID,'ContractID'); alert(_ContractID); return false; });

When I click on a row I have an empty alert.
It happens because of clicked row doesn’t have userdata

So how can I modify che code in order to obtain my alert with the _ContractID???

You should add userdata with setUserData method or from xml. docs.dhtmlx.com/doku.php?id=dhtm … nal_data&s[]=userdata#userdata

Hi Olga,

Refer to the sample:
//adds userdata to the row with id=“row1”
mygrid.setUserData(“row1”,“priority”,“high”);
var userdata = mygrid.getUserData(“row1”,“priority”);//-> “high”

how can I set the “priority” dynamically, such as “high”, “low”? because it is retrieved from database and every row has different “priority”.

In my case:
Contact_grid.setUserData(id,“ContactID”,“contactid”); //contactid must be from the database, every contact has a contactid.
alert(Contact_grid.getUserData(id,“ContactID”));

thanks,

You may define the userdata right in the incoming xml:

contactid
data1
data2

Many thanks, Sematik. I just read your another reply to me. I sorted out my problem.
Most examples of dhtmlx are xml data source. I wonder if xml is the best way to feed data?
I always use render_complex_sql to return data to grid, should I convert retrieved data into xml or json? Is there any efficiency issue?

In case of using the connector you may add the required userdata directly on the server-side using the set_userdata function:
docs.dhtmlx.com/connector__php__ … xtrafields