Unable to display the last page at page loading

Unable to display the last page at page loading

LECARROULECARROU Posts: 4Questions: 3Answers: 0

Hi,

I try to display the last page at page loadin.
I try to use page('first') and fnPageChange('first', false) but it dosen't work

$(document).ready( function () {

        $("#table_id").one("preInit.dt", function () {
                $("#table_id_filter label").append('<a data-target="" class="btn btn-primary" href="{% url 'randomization_settings:edit' %}" style="width: 190px;margin-left:10px;">Modify settings</a>');

        });        

        if(window.navigator.language.slice(0, 2) == 'fr'){
            var table = $('#table_id').DataTable({
                lengthMenu: [5,10],
                "pageLength": 4,
                "bAutoWidth": false,
                "language": {
                "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/French.json"
                },
            });
            table.page('last').draw(false);
        } else {
            var table = $('#table_id').DataTable({
                lengthMenu: [5,10],
                "pageLength": 4,
                "bAutoWidth": false, 
            });
            table.page('last').draw(false);
        }

    } );

Answers

  • rf1234rf1234 Posts: 2,996Questions: 87Answers: 421

    try using an event handler please:

    table
        .on ('init', function () {
            table.page('last').draw(false);
        });
    
  • LECARROULECARROU Posts: 4Questions: 3Answers: 0

    Thanks a lot, it works !

This discussion has been closed.