-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslick.ext.oneClickCheckbox.js
61 lines (48 loc) · 1.36 KB
/
slick.ext.oneClickCheckbox.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
(function ($, undefined) {
$.extend(true, window, {
"Slick": {
"Ext": {
"Plugins": {
"OneClickCheckBox": OneClickCheckBox
}
}
}
});
function OneClickCheckBox(idPropName) {
var grid,
self = this,
options,
idName = idPropName,
data,
handler = new Slick.EventHandler();
function init(g) {
grid = g;
data = grid.getData(),
options = grid.getOptions();
handler.subscribe(grid.onClick, HandleClick)
}
function destroy() {
handler.unsubscribeAll();
}
function HandleClick(e, args) {
var column = grid.getColumns()[args.cell];
if (column.editor && column.editor == Slick.Editors.Checkbox && options['editable'] && options['autoEdit']) {
grid.invalidateRow(args.row);
if (data instanceof Slick.Data.DataView) {
var item = data.getItem(args.row);
item[column.id] = !item[column.id]
data.updateItem(item[idName], item);
} else {
data[args.row][grid.getColumns()[args.cell].field] = !data[args.row][grid.getColumns()[args.cell].field];
}
grid.updateCell(args.row, args.cell);
grid.setActiveCell(args.row, args.cell);
grid.render();
}
}
$.extend(this, {
"init": init,
"destroy": destroy
});
}
})(jQuery)