Wednesday 30th April, 2025
By Allan Jardine

DataTables 2.3

I'm delighted to announce the release of DataTables 2.3.0. This release adds a number of new options and updates, plus a number of patches for issues discovered in previous versions. There is a particular focus on how the column headers of the table are drawn and controlled, as this sets out the groundwork for a new extension to the DataTables family which will be released soon, ColumnControl (keep an eye on this blog for more details when it is released)!

If you are keen to get going with DataTables 2.3 it is available now:

Full release notes are available here.

Example table

Let's take a look at a table rendered by DataTables 2.3:

NamePositionOfficeSalary
Tiger NixonSystem ArchitectEdinburgh$320,800
Garrett WintersAccountantTokyo$170,750
Ashton CoxJunior Technical AuthorSan Francisco$86,000
Cedric KellySenior Javascript DeveloperEdinburgh$433,060
Airi SatouAccountantTokyo$162,700
Brielle WilliamsonIntegration SpecialistNew York$372,000
Herrod ChandlerSales AssistantSan Francisco$137,500
Rhona DavidsonIntegration SpecialistTokyo$327,900
Colleen HurstJavascript DeveloperSan Francisco$205,500
Sonya FrostSoftware EngineerEdinburgh$103,600
Jena GainesOffice ManagerLondon$90,560
Quinn FlynnSupport LeadEdinburgh$342,000
Charde MarshallRegional DirectorSan Francisco$470,600
Haley KennedySenior Marketing DesignerLondon$313,500
Tatyana FitzpatrickRegional DirectorLondon$385,750
Michael SilvaMarketing DesignerLondon$198,500
Paul ByrdChief Financial Officer (CFO)New York$725,000
Gloria LittleSystems AdministratorNew York$237,500
Bradley GreerSoftware EngineerLondon$132,000
Dai RiosPersonnel LeadEdinburgh$217,500
Jenette CaldwellDevelopment LeadNew York$345,000
Yuri BerryChief Marketing Officer (CMO)New York$675,000
Caesar VancePre-Sales SupportNew York$106,450
Doris WilderSales AssistantSydney$85,600
Angelica RamosChief Executive Officer (CEO)London$1,200,000
Gavin JoyceDeveloperEdinburgh$92,575
Jennifer ChangRegional DirectorSingapore$357,650
Brenden WagnerSoftware EngineerSan Francisco$206,850
Fiona GreenChief Operating Officer (COO)San Francisco$850,000
Shou ItouRegional MarketingTokyo$163,000
Michelle HouseIntegration SpecialistSydney$95,400
Suki BurksDeveloperLondon$114,500
Prescott BartlettTechnical AuthorLondon$145,000
Gavin CortezTeam LeaderSan Francisco$235,500
Martena MccrayPost-Sales supportEdinburgh$324,050
Unity ButlerMarketing DesignerSan Francisco$85,675
Howard HatfieldOffice ManagerSan Francisco$164,500
Hope FuentesSecretarySan Francisco$109,850
Vivian HarrellFinancial ControllerSan Francisco$452,500
Timothy MooneyOffice ManagerLondon$136,200
Jackson BradshawDirectorNew York$645,750
Olivia LiangSupport EngineerSingapore$234,500
Bruno NashSoftware EngineerLondon$163,500
Sakura YamamotoSupport EngineerTokyo$139,575
Thor WaltonDeveloperNew York$98,540
Finn CamachoSupport EngineerSan Francisco$87,500
Serge BaldwinData CoordinatorSingapore$138,575
Zenaida FrankSoftware EngineerNew York$125,250
Zorita SerranoSoftware EngineerSan Francisco$115,000
Jennifer AcostaJunior Javascript DeveloperEdinburgh$75,650
Cara StevensSales AssistantNew York$145,600
Hermione ButlerRegional DirectorLondon$356,250
Lael GreerSystems AdministratorLondon$103,500
Jonas AlexanderDeveloperSan Francisco$86,500
Shad DeckerRegional DirectorEdinburgh$183,000
Michael BruceJavascript DeveloperSingapore$183,000
Donna SniderCustomer SupportNew York$112,000

It will immediately be familiar if you have used DataTables before, however, if you look closely at the header you will notice that the column title now aligns correctly with the text in the column below.

This is an evolution of how DataTables has aligned the text for the header:

  • 1.x - Header text was always left aligned with the ordering icon on the right.
  • 2.0-2.2 - Introduced automatic right text alignment for numbers and dates, but left the ordering icon on the right. While this helped with readability for the date, the title text didn't align correctly due to the icon.
  • 2.3 - The ordering icon is on the opposite side of the header text, allowing the text in the column to correctly align between the header and body.

Furthermore, if you "Inspect" the header cell, you will now see that it has a div.dt-column-header element inside it, and uses flexbox for the layout. This is done to allow the addition of other elements to the header - specifically the aforementioned ColumnControl!

New features

New header control options

Continuing the focus on updating the capabilities of the header in DataTables there are a number of new options:

  • titleRow - provides the ability to make any row in the header the "title" row (i.e. where columns.title are read/written, and ordering icons/actions are added). Note that this replaces the old orderCellsTop option. That option is still supported for backward compatibility, but it is recommended that you use titleRow for new projects.
  • ordering.handler - can be used to enable/disable the default column header click-to-order listener.
  • ordering.indicator - can be used to enable/disable the ordering icons in the table's header cells.

Ajax data submission format

When submitting data to the server (e.g. Ajax loading data, or full server-side processing), DataTables uses HTTP parameters. There are, however, times when you might wish to send JSON to the server (particularly for .NET) - it is easy to parse, has (limited) types, and null values. Previously you would use ajax.data and return a string - e.g.:

ajax: {
    url: '/api/data',
    data: d => JSON.stringify(d)
}

The problem with this is that ajax.data executes before preXhr, so any extension or plugin that needs to add extra data to send to the server couldn't without extra processing (it would just see a string).

With 2.3 a new ajax.submitAs option is introduced which will inform DataTables how you want the data to be submitted. It will be either http (default) or json and has DataTables do the stringify of the data for you. So now you would use:

ajax: {
    url: '/api/data',
    submitAs: 'json'
}

The old method still works for backwards compatibility, but it is now strongly recommended that you use ajax.submitAs if you wish to submit a JSON string.

Events on initialisation

There are a lot of events that DataTables can trigger, and they are easily listened for using on(). However, you might wish to listen for events during DataTables' initialisation (i.e. before the API instance is available) - draw and preXhr are perhaps the most common two events for this use case.

Previously, you would need to use jQuery for this - e.g.:

$('#myTable')
    .on('preXhr.dt', (s, s, data) => {
        data.myParameter = true;
    })
    .DataTable({
        ajax: '/api/data'
    });

With the new on parameter you can assign listeners in the DataTables initialisation object and not write any jQuery-based code:

new DataTable('#myTable', {
    ajax: '/api/data',
    on: {
        preXhr: (e, s, data) => {
            data.myParameter = true;
        }
    }
});

Multiple events can be listened for; the event name you want to listen for is the key for the on object.

Upgrading

Upgrading to 2.3 is just a case of updating DataTables' JS and CSS files:

You are unlikely to run into upgrade issues when moving from 2.3, but you may wish to check over the release notes regardless.

As always, I hope you enjoy using DataTables. Feedback is always welcome in the forums.