serverside update data

serverside update data

owenchen0911owenchen0911 Posts: 2Questions: 2Answers: 0
edited January 2020 in Free community support

Hi, how can I use ajax.reload() in datetimepick callback functions??

 let method = '';
    let url = '/myAjaxFunc/';
    method = 'POST';
    $.ajax({
        url: url,
        method: method,
        data: { "selectDate": moment(e.date).format("YYYY-MM-DD HH:mm"),
        "start":0,
        "length":10,
        "draw":0,
        }
    }).success(function (data, textStatus, jqXHR) {

    console.log(data['data']);
    //$('#tb12').DataTable({ajax:data['data']}).ajax.reload();
    $('#tb12').DataTable().destroy();

    if ( $.fn.dataTable.isDataTable( '#tb12' ) ) {
        console.log('111111111111111');
        table = $('#tb12').DataTable({"ajax":data['data']}).ajax.reload();

    }
    else {
        console.log('2222222');
        table = $('#tb12').DataTable({"ajax":data}).ajax.reload();
}


    })

it will show error, can't init datatable twice....

Edited by Kevin:  Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    Its hard to say what the problem is without seeing it happen. Your code snippet is not enough to understand everything that happens when using the datetime picker. Please post a link to your page or a test case replicating the problem so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Its not really clear what you are trying to do with that code snippet. Are you trying to use the selected datetime as the ajax data parameter for Datatables? If so then maybe all you need to do is set the ajax.data option in your Datatables init code as a function to get the chosen datetime and pass that as the selectDate parameter and simply use ajax.relaod() to reload the Datatable instead of the above Ajax call.

    Kevin

This discussion has been closed.