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

[Solved] Keep selection on "virtual" grid

1 Answer 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cedric
Top achievements
Rank 1
Cedric asked on 14 Apr 2015, 08:21 AM

Hi Telerik team.

I've got a grid bound on a server datasource with virtual scrolling and I would like to keep the selected row when the user scrolls.

I've already found a solution on the forum but unfortunately, it doesn't seems to work... Here is my code (with Kendo UI 2014.3.1411): 

    $("#grdResults").kendoGrid({
        dataBound: onDataBound,
        change: onSelectedItemChange,
        dataSource: {

        ........
        scrollable: {
            virtual: true
        },
        selectable: true,
         ........

 function onSelectedItemChange(arg) {
    var selectedRow = arg.sender.dataItem(arg.sender.select());
    $("#selectedRow").val(selectedRow.uid);
}

function onDataBound(e) {
    if ($("#selectedRow").val()) {
        row = $("#grdResults").data().kendoGrid.table.find('tr[data-uid="' + $("#selectedRow").val() + '"]');
        //row = $(this.tbody).find("tr[data-uid='" + $("#selectedRow").val() + "']")
        if ($(row).length > 0) {
            $(row).addClass("k-state-selected");     
        }
    }
}

 

Could you tell me what I've done wrong ?

Thanks for your answer.

Regards,

Cédric

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 16 Apr 2015, 08:39 AM
Hi Cédric,

The provided code is incomplete, but when I add the missing parts (and especially a #selectedRow hidden input), it works perfectly. Have you tried debugging the dataBound and change event handlers? There are three things to check -

- are the event handlers executed
- is the data item UID is saved correctly upon selection
- if the above two checks are OK, then why the UID is not retrieved in dataBound

Regards,
Dimo
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
Cedric
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or