0

I am using jquery dataTables plugin to display data on my site. If I retrieve the data using the DataTable() built in ajax call, the table displays a 'Loading...' message while the data is being retrieved.

I have a need to retrieve the data outside the DataTable() call to avoid double processing and am using a ViewModel to pass data into the DataTable() function and several other fields on the page with a single call to the database server.

Is there a way to use a basic DataTable() , without any data, and force a 'Loading...' message.

I basically want to make a $('#table').DataTable(); call to display a skeleton table, no rows or columns, just the basic layout with the word 'Loading...' displayed, then, after I make an ajax call to retrieve the data, destroy the table before re-calling DataTable() and passing in the retrieved json data

5
  • Have a look at this SO question stackoverflow.com/questions/40645263/… and this thread datatables.net/forums/discussion/22619/… Commented Jan 9, 2018 at 7:03
  • @J-D Thanks, but both those examples only work if I am calling Ajax from WITHIN the DataTable () function. I am needing to display a 'Loading...' type message just as a place holder in the table while a separate function does the Ajax call. Once the response comes back from that Ajax call, the table is destroyed and a new DataTable () call is made and passed one of the objects within the response from the external Ajax call. Commented Jan 9, 2018 at 14:38
  • If I understand what you're saying, you're effectively using 'client-side' datatables. So you'll lose the benefits of server-side paging etc. What are you trying to solve by using this approach? Commented Jan 12, 2018 at 15:01
  • @markpsmith Ya, knew I would lose the built in functionality, but I have a need to consolidate my ajax call to pull back more than just the data for the table itself, so I created an object that includes, among the other information I needed, an object that contains the table data and then hand that off to the datatable() function within the success: portion of the standalone ajax call Commented Jan 13, 2018 at 20:50
  • You can add custom data into the datatables response, so in addition to the table data, you can return any other information that you want to use on the page. Obviously it depends what extra data you want to return, but I strongly suggest you consider this approach as it's the correct use of the datatables API, what you're trying to do might be a bit a bit of 'hack'. Commented Jan 15, 2018 at 10:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.