Get dataItem of current row

2 posts, 0 answers
  1. Emily
    Emily avatar
    4 posts
    Member since:
    Feb 2015

    Posted 27 Oct 2015 Link to this post

    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>

  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 29 Oct 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top