Load ajax after table inizialization
Load ajax after table inizialization
Is it possible to load the table content after the table initialization?
I mean I need to initialize the table
let mytable=$('#htmlTableId').DataTable({...});
and then, when a modal show up, load the table content by ajax, based on the button clicked to open the modal.
I would prefer to initiate the table on the body load and not on the modal shown, because I assign the Datatable to a variable, that I use intensively in other routines. How can I load the remote content only when the modal is shown?
The only way I found at the moment is loading the ajax config and let it return an empty result on page load, then load again and return proper content if called by the shown modal.
Replies
You can use jQuery ajax() to fetch the data. Use the
success
function to executerows.add()
to place the fetched rows into the table. You can initialize an empty Datatable by not providing theajax
ordata
options.Kevin
Thanks Kevin. Yes, I was looking also to this, just wondering if there is a built-in method to set the configuration in the initial initialization, and defer the proper loading to a delayed event.
There is nothing built into Datatables to delay loading the table data. Here is an example of what I described:
https://live.datatables.net/huyexejo/1672/edit
Kevin