Type detection plug-ins

When a DataTable is initialised, each column is scanned automatically for the type of data it contains, which in turn allows DataTables to apply the require type of sorting function. There are three built-in types (string, date and numeric) but this can readily be expanded using the functions below. This can make installed a sorting plug-in much easier since you need not specify the columns.type for the column - it will be picked up automatically.

How to use

To use of one of the plug-in type detections functions below, you simply need to include it and its counterpart sorting function in the Javascript available for your page, after you load the DataTables library, but before you initialise the DataTable. Then all you need to do is initialise the DataTable and the type will be automatically detected.

Browser

Loading type detection plug-ins directly in the browser is just a case of loading the Javascript for the plug-in. As an example the code below makes use of the file-size plug-ins for type detection and sorting saved into a single file:

<script type="text/javascript" src="dataTables.js"></script>
<script type="text/javascript" src="dataTables.file-size.js"></script>
<script type="text/javascript">
    var table = new DataTable('#myTable');
</script>

Plug-ins which can be included in the browser are available on our CDN. See the details page for each plug-in for the full CDN URL.

ES modules

The type detection plug-ins are also available as ES modules, which can be loaded from the datatables.net-plugins package (.mjs files). You need to include the file required for the plug-in. Below we use the example of file-size again:

import DataTable from 'datatables.net';
import 'datatables.net-plugins/sorting/file-size.mjs';
import 'datatables.net-plugins/type-detection/file-size.mjs';

var table = new DataTable('#myTable');

Plug-ins