This happens in FF, Chrome, Safari. Not in IE (see picture FF example)
This comes because the mastergrid has a hidden column.
Why do we use the hidden column.
I have a event
events.OnDetailViewExpand("onDetailViewExpand"))function DetailViewExpand(e) { var masterRow = e.masterRow; var User_ID = masterRow.cells[3].innerHTML;It's an ID column and need it for the rest of the Grid.
Per row the ID is different.
Is there a way I can do without the hidden column?
Regards,
Gerard
14 Answers, 1 is accepted
If your grid is bound via ajax you can use the dataItem JavaScript method.
Regards,Atanas Korchev
the Telerik team
When i use this
var grid = $('#UsersOverzichtGrid').data('tGrid'); var tr = $('#UsersOverzichtGrid tbody tr:first'); var dataItem = grid.dataItem(tr);in my
.ClientEvents(events => events.OnDetailViewExpand(
"onDetailViewExpand"))
dataItem = undefined
Grid is filled with all my grid items
Does this work in the onDetailViewExpand??
Regards,
Gerard
Yes, it should work provided that the UsersOverzichtGrid grid is ajax bound. You can also use the .data array of the grid which contains all data items to which the grid is currently bound (the current page from the data source).
Regards,Atanas Korchev
the Telerik team
Hereby a test project.
Still my dataItem is undefined.
I can't use the data array of the grid because I need to know only the data of the row expanded.
Maybe you see what goes wrong.
In the FleuraProdcuctUserControl.ascx is a method
function onDetailViewExpand(e) { var grid = $('#VoorraadGrid').data('tGrid'); var tr = $('#VoorraadGrid tbody tr:first'); var dataItem = grid.dataItem(tr); }Regards,
Gerard Eikelboom
Your code is actually finding the header row of the grid (there are two table elements in the grid when scrolling is enabled). Change it to this:
var tr = $('#VoorraadGrid .t-grid-content tbody tr:first');
Atanas Korchev
the Telerik team
This works, I got my dataItems, but only for the first row.
So in my grid if I klik on row number 8 it finds dataItems from the 1st row.
Is that because of tr:first');?
If so it means I need to know wich row I am clicking on, correct?
Regards,
Gerard
Yes, tr:first means first tr (row). The OnDetailViewExpand however passes the currently expanding row in its event arguments - e.masterRow. You can pass that to the dataItem method.
Kind regards,Atanas Korchev
the Telerik team
When I use the e.MasterRow The columns I want to read must be in the Grid.
What I do is I fill the Id column in my model return it to the Grid. But I don't want the column in the Grid. So I can't use the e.masterRow for reading the ID because it's not there.
What I can do is read the Grid.data items (collection). get the e.masterRow
and match on the columns known in the masterRow by itteration through that collection.
When found get the ID and continue.
What do you think
Regards,
Gerard
I am not sure I understand why you can't use e.masterRow. Every row has a corresponding data item which can be retrieved by passing the row to the dataItem JavaScript routine.
Greetings,Atanas Korchev
the Telerik team
example: my Model: ID = 1
FirstName = Atanas
LastName = Korchev
Grid: column: FirstName
column: LastName
ClientEvents column: CarType
column: Engine
So when i run the application I see in my Grid Column1: Atanas Column2: Korchev
.ClientEvents(events => events.OnDetailViewExpand(
"onDetailViewExpand"))
function onDetailViewExpand(e){
var test = e.masterRow
test1 = masterRow.cells[0].innerHTML = Atanas
test2 = masterRow.cells[1].innerHTML = Korchev
}
The ID is not in masterRow because it's not in a grid column, this while I fill it in my model
I can read the ID by doing:
var
grid = $('#mygrid').data('tGrid');
var gridData = grid.data;
var ID = gridData[0].ID = 1
var name = gridData[0].FirstName = Atanas
So when I have multiple items in my Grid I have to itterate throught it and compare
for (var i = 0; i < (gridData.length); i++) {
var name = gridData[i].FirstName
if( name = = test1 ){
var myID = gridData[0].ID
break;
}
}
This is how I do it now
Now I have my ID and can go further.
Regards,
Gerard
I tried the following in your application and it worked:
function onDetailViewExpand(e) {
var grid = $('#VoorraadGrid').data('tGrid');
var tr = $('#VoorraadGrid .t-grid-content tbody tr:first');
var dataItem = grid.dataItem(e.masterRow);
alert(dataItem);
}
All the best,
Atanas Korchev
the Telerik team
So easy
Works like a charm.
thank you very much.
Regards,
Gerard
DetailViewExpanded: function (e) { var grid = $('#HistoryGrid').data("tGrid"); var dataItem = grid.dataItem(e.masterRow); alert(dataItem); }