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

[Solved] Global index with virtual scrolling

1 Answer 249 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 15 Oct 2014, 02:05 PM
I would like to get the global index of a given Grid row in order to implement a multi-selection across a grid with virtual scrolling enable.  It's easy to get the index within the displayed rows:

var kendoGrid = $("#myGrid").data("kendoGrid");
var index = kendoGrid.items().index(kendoGrid.select());


At this point, to logic would be to use the page number / page size to determine what is the global index of the selected row.

//Pages are base 1
index += (kendoGrid.dataSource.page() - 1) * kendoGrid.dataSource.pageSize();


However, this ain't working with the Kendo grid (except for the first page) as the grid is displaying rows from page previously loaded.

Example: You have records from 1 to 200 with a page size of 100. When you'll scroll down to the record #100, the dataBound grid event will be triggered and you'll be able to notice the dataSource page has changed from 1 to 2.

You'll also notice some rows from page 1 are still visible and their index will be calculated as a page 2 element.

For instance, the record #96 has the index 95 as long as the grid remain on page 1. When you'll switch to page 2, the record #96 will be displayed (as the first item). At this point, index returned by the grid for that row will be 0. If you apply the page number / size rule above, you'll end up with the index 100.

Is there any solution that doesn't involve a row index calculated on the server side?

Note If we had a PK column, it could be possible to use it to build a list of index, but we don't always have a PK column so this isn't an option.

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 17 Oct 2014, 10:50 AM
Hello Simon,

Having virtual scrolling or regular paging makes no difference in this case. The idea of paging is to display just the items for the current page - the other items do not exist in the DOM neither they can be retrieved in the correct order through JavaScript (most of the times they are also not available as JS objects).

Thus said the only option to get this information is to get it from the server or make it part of the model (e.g. there is a field called Selected that you use to determine whether or not that record is selected).

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or