first load with no data

first load with no data

rodolphenrodolphen Posts: 18Questions: 4Answers: 0

Hi,
I migrate datatable from 1.10 to 1.13.

As i am on server side, i don't load data at first time. I wait the user choose option to get data.
With 1.10, the emptyTable string was raised
With 1.13 i have the processing string.

So user waits but I don't want to load data at first time.
Could you help me?

Answers

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    If you don't have any data to load you need to return an empty data array.

    Perhaps you can link to your page so I can offer some more help (i.e. I need to be able to see the specifics of the returned data and configuration of the table).

    Allan

  • rodolphenrodolphen Posts: 18Questions: 4Answers: 0

    Hi,
    I can't it is on intranet only.
    I have the same code&page as datable 1.10.9 but I have this :

    Else here an extract of JS, as I set data to null in $(document).ready(function() :

    var table = $('#tablereporting').DataTable( {

        "sScrollX": "100%",
        "bScrollCollapse": true,
        "order": [ 5, "asc" ],
        "deferRender": true,
        "columnDefs": [ 
            {
                "targets": 0,
                "className":      'details-control',
                "orderable":      false,
                "data":           null,
                "defaultContent": '',
                "sWidth": "20px"
    
            },
    

  • kthorngrenkthorngren Posts: 20,409Questions: 26Answers: 4,789

    I would first look at the browser's console for errors. Use the browser's network inspector tool to view the JSON response. You can post it here. Use Markdown to format the code output. As Allan suggested the data object should be an empty array, ie data: [], if no rows are returned.

    Kevin

  • rodolphenrodolphen Posts: 18Questions: 4Answers: 0

    Hi,
    There is no error in console.
    I am on server side with ajax. Data should be an empty array, until a request is sent.
    It works good with datatable 1.10.9
    As I have no data, no row, I don't want to have the processing message.
    thank you,

  • kthorngrenkthorngren Posts: 20,409Questions: 26Answers: 4,789

    We understand the problem description but need more information to help debug. Can you post the JSON response that is causing the issue? If not maybe use the debugger to gather diagnostic info for Allan to review.

    Kevin

  • rodolphenrodolphen Posts: 18Questions: 4Answers: 0

    Hummm, it seems the ajax is called anyway, but it is empty :

    the configuration :
    "processing": true,
    "serverSide": true,
    "ajax": "ajax/search_DB_reporting_h.php",
    "drawCallback": function( settings ) {
    cursor_defaut();
    },

    And result of ajax :
    {"draw":0,"recordsTotal":0,"recordsFiltered":0,"data":[]}

  • kthorngrenkthorngren Posts: 20,409Questions: 26Answers: 4,789

    Yes, when Datatables initializes it will send an Ajax request for the data. The problem is with the response. It has "draw":0 which is incorrect. The draw parameter is a sequence number and Datatables always starts with 1 so a response with draw=0 should never happen. See the Server Side Processing Protocol docs for details.

    I don't know where it was changed but I believe there was a bug fix where Datatables accepted "draw":0 when it shouldn't.

    My guess is the server script is checking for draw=1 being sent in the request and will return the above response if so. Change it to return draw=1 and it should work correctly.

    Kevin

  • rodolphenrodolphen Posts: 18Questions: 4Answers: 0

    Hi,
    It works better, thank you!

Sign In or Register to comment.