This is a migrated thread and some comments may be shown as answers.

Get dataItem of current row

1 Answer 522 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emily
Top achievements
Rank 1
Emily asked on 27 Oct 2015, 02:34 PM

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>

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 29 Oct 2015, 09:44 AM

Hello Emily,

 

The client template function will be executed for every item and the data variable in your case will hold the dataItem, please see this sample:

 

http://dojo.telerik.com/OdasE

 

Regards,
Kiril Nikolov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Emily
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or