draw() and initCompete

draw() and initCompete

kevin2kevin2 Posts: 3Questions: 1Answers: 0
edited March 2022 in DataTables 1.10

Hello, I'm using table.api().draw() to read new data through ajax for a table. But this function does not call initComplete again. How to force a table to completely redraw with an initComplete call?

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    initComplete runs only once after the Datatable has initialized. You will need to move the code to a more appropriate event so it runs when desired. The draw event may work for your needs.

    Kevin

  • kevin2kevin2 Posts: 3Questions: 1Answers: 0

    Thanks, I'm using initComplete because I need the data received from the server via ajax initComplete(settings, json). Can you suggest what other event can accept the same input data?

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    The xhr event has a json parameter. You can also use the ajax.json() API to read the current JSON data.

    Kevin

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406
    edited March 2022

    If you use ajax.reload() to reload the table you can use the callback to access the data read from the server.

    https://datatables.net/reference/api/ajax.reload()

    json.data is the array with the rows read from the server if you use Editor.

  • kevin2kevin2 Posts: 3Questions: 1Answers: 0

    Thank you

Sign In or Register to comment.