slickgrid.js
2.16 KB
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
var loader = new Slick.Data.RemoteModel($dj.ajax_get_page);
var slickgrid = {
grid: null
};
var options = {
editable: false,
enableAddRow: false,
enableCellNavigation: false
};
var loadingIndicator = null;
$(function() {
"use strict";
slickgrid.grid = new Slick.Grid(
'#' + slickgrid.grid_element_id, loader.data, slickgrid.columns,
options);
slickgrid.grid.onViewportChanged.subscribe(function (e, args) {
var vp = slickgrid.grid.getViewport();
loader.ensureData(vp.top, vp.bottom);
});
slickgrid.grid.onSort.subscribe(function (e, args) {
loader.setSort(args.sortCol.field, args.sortAsc ? 1 : -1);
var vp = slickgrid.grid.getViewport();
loader.ensureData(vp.top, vp.bottom);
});
loader.onDataLoading.subscribe(function () {
if (!loadingIndicator) {
loadingIndicator = $(
"<span class='loading-indicator'><label>Ładowanie..." +
"</label></span>").appendTo(document.body);
var $g = $('#' + slickgrid.grid_element_id);
loadingIndicator
.css("position", "absolute")
.css("top", $g.position().top + $g.height() / 2 - loadingIndicator.height() / 2)
.css("left", $g.position().left + $g.width() / 2 - loadingIndicator.width() / 2);
}
loadingIndicator.show();
});
loader.onDataLoaded.subscribe(function (e, args) {
for (var i = args.from; i <= args.to; i++) {
slickgrid.grid.invalidateRow(i);
}
slickgrid.grid.updateRowCount();
slickgrid.grid.render();
loadingIndicator.fadeOut();
layout.adjust_grid_size();
});
var text_search = $("#text-search");
text_search.keyup(function (e) {
if (e.which === 13) {
loader.setSearch($(this).val());
var vp = slickgrid.grid.getViewport();
loader.ensureData(vp.top, vp.bottom);
}
});
loader.setSearch(text_search.val());
loader.setSort("create_ts", -1);
slickgrid.grid.setSortColumn("date", false);
// load the first page
slickgrid.grid.onViewportChanged.notify();
});