Persist Single-Row Selection on Virtual Scrolling in Grid
Environment
Product Version | 2018.1 117 |
Product | Progress® Kendo UI® Grid for jQuery |
Description
When the user selects a row on the first page, scrolls to the second page, and selects a row, the Grid has two selected items.
- How can I persist the single-row selection when the virtual scrolling functionality of the Grid is used?
- How can I ensure I always have only one selected row when using the virtually scrollable Grid?
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>