pageLength does not change with custom select

pageLength does not change with custom select

matteoterzimatteoterzi Posts: 2Questions: 1Answers: 0

Hi, i have a problem with pagination length.
This is my code:
var table = $('#customerTable').DataTable({
serverSide: true,
rowId: 'id',
destroy : true,
pageLength: $("#test option:selected").val(),
dom: '<"length">Bfrtip',
//dom: 'lBfrtip',
buttons: [
'copy', 'csv', 'excel', 'print'
],
ajax: {
url: "{{ route('ajax-customer') }}"
//dataSrc: ''
},
columns: [
{data: 'id'},
{data: 'email'},
{data: 'phone_number'},
{data: 'first_name'},
{data: 'last_name'},
]
});

        //$("div.length").html('<div class="dataTables_length" id="customerTable_length"><select name="customerTable_length" aria-controls="customerTable" class="select2"><option value="10">10</option><option value="25">25</option></select></div>');
        $('#test').change(function () {
            table.ajax.reload(null,false);
        });

Basically, i need to use a value of external select as pageLength. When datetables is init, load the $("#test option:selected").val() value correctly, but when table.ajax.reload(null,false); is called, in the ajax request the page length is the same as the initial request.

Also, i neet to customise the search input, how can i do that?

Answers

  • matteoterzimatteoterzi Posts: 2Questions: 1Answers: 0

    Anyone that can help me?

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    The pageLength option is only specified when configuring/creating the table. ajax.reload does not reconfigure the table. Once your table is created you can use the API to change the page length. See the documentation for page.len to change the page length after it's been created.

This discussion has been closed.