本文介绍了更改jQuery datatable中显示的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 为什么 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 }); }; 要在数据加载后以某种方式修改表,您需要添加 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中显示的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 09:18