Server side pagination not working v 1.10

Server side pagination not working v 1.10

ScotlandScotland Posts: 3Questions: 1Answers: 0
edited July 2014 in Free community support

Hi Forum Users,

I'm hoping you can help me with a question I have regarding server side paging using v 1.10 of datatables.

Currently I have a controller that returns the following data:

{
    **** Data Truncated for display purposes ****
    "draw":10,
    "recordsTotal":676,
    "recordsFiltered":676,
    "data":[
        {
            "ContactId":11,
            "EntityClassId":1,
            "Name":"Matthew Adley",
            "JobCategory":"Building, Construction \u0026 Property ",
            "JobTitle":"Senior Project Manager (England)",
            "Organisation":"Jameson Construction (Oldham)",
            "IsPrimaryContact":false,
            "PhoneNumber":"0161 925 7830",
            "LastUpdated":"\/Date(1393452818000)\/"
        },
        {
             "ContactId":12,
             "EntityClassId":1,
             "Name":"Mark Campbell",
             "JobCategory":"Building, Construction \u0026 Property ",
             "JobTitle":"Contracts Manager",
             "Organisation":"McLaughlin \u0026 Harvey",
             "PhoneNumber":"",
             "IsPrimaryContact":false,
             "LastUpdated":"\/Date(1224166069000)\/"
         }
     ]
}

To call the controller, you need to pass the following object:

{
    "SearchTerm":"",
    "Page":2,
    "Draw":10,
    "EntityToSearch":"1"
}

My Datatable setup is :

SearchParameters.EntityToSearch = $("#EntityType").val();
var  tableOfResults  = $('#datatable_tabletools').DataTable({
        "processing": false,
        "serverSide": true,
        "paging": true,
        "ajax": {
            "type": "POST",
            "processData": false,
            "url": "../pagesearchresults",
            "dataType": "json",
            "contentType": 'application/json; charset=utf-8',
            "data": function (data) {
                var info = (tableOfResults == null) ? { page: 0, length: 10 } : tableOfResults.page.info();
                SearchParameters.SearchTerm = '';
                SearchParameters.Page = info.page + 1;
                SearchParameters.Draw = info.length;
                return JSON.stringify(SearchParameters);
            }
        } ,
        "columns": [
            { "data": "ContactId" },
            { "data": "EntityClassId" },
            { "data": "Name" },
            { "data": "JobCategory" },
            { "data": "JobTitle" },
            { "data": "Organisation" },
            { "data": "IsPrimaryContact" },
            { "data": "PhoneNumber" },
            { "data": "LastUpdated" }
        ]
    });

My html is set up as:

<table id="datatable_tabletools" class="table table-striped table-hover" >
    <thead>
        <tr role="row">
            <th >ContactId</th>
            <th >EntityClassId</th>
            <th >Name</th>
`           <th >JobCategory</th>
            <th >JobTitle</th>
            <th >Organisation</th>
            <th >IsPrimaryContact</th>
            <th >PhoneNumber</th>
            <th >LastUpdated</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

The problem I'm getting is when I click on page2, the ajax call is processed, I can see the correct json returned to the client in fiddler but the data isn't displayed on the html.

If I change the value of draw that is returned from the server to match the page number, then data table will successfully page up the pages but not down or first or last.

I can not see what I'm doing wrong and all of the examples in the forum relate to the older version of data tables.

Any help would be most appreciated.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Are you able to link to the page so we can take a look please? Normally if page 1 works and page 2 doesn't it is an issue with the draw parameter.

    Allan

  • ScotlandScotland Posts: 3Questions: 1Answers: 0

    At the moment, the site is on a company intranet so no.

    I'll take a look at js fiddle to see if i can replicate the issue.

    Is there anything I should be looking out for?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The DataTables debugger might give us some clue if you run it on the second page.

    Is there anything I should be looking out for?

    Yes, the draw counter should go up by one on every draw.

    Allan

  • ScotlandScotland Posts: 3Questions: 1Answers: 0

    That will be the problem as from the documentation, I thought that draw was the the length of the page.

    I'll amend this and see if that works.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Could you point me to the documentation that is in error so I can fix it? The manual for server-side processing says:

    Draw counter. This is used by DataTables to ensure that the Ajax returns from server-side processing requests are drawn in sequence by DataTables (Ajax requests are asynchronous and thus can return out of sequence). This is used as part of the draw return parameter (see below).

    Allan

This discussion has been closed.