No matching records found even though the json result is sent and push via dataSrc function

No matching records found even though the json result is sent and push via dataSrc function

newbie14newbie14 Posts: 3Questions: 1Answers: 0

I have below my datatable codes.

      $('#dashboard').DataTable({
                        "order": [[ 1, "asc" ]],
                        "aoColumnDefs" : [   
                        {
                        'bSortable' : false,  
                        'aTargets' : [ 0,2 ]
                        }],
                        "processing": true,
                        "serverSide": true,
                        "destroy":true,
                       "ajax": {
                            "url" : "dashboard.php",
                            "type": "POST",
                            "dataType": 'json',
                            "cache": false,
                            "data" : {
                                "checkAll" : "1",

                            },
                            /*success: function(results) {
                                //should create datatable from data

                            },*/
                            "dataSrc" : function (results) {
                                console.log("json length "+results["data1"]);
                                 console.log("json value is "+JSON.stringify((results.data1)));
                                return results.data1;

                            },
                            error: function(error) {
                                $('#result').html(error);
                            }
                        },
                        //dom: 'Bfrtip',
                        buttons: [
                        'copy', 'csv', 'excel', 'pdf', 'print'
                        ]
                        }
                    );

The problem it keep showing me no matching records found. I am passing from php via this way echo json_encode(array("data1" =>$json_data)); and when I check the return results is something like this.

data1: {draw: 1, recordsTotal: 3, recordsFiltered: 3,…}

What else could be wrong cause the datatype also I have set as json ?

Answers

  • colincolin Posts: 5,407Questions: 0Answers: 940

    Hi @newbie14 ,

    You've enabled serverSide, so the server is responsible for doing all searches. The protocol is discussed here. It would be worth checking your browser's network tab to ensure the server is returning the data in the expected format.

    Cheers,

    Colin

  • newbie14newbie14 Posts: 3Questions: 1Answers: 0

    Hi Colin,
    Yes I can see the in my browser's network tab there is data here its

    data1: {draw: 1, recordsTotal: 3, recordsFiltered: 3,…}. Off course its much longer but I keep it simple this the data I got back from the server. There is 3 recordsTotal etc.

  • colincolin Posts: 5,407Questions: 0Answers: 940

    The problem it keep showing me no matching records found.

    So, the data is being returned, but nothing is showing in the table? Are you able to link to your page?

    Cheers,

    Colin

  • newbie14newbie14 Posts: 3Questions: 1Answers: 0

    Hi Colin,
    Yes I am able to link to my page. Previously I was able to send like this format. Like the below codes.

    $('#dashboard').DataTable({
                      "order": [[ 1, "asc" ]],
                      "aoColumnDefs" : [  
                      {
                      'bSortable' : false, 
                      'aTargets' : [ 0,2 ]
                      }],
                      "processing": true,
                      "serverSide": true,
                      "destroy":true,
                     "ajax": "getDashboardListDT.php",
    
                      },
                      //dom: 'Bfrtip',
                      buttons: [
                      'copy', 'csv', 'excel', 'pdf', 'print'
                      ]
                      }
                  );
    

    And the return from php is like this echo json_encode($json_data);. This settings works fine. The problem now I want to return 2 different array from php echo json_encode(array("data1" =>$json_data,"data2" =>$data2Array));. So this the problem is just single array my grid works perfectly fine.

Sign In or Register to comment.