I have a nested Grid with a ClientTemplate in a bounded column:
@(Html.Kendo().Grid<RepViewModel>().Name(
"RepCodes_#=UserId#"
).Columns(column =>
{
column.Bound(model => model.RepCode);
column.Bound(model => model.IsPrimary).Title(
"Primary"
).ClientTemplate(
"\\#=setPrimaryTemplate(data, 'RepCodes_#=UserId#')\\#"
);
}
The ClientTemplate displays a "Set" or "Unset" button in the external template:
<script type=
"text/x-kendo-template"
id=
"setPrimaryTemplate"
>
# if (IsPrimary){#
<a href=
"javascript:void(0);"
id=
"ix_unsetPrimary#=RepCode#"
>Unset</a>
#}else{#
<a href=
"javascript:void(0);"
id=
"ix_setPrimary#=RepCode#"
>Set</a>
#}#
</script>
In the function, I want to get the dataItem of the current row so I can set IsPrimary to true or false. How can I do that?
<script type=
"text/javascript"
>
function
setPrimaryTemplate(data, gridName) {
var
grid = $(
'#'
+ gridName).data(
'kendoGrid'
);
var
dataItem = grid.dataItem($(
this
).closest(
"tr"
)); <- this is currently displaying as null
var
data = {IsPrimary: IsPrimary};
var
setPrimaryTemplate = kendo.template($(
'#setPrimaryTemplate'
).html());
}
</script>