Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing 0 to 0 of 0 entries (filtered from NaN total entries)

I am using jQuery DataTables version 1.10.12. Below is my relevant code

// initialize datatable
jQuery('#taskTable').DataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "bInfo": true,
    "bPaginate": true,
    "bLengthChange":false,
    "pageLength": 10,
    "sAjaxDataProp":"serverPageDataModelBean.data" 
});

Data is being displayed and pagination is working. However when I set "bInfo": true I get the following message:

Showing 0 to 0 of 0 entries (filtered from NaN total entries)

and my Next button does not work. In serverPageDataModelBean I am sending {"recordsTotal":12,"recordsFiltered":12,"data":[]} where data is not empty.

Can someone please tell me what is wrong?

like image 494
prashant Avatar asked Jan 18 '17 15:01

prashant


4 Answers

I know this too late, but I'm posting this in case someone stumbles on this. The answer is you need to set serverside to false like this "serverSide": false.

like image 126
Mamadou Barry Avatar answered Nov 08 '22 14:11

Mamadou Barry


CAUSE

Your server-side response is missing draw parameter which should have the same value as the draw parameter in the request. When that happens, jQuery DataTables discards the data.

draw

The draw counter that this object is a response to - from the draw parameter sent as part of the data request.

SOLUTION

Return draw parameter with the same value as draw parameter from the request.

LINKS

See Server-side processing - Returned data for more information.

like image 11
Gyrocode.com Avatar answered Nov 08 '22 13:11

Gyrocode.com


If you are using serverside: true option, then remove this or write serverside: false

for example:

$(document).ready(function() {
    $('#example1').dataTable( {
        "ajax": {
            "url": "view_results",
            "type": "POST"
        },
        'order':[]
    } );
});
like image 5
Sumit Kumar Gupta Avatar answered Nov 08 '22 15:11

Sumit Kumar Gupta


the response for empty data when handling on server side for example php will be ...

echo json_encode(
        array(
        'draw' => $_POST['draw'],
        'data' => [],
        'recordsFiltered' =>  0,
        'recordsTotal' => 0
        )
     );

In pure json

{"draw":1,"data":[],"recordsFiltered":0,"recordsTotal":0}

In short no matter what Datatable as on 2020 needs this parameters on server side handling.

like image 4
3rdi Avatar answered Nov 08 '22 13:11

3rdi