Get index of item in grouped kendo grid MVVM

2 posts, 0 answers
  1. Neeraj
    Neeraj avatar
    127 posts
    Member since:
    May 2015

    Posted 29 Nov 2018 Link to this post

    Hello,
             I have kendo mvvm grid which is grouped .  How can i delete item from grid easily?

    Below is code to delete item from grid i found from various sources, in that 'index' gives incorrect number after grid is inserted or deleted with other items later on

    var tstgrid = $(e.currentTarget).closest("[data-role='grid']").data("kendoGrid");
     $(e.target).closest("tr").trigger("click");
    var index = tstgrid.items().index(tstgrid.select());
    ImportPNRPricingViewModel.Tsts._data.splice(index, 1);

     

    to insert we, use $.merge, 'ImportPNRPricingViewModel' is my observable and 'response' has new items

    $.merge(response, ImportPNRPricingViewModel.Tsts.data());
    ImportPNRPricingViewModel.Tsts.data(response);

     

     

     

  2. Stefan
    Admin
    Stefan avatar
    2378 posts

    Posted 03 Dec 2018 Link to this post

    Hello, Neeraj,

    Thank you for the code.

    I can assume that the difference occurs because the listed method is getting the index of the row not the dataItem in the data array. When the Grid is grouped, the array order is often different.

    I made an example which shows how to get the item index based on the current row and based on the data array:

    https://dojo.telerik.com/ECAfifUJ

      $('button').click(function(e){
        var tstgrid = $("[data-role='grid']").data("kendoGrid");
        var dataItem = tstgrid.dataItem(tstgrid.select());
        var indexItem = tstgrid.dataSource.indexOf(dataItem);
    console.log(indexItem)
        var indexRow = tstgrid.items().index(tstgrid.select());
        console.log(indexRow)
      })

    I hope this is helpful.

    Regards,
    Stefan
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top