New in DataTables 2

DataTables 2.1 is the first minor release of the 2.x series and introduces a number of new features, as well as addressing points that have come to light since 2.0 was released.

This document is part of a number of related documents detailing the release of DataTables 2.1:

Layout

One of the big new features in DataTables 2 was the introduction of layout, which replaces the legacy dom option as something that is much easier to work with. Based on feedback 2.1 now places features that are in the same layout cell (i.e. an array) on the same line. Also items in a full width cell (e.g. simply top or bottom) are spaced evenly on the row.

To see this in action, consider the table below:

NameOfficeStart dateSalary
Tiger NixonEdinburgh2011-04-25320800
Garrett WintersTokyo2011-07-25170750
Ashton CoxSan Francisco2009-01-1286000
Cedric KellyEdinburgh2012-03-29433060
Airi SatouTokyo2008-11-28162700
Brielle WilliamsonNew York2012-12-02372000
Herrod ChandlerSan Francisco2012-08-06137500
Rhona DavidsonTokyo2010-10-14327900
Colleen HurstSan Francisco2009-09-15205500
Sonya FrostEdinburgh2008-12-13103600
Jena GainesLondon2008-12-1990560
Quinn FlynnEdinburgh2013-03-03342000
Charde MarshallSan Francisco2008-10-16470600
Haley KennedyLondon2012-12-18313500
Tatyana FitzpatrickLondon2010-03-17385750
Michael SilvaLondon2012-11-27198500
Paul ByrdNew York2010-06-09725000
Gloria LittleNew York2009-04-10237500
Bradley GreerLondon2012-10-13132000
Dai RiosEdinburgh2012-09-26217500
Jenette CaldwellNew York2011-09-03345000
Yuri BerryNew York2009-06-25675000
Caesar VanceNew York2011-12-12106450
Doris WilderSydney2010-09-2085600
Angelica RamosLondon2009-10-091200000
Gavin JoyceEdinburgh2010-12-2292575
Jennifer ChangSingapore2010-11-14357650
Brenden WagnerSan Francisco2011-06-07206850
Fiona GreenSan Francisco2010-03-11850000
Shou ItouTokyo2011-08-14163000
Michelle HouseSydney2011-06-0295400
Suki BurksLondon2009-10-22114500
Prescott BartlettLondon2011-05-07145000
Gavin CortezSan Francisco2008-10-26235500
Martena MccrayEdinburgh2011-03-09324050
Unity ButlerSan Francisco2009-12-0985675
Howard HatfieldSan Francisco2008-12-16164500
Hope FuentesSan Francisco2010-02-12109850
Vivian HarrellSan Francisco2009-02-14452500
Timothy MooneyLondon2008-12-11136200
Jackson BradshawNew York2008-09-26645750
Olivia LiangSingapore2011-02-03234500
Bruno NashLondon2011-05-03163500
Sakura YamamotoTokyo2009-08-19139575
Thor WaltonNew York2013-08-1198540
Finn CamachoSan Francisco2009-07-0787500
Serge BaldwinSingapore2012-04-09138575
Zenaida FrankNew York2010-01-04125250
Zorita SerranoSan Francisco2012-06-01115000
Jennifer AcostaEdinburgh2013-02-0175650
Cara StevensNew York2011-12-06145600
Hermione ButlerLondon2011-03-21356250
Lael GreerLondon2009-02-27103500
Jonas AlexanderSan Francisco2010-07-1486500
Shad DeckerEdinburgh2008-11-13183000
Michael BruceSingapore2011-06-27183000
Donna SniderNew York2011-01-25112000

Here the top most row (top1) has only a Start cell, and you'll be able to see that the three feature elements are on the same row. The next row also have three feature elements, but as it is a "full" row, they are equally spaced. This addition makes it much easier to have more than just two items on a row, while keeping the ease of use of layout.

A more complete example of the layout options is available here.

IDs and class names

2.1 also introduces the ability to set the class name and id of rows and cells created by layout. See this example and the layout documentation for details.

Table width

Related to layout, DataTables will now automatically set the table width to 100% if no style="width: ... or width attributes are found. Almost all tables I've encountered use 100% width, but it is surprisingly difficult to read a relative value from CSS, so DataTables will now make this assumption to help assist with clean and simple markup.

Data type detection and accented characters

DataTables 2.1 introduces a major enhancement to the way data type detection works. Previously a single function was used and if all data points in a column passed the function's test the column would be assigned that data type. However, that lead to issues with similar and empty data - for example a column with FontAwesome icons in it could be found to be numeric, since the HTML was stripped and the numeric data type allows empty cells!

With 2.1 a type detection function can now specify oneOf and allOf functions. At least one data point from a column must pass the new oneOf function, while allOf is the same as the previous behaviour. Backwards compatibility is still assured with support for a single function. This allows a tightening of the data type tests, which have been implemented.

Auto ordering for accented characters

As part of the type detection improvements, 2.1 introduces a new data type: string-utf8. This is distinct from string and is matched if a string contains a character that is outside the ASCII range. This new data type will make use of localeCompare to order data, allowing correct ordering for accented characters. It is not used for columns with ASCII only characters as it is slower than a simple string compare.

Bulma 1

Bulma is a popular CSS framework for building modern web apps and sites, and has long been supported by DataTables. Earlier in the year Bulma released 1.0 (huge coagulations to the team) and DataTables 2.1 has been updated to fully support the new release. Bulma also introduced a dark mode in 1.0, which is also now fully supported in DataTables. The DataTables examples can all have "Bulma" selected as the styling framework, and you can alternate between light and dark mode as needed.

This takes the support for dark mode in our supported frameworks to three: DataTables default, Bootstrap 5, and now Bulma 1.

Use method

When loading DataTables directly in the browser it will automatically look for certain libraries such as Moment.js and Luxon, making use of them if available. This isn't possible in an ESM environment where libraries don't attach to the global scope. In such a case you need to tell DataTables about the external libraries, which you can now do with the DataTable.use() static method.

For example, the code below is the same as this example, but for ESM (to then be transformed via a bundler such as Vite or Webpack):

import moment from 'moment';
import DataTable from 'datatables.net';

// Tell DataTables that it can use Moment for date formatting
DataTable.use(moment, 'moment');

// Tell DataTables what date format you want to look for in the HTML data
DataTable.datetime('D MMM YYYY');

// Initialise DataTables
new DataTable('#example');

And more...

There are other smaller additions to 2.1 - these are just the "big ticket" items. Please see the release notes for full details on additions and changes in DataTables 2.1.