更改jQuery datatable中显示的行数 [英] Change the number of displayed rows in jQuery datatable
问题描述
为什么 jquery datatable
中的行数(见下面的代码)未设置为5?默认值等于10 8as)。为什么'iDisplayLength':5
在这里不起作用?
脚本>
function loadData(){
$ .getJSON(
'modules / getData.php',
function(data){
var oTable = $('#newspaper -b')dataTable({
sPaginationType:full_numbers,
aaSorting:[[3,asc]],
bJQueryUI:true,
'iDisplayLength':5,
'bLengthChange':false
});
oTable.fnDraw();
var list = data ($ i $)$ {$ $
for(var i = 0; i< list.length; i ++){
aux = list [i];
textToInsert + ='< tr>< td>';
textToInsert + = aux.Var1;
textToInsert + ='< / td>< / tr>';
}
$('table#newspaper-b tbody')。html(textToInsert);
}
);
}
< / script>
尝试这样的东西。 DataTables具有内置选项,可让您从AJAX源中提取数据,而无需自行构建。 阅读文档,并根据需要进行自定义:
$ pre>
function loadData(){
var oTable = $('#newspaper-b')。dataTable({
sAjaxSource:'modules / getData
sPaginationType:full_numbers,
aaSorting:[
[3,asc]
],
bJQueryUI true,
'iDisplayLength':5,
'bLengthChange':false
});
};
要在数据加载后以某种方式修改表,您需要添加< a href =http://datatables.net/ref#fnDrawCallback> fnDrawCallback
选项:
fnDrawCallback:function(oSettings){
//使用jQuery更改某些单元格的内容
$ lastcell = $('#newspaper-b' ).find('tr')。find('td:last');
//以某种方式操纵它
}
Why the number of rows in jquery datatable
(see the code below) is not set to 5? It is equal to 10 8as by default). Why 'iDisplayLength': 5
does not work here?
<script>
function loadData() {
$.getJSON(
'modules/getData.php',
function(data) {
var oTable = $('#newspaper-b').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[3, "asc"]],
"bJQueryUI":true,
'iDisplayLength': 5,
'bLengthChange': false
});
oTable.fnDraw();
var list = data.flights;
var textToInsert = '';
for (var i = 0; i < list.length; i++) {
aux = list[i];
textToInsert += '<tr><td>';
textToInsert += aux.Var1;
textToInsert += '</td> </tr>' ;
}
$('table#newspaper-b tbody').html(textToInsert);
}
);
}
</script>
Try something like this. DataTables has built-in options that let you pull data from an AJAX source without trying to build it yourself. Read the documentation and customize it as needed:
function loadData() {
var oTable = $('#newspaper-b').dataTable({
"sAjaxSource": 'modules/getData.php',
"sPaginationType": "full_numbers",
"aaSorting": [
[3, "asc"]
],
"bJQueryUI": true,
'iDisplayLength': 5,
'bLengthChange': false
});
};
To modify the table in some way after the data is loaded, you'll want to add the fnDrawCallback
option:
"fnDrawCallback": function( oSettings ) {
// use jQuery to alter the content of certain cells
$lastcell = $('#newspaper-b').find('tr').find('td:last');
// manipulate it somehow
}
这篇关于更改jQuery datatable中显示的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!