Skip to content

Commit 36c6c0e

Browse files
committed
Initial version of the virtualization help topic
1 parent a4b7231 commit 36c6c0e

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

web/combobox/virtualization.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Virtualization
3+
page_title: Kendo UI ComboBox Virtualization
4+
description: This document provides information how to configure virtualization in Kendo UI ComboBox, DropDownList, AutoComplete and MultiSelect
5+
position: 3
6+
---
7+
8+
# Virtualization
9+
10+
Kendo UI AutoComplete, ComboBox, DropDownList and MultiSelect support UI and data virtualization which may be used to display large amount of flat or grouped items.
11+
The UI virtualization technique ensures that the widget creates only a fixed amount of list items which are shown in the widget's popup list.
12+
When the list is scrolled the widget will reuse existing containers, instead of creating new ones.
13+
14+
The DataSource component is responsible for data paging and pre-fetching on demand.
15+
16+
##How it works?
17+
18+
Here is an example:
19+
20+
<input id="orders" style="width: 400px" />
21+
<script>
22+
$(document).ready(function() {
23+
$("#orders").kendoComboBox({
24+
template: '#= OrderID # | #= ShipName #',
25+
dataTextField: "ShipName",
26+
dataValueField: "OrderID",
27+
virtual: {
28+
itemHeight: 26,
29+
valueMapper: function(options) {
30+
$.ajax({
31+
url: "http://demos.telerik.com/kendo-ui/service/Orders/ValueMapper",
32+
type: "GET",
33+
data: convertValues(options.value),
34+
success: function (data) {
35+
options.success(data);
36+
}
37+
})
38+
}
39+
},
40+
height: 520,
41+
dataSource: {
42+
type: "odata",
43+
transport: {
44+
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
45+
},
46+
schema: {
47+
model: {
48+
fields: {
49+
OrderID: { type: "number" },
50+
Freight: { type: "number" },
51+
ShipName: { type: "string" },
52+
OrderDate: { type: "date" },
53+
ShipCity: { type: "string" }
54+
}
55+
}
56+
},
57+
pageSize: 80,
58+
serverPaging: true,
59+
serverFiltering: true
60+
}
61+
});
62+
});
63+
64+
function convertValues(value) {
65+
var data = {};
66+
67+
value = $.isArray(value) ? value : [value];
68+
69+
for (var idx = 0; idx < value.length; idx++) {
70+
data["values[" + idx + "]"] = value[idx];
71+
}
72+
73+
return data;
74+
}
75+
</script>
76+
77+
### itemHeight
78+
79+
All items in the virtualized list **must** have the same height. If the developer does not specify one, the framework will automatically set `itemHeight` based on the current theme and font size.
80+
81+
### Container height
82+
83+
The virtualized list container **must** have a `height`. If the developer does not specify one, the list will use default `height` of the widget which is `200`.
84+
85+
### pageSize
86+
87+
The `pageSize` should be equal to `height/itemHeight * 4`. For example if the `height` is 520 and `itemHeight` is 26 `pageSize` should be set to 80. Setting the correct page size is important for the functionality of the widget and will prevent the DataSource from making multiple requests for the same data.
88+
89+
> The widget will automatically control all data requests and may modify the `pageSize` if it is not correctly set by the developer in the DataSource configuration.
90+
91+
### valueMapper
92+
93+
The `valueMapper` function is **mandatory** for the functionality of the virtualized widget. This function will be called every time when the widget receives a value that is not fetched from the remote server yet.
94+
The widget will pass selected value(s) in the `valueMapper` function and will expect from it to return the data item index.
95+
96+
valueMapper: function(options) {
97+
$.ajax({
98+
url: "http://demos.telerik.com/kendo-ui/service/Orders/ValueMapper",
99+
type: "GET",
100+
data: convertValues(options.value), //send value to the server
101+
success: function (data) {
102+
options.success(data); //return the index number of the correspoding data item
103+
}
104+
})
105+
}

0 commit comments

Comments
 (0)