forked from mydea/handsontable-chosen-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
80 lines (73 loc) · 2.41 KB
/
demo.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var data = [];
$(document).ready(function () {
new Handsontable(document.getElementById("handsontable"), {
data: data,
minSpareRows: 1,
minRows: 5,
rowHeaders: true,
columns: [
{
renderer: customDropdownRenderer,
editor: "chosen",
width: 150,
chosenOptions: {
data: [
{
id: "SPOT",
label: "Spot"
}, {
id: "AFLOAT",
label: "Afloat"
}, {
id: "PREORDER",
label: "Preorder"
}, {
id: "FORWARD",
label: "Forward"
}
]
}
},
{
renderer: customDropdownRenderer,
editor: "chosen",
width: 150,
chosenOptions: {
multiple: true,
data: [
{
id: "1",
label: "Catuai"
}, {
id: "2",
label: "Bourbone"
}, {
id: "3",
label: "Geisha"
}
]
}
},
{}
]
});
});
function customDropdownRenderer(instance, td, row, col, prop, value, cellProperties) {
var selectedId;
var optionsList = cellProperties.chosenOptions.data;
if(typeof optionsList === "undefined" || typeof optionsList.length === "undefined" || !optionsList.length) {
Handsontable.cellTypes.text.renderer(instance, td, row, col, prop, value, cellProperties);
return td;
}
var values = (value + "").split(",");
value = [];
for (var index = 0; index < optionsList.length; index++) {
if (values.indexOf(optionsList[index].id + "") > -1) {
selectedId = optionsList[index].id;
value.push(optionsList[index].label);
}
}
value = value.join(", ");
Handsontable.cellTypes.text.renderer(instance, td, row, col, prop, value, cellProperties);
return td;
}