简体   繁体   English

具有服务器端处理的DataTable

[英]DataTable with Server-side processing

My current problem is how could I properly perform pagination in DataTable to generate lengthMenu (Showing 1 to 10 of 57 entries) dynamically and only load data when next page is clicked. 我当前的问题是如何在DataTable中正确执行分页以动态生成lengthMenu (Showing 1 to 10 of 57 entries)并且仅在单击下一页时才加载数据。
So far my understanding on server-side processing is like this: 到目前为止,我对服务器端处理的理解是这样的:
My web service is returning data from database using MySQL with limit and offset in JSON format . 我的Web服务正在使用MySQL(具有JSON格式的限制和偏移量)从数据库返回数据
Assuming that the JSON data is correct how could I properly paginate my DataTable? 假设JSON数据正确,如何正确分页DataTable?

Below is my code: 下面是我的代码:

var Table1 = $('#table').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": SomeWorkingURLS,
        "dataType": "jsonp"
    },

    "columns": [
        { "data": "Column1" },
        { "data": "Column2" },
        { "data": "Column3" },
        { "data": "Column4" }
    ],
    "columnDefs": [
        {
            "render": function ( data, type, row ) {
                return data + "<hr>" + row.data1;
            },
            "targets": 0
        },
        {
            "render": function ( data, type, row ) {
                return data + "<br>" + row.data2 ;
            },
            "targets": 1
        },
        {
            "render": function ( data, type, row ) {
                return  data ;
            },
            "targets": 2
        },
        {
            "render": function ( data, type, row ) {

                if (row.status == '2'){

                return '<button class="fas fa-edit btn-success" data-toggle="tooltip" title="Edit" value="' + data + '">Verify</button>'
                + ' <button class="fas fa-undo btn-danger" data-toggle="tooltip" title="Resend" value="' + data + '"> Authenticate</button>';

                }
                else{
                    return '<button class="fas fa-edit btn-success" data-toggle="tooltip" title="Edit" value="' + data + '">Authenticate</button>';
                }

            },
            "targets": 3
        },
        { "width": "14%", "targets": 0 },
        { "width": "60%", "targets": 1 },
        { "width": "10%", "targets": 2 },
        { "width": "16%", "targets": 3 , "class":"dt-center"},
    ],

    "destroy": true,
    "searching" :false

    });

    Table1.draw();
    $("select[name*='table_outbound_shipment_list']").removeClass('form-control');
    $("#table_outbound_shipment_list_length").remove();
    $('.form-control.form-control-sm').removeClass('form-control');


My web service would always return 10 row of data (or am I doing wrong here?) 我的Web服务将始终返回10行数据(或者我在这里做错了吗?)
My reference: https://datatables.net/examples/data_sources/server_side 我的参考: https : //datatables.net/examples/data_sources/server_side

There are libraries and helper classes for server-side processing that help with preparing server-side response. 有一些用于服务器端处理的库和帮助程序类,它们有助于准备服务器端响应。

For example, DataTables distribution includes ssp.class.php helper calss and sample script to aid in generating response if you're using PHP. 例如,DataTables发行版包括ssp.class.php帮助程序和示例脚本,以帮助您在使用PHP时生成响应。

Otherwise, you can inspect sent parameters and paginate your results based on start and length request parameters. 否则,您可以检查发送的参数并根据startlength请求参数对结果进行分页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM