I'm trying to loop through the dataitems held by my grid but get an error that the field I am trying to look at in every data item is undefined. This is the code I'm using:
What I'm trying to do is get the data item whose FirstName field matches the reference variable. Does anyone have any ideas?
grid = $(
"#grid"
).data(
"kendoGrid"
);
for
(
var
i = 0; i < 50; i ++) {
if
( grid.dataItem(i).FirstName == reference) {
var
item = grid.dataItem(i);
break
;
}
}
What I'm trying to do is get the data item whose FirstName field matches the reference variable. Does anyone have any ideas?
You need to pass a row, not a rowindex, to dataItem.
You could try something like this, though:
$(
"#grid"
).data(
"kendoGrid"
)._data[i].FirstName
Or, you could define a custom data attribute in a template for that cell.
<
td
data-first-name
=
"# FirstName #"
>
#= FirstName #
</
td
>
And, in your code, look for a matching value like this:
var
rowindex;
var
cell =
$(
"#grid"
).data(
"kendoGrid"
).
tbody.find("td[data-first-name='" + reference + "']"
);
if
(cell) {
rowindex = cell.parent()[0].rowIndex;
}
and that will give you the rowindex of the grid where the match was found.
Jerry