jqueryjsonpaginationjquery-jtable

jQuery JTable paging not working


I'm having trouble with jQuery Jtable pagination.

JSON response:

{
    "Result": "OK",
    "Records": [
        {
            etc...
        }
    ],
    "TotalRecordCount": 33
}

Javascript:

$('#foo').jtable({
    title: 'My Table Title',
    paging: true,
    pageSize: 25,
    actions: {
        listAction... etc
    },
    fields: {
        title: myTitle,
        etc
    }
});

I used variables for every fields parameters:

var myTitle = {
    title: 'MyTitle',
    type: 'text'
};

which are all declared before the jtable instance.

The table works fine, but shows all 33 records instead of 1-25 of 33. In the http header, I can see the Query String Parameters set correctly:

Query String Parameters
    action: list
    jtStartIndex: 0
    jtPageSize: 25

I don't know what I'm doing wrong. Any suggestions?


Solution

  • I don't know what your sql statement is like, but I was having the same issue you were and finally figured out that you have to set the paging yourself, using LIMIT in MySQL (it's a bit more complicated in MSSQL).

    --MySQL, PHP
    "SELECT * FROM Students ORDER BY Name ASC LIMIT" . $_REQUEST['jtStartIndex'] .
    "," . $_REQUEST['jtPageSize'];
    
    --SQL Server, ASP
    "SELECT * FROM
        (SELECT ROW_NUMBER() OVER (ORDER BY Name ASC) AS Row, * FROM Students)
        AS StudentsWithRowNumbers
    WHERE Row > " & Request.QueryString("jtStartIndex") & " AND Row <= " &
    Request.QueryString("jtPageSize")
    

    jTable Paging (source)