datatables + lengthMenu + All + serverside处理+不工作 [英] datatables + lengthMenu + All + serverside processing + not working

查看:699
本文介绍了datatables + lengthMenu + All + serverside处理+不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个是一个基本的数据库小提琴。
这是默认,下拉列表将显示以下内容显示选项10,25,50,75和100记录:



现在我想要工作的是 lengthMenu:可以在 net / 5gpLcfkr / 1 /rel =nofollow>这个小提琴。但是,如果我使用服务器端处理,这是 All 选项对我来说无效。其他人。当我选择 All 它会分配它显示的数据,底部表示在服务器中找不到数据



据我所知,唯一的区别是数据来自服务器。任何人都可以建议我可以麻烦拍摄这个吗?据我所知,当我选择所有我发送长度:-1 10 它是长度:10 所以不知道为什么全部不工作< p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 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,//方法,默认情况下get
error:function(){//错误处理
$(。employee-grid-error)。 html();
$(#employee-grid)。append('< tbody class =employee-grid-error>< tr>< th colspan =3> ;没有找到数据服务器< / th>< / tr>< / tbody>');
$(#employee-grid_processing)。css(display,none);

}
}
});
});


解决方案

使用服务器端处理时,您应该忽略开始长度请求参数只有如果,您的PHP脚本中的长度参数是 -1 才能返回所有记录。


This is a basic datatables fiddle. This is the default and the dropdowns will show the follwoing Show options 10, 25, 50, 75 and 100 records:

Now what I would like to get working is the "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ] which I can in this fiddle. But what if I use server side processing, this is where the All option does not work for me. The others do. When I select All it dispalys the data that it was showing and the at the bottom says No data found in the server

As far as i Know the only difference is the data comes from the server. Can anyone advise how i can trouble shoot this? As far as I can tell when I select All I am sending length:-1 and for 10 it is length:10 so not sure why All is not working

        $(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('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
                        $("#employee-grid_processing").css("display","none");

                    }
                }                   
            } );
        } );


解决方案

When using server-side processing, you should ignore the start and length request parameters ONLY IF the length parameters is -1 in your PHP script in order to return all records.

这篇关于datatables + lengthMenu + All + serverside处理+不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆