Anss
Anss

Reputation: 674

DataTable not showing pagination buttons and records info - JQuery

Using Datatable plugin for pagination, I can't get it to display pagination buttons and records information ("Showing X out of Y Records"). It is fetching the records correctly when I am selecting the page size from the drop down just above the table, but for some reason, it is not showing pagination buttons.

My guess is that it has to know the Total Record count of the table, and I am giving it that in the ""iTotalRecords": 10000" part, I have 1000 records in my table, but still it is of no use. What exactly am I missing here?

It is passing the start (page number) and length (page size) params correctly. Below is my code,

$('#leadDetailTable').dataTable({
        "processing": true,
        "serverSide": true,
        "info": true,
        "stateSave": true,
        "lengthMenu": [[10, 50, 100, 500], [10, 50, 100, 500]],
        "iTotalRecords": 10000,
        "iDisplayLength": 10,
        "searching": false,
        "scrollY": false,
        "scrollX": false,
        "ajax":{
            type: 'POST',
            url: '@Url.Action("SearchLeads", "ResourceManagement")',
            data: args,
            success: function (result) {
                /* Do things with result */
            },

        }
    });

Upvotes: 3

Views: 14886

Answers (4)

jakobinn
jakobinn

Reputation: 2032

I had the same issue and it was because I returned the wrong recordsFiltered value from the server-side. Make sure that the recordsTotal value represents the number of records(rows) in the table and the recordsFiltered value represents the number of rows that should stay hidden of the total rows. DataTables uses this information to create the pagination buttons.

Upvotes: 1

Somna
Somna

Reputation: 148

What is the response being returned by the ajax request? It should include the following:

{
    data: <the array of row data>,
    draw: <the same value the request had for its draw value>,
    recordsTotal: <the total number of records>,
    recordsFiltered: <the total number of records after filtering>
}

If you don't want it to say "filtered from x records", then count the records after filtering and set both recordsTotal and recordsFiltered to that value.

Upvotes: 0

Samyukta R.
Samyukta R.

Reputation: 154

Have you tried adding following parameters:

 "bPaginate":true,
 "sPaginationType":"full_numbers",
 "bLengthChange": true,
 "bInfo" : true

Upvotes: 1

Anoop LL
Anoop LL

Reputation: 1575

Add the below property

"pagingType": "full_numbers"

Upvotes: 0

Related Questions