Display Datatable message "Data is not availble"

Display Datatable message "Data is not availble"

himanshu vyashimanshu vyas Posts: 5Questions: 0Answers: 0
edited May 2017 in Free community support

Hello I m Himanshu i want to display message when data value null display simple message data is not available

    table = jQuery('#myTable').DataTable({            
                'responsive': true,           
                'ajax': {
                    'type': 'POST', 
                    'url': zpriceload_ajax.ajax_url_one,
                    'dataType': 'json',
                    'data': {
                        action: 'ajax_zprice_manage_function',
                        cropid: id,
                        community_community_value: radioValue
                    },
                    'success': function(result) {
                        if (result.data === null) {
                            result.data = [];  
                        }    
                        console.log(result);
                    }
                },
                "columns": [
                    { "data": "crop_name" },
                    { "data": "date" },
                    { "data": "measure" },
                    { "data": "unit" },
                    { "data": "newprice" },
                    { "data": "oldprice" },
                    { "data": "symbol" },
                    { "data": "newchange" },
                    { "data": "percent" }
                ],
            });

Right Now i m getting error datatables warning table id= - invalid json response

Replies

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    Did you go through this? https://datatables.net/manual/tech-notes/1

    Also, if you format your code using the code tags - triple backticks, it will be easy to read for those who want to help you.

    Regards,
    Harsha

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    Remove the success callback. As the ajax documentation notes you should not override it since you are replacing DataTables' default.

    Use ajax.dataSrc if your server is returning null rather than an empty array for zero results.

    Allan

  • himanshu vyashimanshu vyas Posts: 5Questions: 0Answers: 0
    edited May 2017

    first of all thanks for replay but i am use this code in wordpess ajax so as you said i am use 'dataSrc' is successfully get message no data available but when data is get same message show data is not available so can you please guide me??
    This is my code

     table = jQuery('#myTable').DataTable({            
                    'responsive': true,           
                    'ajax': {
                        'type': 'POST', 
                        'url': zpriceload_ajax.ajax_url_one,
                        'dataType': 'json',               
                        'dataSrc': {
                            action: 'ajax_zprice_manage_function',
                            cropid: id,
                            community_community_value: radioValue
                        }                    
                    },
                    "columns": [
                        { "data": "crop_name" },
                        { "data": "date" },
                        { "data": "measure" },
                        { "data": "unit" },
                        { "data": "newprice" },
                        { "data": "oldprice" },
                        { "data": "symbol" },
                        { "data": "newchange" },
                        { "data": "percent" }
                    ],
                });   
    

    here is my server response

    {"tableData":null,"customer_crop_currency":"true"}
    
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    You need to use it as a function - something like:

    dataSrc: function ( json ) {
      if ( json.tableData === null ) {
        return [];
      }
      return json.tableData;
    }
    

    Allan

  • himanshu vyashimanshu vyas Posts: 5Questions: 0Answers: 0

    Thanks, Allan.....

    that's thing works for me......great .......support.....thank you again

This discussion has been closed.