Frequently Asked Questions
DataTables is a complex piece of software and undoubtedly questions will arise from its use. Many of these questions have already been posed and answered, the most common of which are shown here.
Getting help
Q. I have a question - how can I get help?
A. The best place to get help for DataTables is on this site. There is extensive documentation on DataTables in the manual, reference, examples, these FAQs and in the forum. If you can't find the answer to your question on the site already, please post it in the forum. When posting a question about an existing table, please link to a test case showing the issue, or at the very least use the DataTables debugger to provide information about the table.
Q. I need to get an answer to this question as soon as possible!
A. Post your question in the forum as normal, and then use the support page to purchase a support package for DataTables. Purchasing support ensures you will receive assistance with the problem you are having, and also helps support the DataTables project as a whole.
Q. How can I support DataTables?
A. The best way to support DataTables is by purchasing a DataTables Plus license. Each purchase makes it possible to continue developing and supporting DataTables. Aside from that, write about DataTables and share the word!
Most common FAQs
Q. My events don't work on the second page
A. When attaching events to cells in a table controlled by DataTables, you need to be careful how it is done. Because DataTables removes nodes from the DOM, events applied with a static event listener might not be able to bind themselves to all nodes in the table. To overcome this, simply use delegated event listener options, as shown in this example.
Q. I get a JSON parsing error
A. This is due to incorrect JSON data being passed back from the server. Please refer to this technical note on how to debug and resolve this issue.
Q. "Requested unknown parameter" error
A. When DataTables requests a property that is not present in the data source for the table, you get this error. It can be caused by specifying an incorrect number of columns, missing parameters and colspan / rowspan in the body. Please refer to this technical note on how to debug and resolve this issue.
Q. I get an error message stating that an API method is not available
A. Very likely you are using a the legacy jQuery interface to DataTables and calling $().dataTable(). This form will return a jQuery object, while $().DataTable() returns a DataTables API instance. Please see the API documentation for further information.
Q. I append a row to the table using appendChild(), but it is removed on redraw.
A. The issue here is that DataTables doesn't know about your manipulation of the DOM structure - i.e. it doesn't know that you've added a new row, and when it does a redraw it will remove the unknown row. To add, edit or delete information from a DataTable you must use the DataTables API (specifically the row.add(), row().data() and row().remove() methods to add, edit and delete rows.
Q. Does DataTables work with platform X / server framework Y
A. DataTables is a Javascript library, so the server-side environment doesn't matter. As long as it can construct valid HTML or JSON DataTables can read via Ajax it will work. That said, we do publish libraries specifically for use with DataTables on a number of the most popular platforms.
Q. Why doesn't the table update if I modify the HTML?
A. This is similar to the previous question. When you initialise the DataTable, the table's contents are cached for speed optimisations - therefore any changes to the HTML after this won't be reflected in the DataTable. To update the table, use one of the following API methods: cell().data(), cells().data(), row().data() or rows().data(). If you can't avoid updating the HTML directly, you can invalidate the cache for that cell or row with cell().invalidate() and row().invalidate() (or their plural equivalents), or you can destroy the DataTable with destroy() and re-initialise.
Q. How do I sort dates and times?
A. Dates and times come in all sorts of different formats, from computer readable only to locale specific formats. DataTables has built in support for ISO6801 formatted dates and times with auto locale formatting, and support for formatted dates and times through integration with Moment.js and Luxon. The correct method to have DataTables understand your date / time information is dependent upon how the data is loaded and displayed:
- ISO8601 with no transform for output
- ISO8601 with locale based output
- ISO8601 with custom format output
- Custom format with no transform.
- Custom format to custom output format
Q. How do I keep the table sorted on the third click of a column header?
A. By default DataTables will cycle through ascending ordering, descending ordering and no ordering, repeating as needed. This is controlled with by the columns.orderSequence option. You can selectively disable that for specific columns, but to disable it completely for all tables on the page you can set the default as showing in the columns.orderSequence documentation.
General initialisation
Q. DataTables is running slow. How can I speed it up?
A. There are several ways in which you can speed up DataTables. Often the first thing to do is enable paging (paging) if it has been disabled as this simply reduces the amount of data to be displayed. Its also worth noting that scrolling (scrollX and scrollY) can have a significant impact on draw performance for tables with lots of columns, due to the calculations involved. Beyond that, the method you are using for loading the data will typically have the most significant impact on performance.
- Client-side processing - DOM sourced data: ~5'000 rows. Speed options:
orderClasses. - Client-side processing - Ajax sourced data (
ajax): ~50'000 rows. Speed options:deferRender - Server-side processing (
serverSide): millions of rows.
Note that older browsers such as IE6/7 might have lower numbers than those given above. Additionally, if you are using Firefox and using Firebug, turn off Firebug as this can have a negative impact on performance.
Q. My table isn't working!?
A. Have you got a thead and tbody defined as DataTables requires (manual - installation)? Is your HTML valid (W3C validator)? Are you seeing any Javascript errors?
Q. My styles aren't showing up / my table isn't styled.
A. Have you included the demo CSS for DataTables on your page (and got the paths correct!)?
Q. How can I move the table controls?
A. You can move the elements that DataTables puts around the table by using the layout initialisation parameter.
Q. Can I define my columns in Ajax loaded JSON?
A. This is not currently a native feature in DataTables (although it is likely to be added in future). Instead, you would need to load the JSON data using DataTable.ajax() and assign the column definition array using the columns option.
Q. How can I show the page length select when using Buttons?
A. This question arises when you use the legacy dom option to insert the Buttons into the page, but the l character in the dom string is removed (which it is in many Buttons examples). You could use the pageLength button to insert a page length button list, or add the l option back into the dom string.
Q. When using a
custom action with Buttons, the spinner runs forever
A. If you are calling the native action function for a Button from your own function, you must remember to pass all five arguments to the native one. Not passing the fifth parameter, which is a callback function, will result in the endless processing indicator. See buttons.buttons.action for an example.
This issue can also occur with the layout option when you make use of the topStart location for something other than the default pageLength. Use another layout location for the feature, pageLength, or an array to have multiple items in the topStart location.
Server-side processing
Q. It's not working... (stuck on Processing)
A. This is usually down to incorrect JSON data being passed back from the server. Please refer to this technical note on how to debug and resolve this issue.
Q. It's still not working...
A. The next most common reason for server-side processing not working is the draw variable not being returned as it was set in the request. DataTables uses draw to keep a draw count, so this is an important parameter. See server-side usage.
Q. Pagination is not enabled, or the information text shows the wrong data set count
A. This is likely to be caused by the incorrect use of recordsFiltered. recordsFiltered is the total number of records in the data set after filtering - not just the data array length (which DataTables can do itself!). So if you have no filtering recordsFiltered should be exactly the same as recordsTotal. See server-side usage.
Q. My events aren't being applied
A. What happens is that for each draw, DataTables will create the required display nodes (TR, TD etc), so old events are lost. You can either use delegated events (preferable) like in this example, or drawCallback to re-add the events on each draw. You can also use Visual Event bookmarklet to help debug event issues.
Q. How can I export the whole table when using serverSide and Buttons.
A. Buttons is a client-side process, so it can only export the data available at the client-side. When server-side processing is enabled, the full data set is not held on the client-side, so only the visible data can be exported. You can either: 1. Use a server-side process to create the files to download (recommended - the download plugin Button might be of some assistance here) or 2. Disable server-side processing.
Licensing
Q. DataTables is great! How much does it cost?
A. DataTables core and many of the extensions are free, open source software that you can download and use for whatever purpose you wish, on any and as many sites you want. The open source libraries are available under the MIT license. Some extensions have a commercial license and together form DataTables Plus. A license for DataTables Plus can be purchased on this site.
Q. We can't use MIT licensed software. What do we do?
A. In the rare case that you can't use DataTables under its available license, please get in touch to discuss alternative licensing arrangements.
Development FAQs
Q. This is great software - how can I contribute?
- Purchasing a DataTables Plus license
- Write about DataTables on your blog or social media and spread the word!
- Create plug-ins for DataTables which can be show-cased on this site.
- Answer support questions in the forums.
- Contribute patches to any bugs you find
- Test for bugs!
Q. I have created a plug-in - how can I share it with everyone else?
A. Please send it to me direct, or post it in the forum.
Q. I think I have found a bug - how do I report it?
A. Please post your bug, along with a full test case showing how to recreate the issue in the forum.