-
Notifications
You must be signed in to change notification settings - Fork 78
/
helpers.js
35 lines (31 loc) · 1.07 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export const getDataProvider = (allItems) => (params, callback) => {
const offset = params.page * params.pageSize;
const filteredItems = allItems.filter((item) => item.indexOf(params.filter) > -1);
const size = filteredItems.length;
const items = filteredItems.slice(offset, offset + params.pageSize);
callback(items, size);
};
export const getAsyncDataProvider = (allItems) => {
const dataProvider = getDataProvider(allItems);
return (params, callback) => {
setTimeout(() => {
dataProvider(params, callback);
}, 0);
};
};
/**
* Returns all the items of the combo box dropdown.
*/
export const getAllItems = (comboBox) => {
const internal = comboBox.$.comboBox;
return Array.from(internal._scroller.querySelectorAll('vaadin-multi-select-combo-box-item'))
.filter((item) => !item.hidden)
.sort((a, b) => a.index - b.index);
};
/**
* Returns first item of the combo box dropdown.
*/
export const getFirstItem = (comboBox) => {
const internal = comboBox.$.comboBox;
return internal._scroller.querySelector('vaadin-multi-select-combo-box-item');
};