Search code examples
jquerypaginator

jQuery Paginator when total number of rows are not available


I have a requirement in which I need to implement a paginator using jQuery.

But the problem is, the table which I need to display in datatable is huge(hundreds of thousands of records). Therefore can't hit the DB to get the total number of rows.

What I need is, a paginator with 4 buttons, First, Previous, Next and Last. At a time, a fixed number of records should be fetched. When clicked on next, it should fetch next set of records from server. If no records are available, then empty data table will also work for me.


Solution

  • I don't think your count query will take much time for just for calculating number of rows in table,

    SELECT count(1) from DB_TABLE CONDITION
    

    Although if you want go with custom solution, you can create two buttons with prev and next with page number

    Client

    1. Add currentpage as local variable in js
    2. Add prev and Next event handler with increase and decrease current page number
    3. Parse return json data, and get status whether data returned or not, based on status display message or data
    4. use data to draw table.

    Server

    1. Return data with status in JSON format , so it can be easily parseable in client js
    2. Add server side script to handle page number for limiting data range

    similarly you can add search option as well.