dongshang1768 2018-07-25 08:54
浏览 78

Jquery Datatables客户端优化

I'm using Jquery datatables library since a long time in server side processing but I encountered lot of problem when I use filter search because the rendered data isn't the same value of the database value.

So I have a new project and I decide to use datatables client side. So I have an ajax call to get all my data. But php is really slow if I do queries with relationship on 100 000 rows.

Then the idea is to use a limit to display some data to the client and processing in background and display all result when it's ok. I see deferRender method in datatables documentation but I don't see any changes.

So I do an first ajax call with a limit parameter, I display the results and I do a second ajax call without limit parameter, then I display all result.

The problem with that is the number of the total record... When the table is populate with the first call I have the total record of the limit so I don't have the real total record number. It's initialized at the second time.

How can I edit the total record number to display the final pagination and the final "Showing x to y of z entries" at the first call ? Or maybe I'm doing wrong and there is another good way to do what I want.

Here is my datatable initialization :

$('#foldersTable').DataTable({
    dom: "t<'col-sm-5'i><'col-sm-7'p>",
    autoWidth: false,
    serverSide: false,
    aaSorting: [[2, 'desc']],
    createdRow: addDataAttr,
    drawCallback: keepSelectedRow,
    rowId: 'id',
    lengthChange: false,
    iDisplayLength: 10,
    deferRender: true,
    initComplete: function(settings, json) {
        $('.table-responsive').show();
        limit = false;
        $('#foldersTable').DataTable().ajax.reload(null, false);
    },
    ajax: {
        url: 'getFolders',
        method: 'POST',
        dataSrc: checkSessionDT,
        data : { "limit" : function() { return limit; } }
    },
    language: {
        lengthMenu: datatable_lang.lengthMenu,
        zeroRecords: datatable_lang.zeroRecords,
        info: datatable_lang.info,
        infoEmpty: datatable_lang.infoEmpty,
        infoFiltered: datatable_lang.infoFiltered,
        search: datatable_lang.search,
        searchPlaceholder: datatable_lang.searchPlaceholder,
        paginate: {
            previous: datatable_lang.paginate.previous,
            next: datatable_lang.paginate.next
        }
    },
    columns: [
        {data: "Column A", width:"20%"},
        {data: "Column B", width:"20%", orderData:[1, 0]},
        {data: "Column C", render: renderFunction, width:"20%", orderData:[2, 0], type: "date-euro"},
        {data: "Column D", width:"20%", orderData:[3, 0]},
        {data: "Column E", width:"20%", orderData:[4, 0]}
    ]
});

I hope you can help me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序