相关连接
Features Data Columns Options Internationalisation
Callbacks - 回调函数部分
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
var table = $('#example').DataTable({
"createdRow": function(row, data, dataIndex) {
if (data[4] == "A") {
$(row).addClass('important');
}
},
"drawCallback": function(settings) {
alert('DataTables has redrawn the table');
},
"footerCallback": function(tfoot, data, start, end, display) {
$(tfoot).find('th').eq(0).html("Starting index is " + start);
},
"formatNumber": function(toFormat) {
return toFormat.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "'");
},
"headerCallback": function(thead, data, start, end, display) {
$(thead).find('th').eq(0).html('Displaying ' + (end - start) + ' records');
},
"infoCallback": function(settings, start, end, max, total, pre) {
return start + " to " + end;
},
"initComplete": function(settings, json) {
alert('DataTables has finished its initialisation.');
},
"preDrawCallback": function(settings) {
$('#example tbody').off('click', 'td');
},
"rowCallback": function(row, data, index) {
if (data.grade == "A") {
$('td:eq(4)', row).html('<b>A</b>');
}
},
"stateLoadCallback": function(settings) {
var o;
// Send an Ajax request to the server to get the data. Note that
// this is a synchronous request since the data is expected back from the
// function
$.ajax({
"url": "/state_load",
"async": false,
"dataType": "json",
"success": function(json) {
o = json;
}
});
return o;
},
"stateLoaded": function(settings, data) {
alert('Saved filter was: ' + data.search.search);
},
"stateLoadParams": function(settings, data) {
data.search.search = "";
},
"stateSaveCallback": function(settings, data) {
// Send an Ajax request to the server with the state object
$.ajax({
"url": "/state_save",
"data": data,
"dataType": "json",
"type": "POST",
"success": function() {}
});
},
"stateSaveParams": function(settings, data) {
data.search.search = "";
}
});
PS:以上代码无任何实际使用价值,纯粹演示对象结构,和新版参数的写法