Edit this page

Persist Row Selection on Virtual Scrolling in Grid

Environment

Product Version 2018.1 117
Product Grid for ProgressĀ® Kendo UIĀ®

Description

How can I persist the single row selection when the virtual scrolling functionality of the Grid is used?

Solution

Programmatically handle the collection of item selection on the change event of the Grid.

<div id="example">
            <div id="grid"></div>
            <script>
                $(document).ready(function() {
                    $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            serverPaging: true,
                            serverSorting: true,
                            pageSize: 100,
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                            },
                            schema: {
                               model: {
                                 id:"OrderID"
                               }
                                }
                        },
                        height: 543,
                        scrollable: {
                            virtual: true
                        },
                      change: function(e) {
                                            var selectedRows = this.select();
                                            var dataItem = this.dataItem(selectedRows[0]);
                                            e.sender._selectedIds= {};
                        e.sender._selectedIds[ dataItem.OrderID ]= true;
                                        },
                        selectable:true,
                        persistSelection:true,
                        sortable: true,
                        columns: [
                            { field: "OrderID", title: "Order ID", width: 110 },
                            { field: "CustomerID", title: "Customer ID", width: 130},
                            { field: "ShipName", title: "Ship Name", width: 280 },
                            { field: "ShipAddress", title: "Ship Address" },
                            { field: "ShipCity", title: "Ship City", width: 160 },
                            { field: "ShipCountry", title: "Ship Country", width: 160 }
                        ]
                    });
                });
            </script>
            <style>

                /*A horizontal Grid scrollbar appears if the browser window is shrunk too much.*/
                #grid table
                {
                    min-width: 1190px;
                }

            </style>
        </div>
<div id="example">
            <div id="grid"></div>
            <script>
                $(document).ready(function() {
                    $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            serverPaging: true,
                            serverSorting: true,
                            pageSize: 100,
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                            },
                            schema: {
                               model: {
                                 id:"OrderID"
                               }
                                }
                        },
                        height: 543,
                        scrollable: {
                            virtual: true
                        },
                      change: function(e) {
                                            var selectedRows = this.select();
                                            var dataItem = this.dataItem(selectedRows[0]);
                                            e.sender._selectedIds= {};
                        e.sender._selectedIds[ dataItem.OrderID ]= true;
                                        },
                        selectable:true,
                        persistSelection:true,
                        sortable: true,
                        columns: [
                            { field: "OrderID", title: "Order ID", width: 110 },
                            { field: "CustomerID", title: "Customer ID", width: 130},
                            { field: "ShipName", title: "Ship Name", width: 280 },
                            { field: "ShipAddress", title: "Ship Address" },
                            { field: "ShipCity", title: "Ship City", width: 160 },
                            { field: "ShipCountry", title: "Ship Country", width: 160 }
                        ]
                    });
                });
            </script>
            <style>

                /*A horizontal Grid scrollbar appears if the browser window is shrunk too much.*/
                #grid table
                {
                    min-width: 1190px;
                }

            </style>
        </div>

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy