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

Get index of item in grouped kendo grid MVVM

1 Answer 227 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 29 Nov 2018, 01:16 PM

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);

 

 

 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 03 Dec 2018, 07:31 AM
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.
Tags
MVVM
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Stefan
Telerik team
Share this question
or