datatables + lengthMenu +所有+服务器端处理+无法正常工作

这是一个基本的数据表小提琴。 这是默认值 ,下拉菜单将显示以下Show options 10, 25, 50, 75 and 100 records: 10,25,50,75 Show options 10, 25, 50, 75 and 100 records:

现在我想要工作的是"lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ]我可以在这个小提琴中 。 但是,如果我使用服务器端处理,那么All选项对我来说不起作用。 其他人呢。 当我选择All时,它显示它显示的数据,并在底部显示No data found in the server

据我所知,唯一的区别是数据来自服务器。 任何人都可以建议我怎么能麻烦拍这个? 据我所知,当我选择All我发送length:-110它是length:10所以不确定为什么All都不工作

  $(document).ready(function() { var dataTable = $('#employee-grid').DataTable( { "lengthMenu" : [[ 10, 25, 50, -1 ],[ '10', '25', '50', 'All' ]], //"pageLength": 25, "processing": true, "serverSide": true, "ajax":{ url :"employee-grid-data.php", // json datasource type: "post", // method , by default get error: function(){ // error handling $(".employee-grid-error").html(""); $("#employee-grid").append('No data found in the server'); $("#employee-grid_processing").css("display","none"); } } } ); } ); 

使用服务器端处理时, 只有在PHP脚本中length参数为-1才能返回所有记录时,应忽略startlength请求参数。

“lengthMenu”:[[10,25,50,-1],[10,25,50,“全部”]]

1)表示“ALL”的值为-1。

2)这就是为什么当你选择所有你的发送长度:-1和10为长度:10

3)这也是你在服务器中找不到数据的原因 – 错误

4)在你的控制器中给出这个

var length = Request.Form.GetValues(“length”)。FirstOrDefault()==“ – 1”? Convert.ToString(YOUR_LIST.Count()):Request.Form.GetValues(“length”)。FirstOrDefault();

5)这将告诉长度== -1然后获取您的列表总计数,以便它显示所有行。