Is there a way to use Data Live DOM Ordering together with "deferRender" + "paging" enabled

Is there a way to use Data Live DOM Ordering together with "deferRender" + "paging" enabled

ouatatazouatataz Posts: 3Questions: 2Answers: 0

Dear all,

I'm using Datatables client-side with AJAX but not in server side processing mode.
I have defined custom live DOM ordering functions that are doing their job very well ; the following is an exemple of such functions.

    jQuery.fn.dataTable.ext.order['dom-data-timestamp'] = function(settings, col) {
        return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
            return parseInt($(td).find('span').attr('data-timestamp'));
        });
    };

The datatable code is as follows.

var table = $('#my-table').DataTable({
    ajax: {
        url: '/my-table-populate-ajax-url.php',
        type: 'POST',
        global: false,
    },
    deferRender: true,
    pageLength: 10,
    paging: true,

    ordering: true,
    searching: true,

    dom: 'rt',

    order: [1, 'asc'],

    columnDefs: [
        {
            targets: [1],
            render: $.fn.dataTable.render.dataAttribute('data-date'),
            orderDataType: 'dom-data-timestamp',
            type: 'numeric',
        },
    ],
    buttons: [],
 
    initComplete: function(settings, json) {
        // Do Stuffs...
    },
});

When the number of row does not exceed the page length everything just work fine.
But as soon as there is multiple pages, ordering fail on my column 1 with a console error (either a or b is undefined), because of the deferRender enabling.

What is the correct way to use data live DOM ordering with deferRender ?

Many thanks,

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,550Questions: 1Answers: 10,476 Site admin
    Answer ✓

    No - fundamentally to do DOM based ordering you need the DOM elements. But deferRender explicitly tells DataTables to not create all of the nodes up front. So the two are not and cannot (at least as far as I can see) be compatible.

    Allan

  • ouatatazouatataz Posts: 3Questions: 2Answers: 0

    Thank you very much Allan, that's exactly what I supposed... Maybe you should mention this in the manual reference ?

    I've found a workaround using a span element for my TDs on which the ordering is done.

    Best,

This discussion has been closed.