Advanced Datatable

DOM / jQuery events

Events assigned to the table can be exceptionally useful for user interaction, however you must be aware that DataTables will add and remove rows from the DOM as they are needed (i.e. when paging only the visible elements are actually available in the DOM). As such, this can lead to the odd hiccup when working with events.

NamePositionOfficeAgeStart dateSalary
Airi SatouAccountantTokyo332008/11/28$162,700
Ashton CoxJunior Technical AuthorSan Francisco662009/01/12$86,000
Bradley GreerSoftware EngineerLondon412012/10/13$132,000
Brielle WilliamsonIntegration SpecialistNew York612012/12/02$372,000
Cedric KellySenior Javascript DeveloperEdinburgh222012/03/29$433,060
Charde MarshallRegional DirectorSan Francisco362008/10/16$470,600
Colleen HurstJavascript DeveloperSan Francisco392009/09/15$205,500
Dai RiosPersonnel LeadEdinburgh352012/09/26$217,500
Garrett WintersAccountantTokyo632011/07/25$170,750
Gloria LittleSystems AdministratorNew York592009/04/10$237,500
NamePositionOfficeAgeStart dateSalary
Showing 1 to 10 of 20 entries

Column rendering

Each column has an optional rendering control called columns.render which can be used to process the content of each cell before the data is used. columns.render has a wide array of options available to it for rendering different types of data orthogonally (ordering, searching, display etc), but it can be used very simply to manipulate the content of a cell, as shown here.

NamePositionOfficeStart dateSalary
Airi Satou (33)AccountantTokyo2008/11/28$162,700
Ashton Cox (66)Junior Technical AuthorSan Francisco2009/01/12$86,000
Bradley Greer (41)Software EngineerLondon2012/10/13$132,000
Brielle Williamson (61)Integration SpecialistNew York2012/12/02$372,000
Cedric Kelly (22)Senior Javascript DeveloperEdinburgh2012/03/29$433,060
Charde Marshall (36)Regional DirectorSan Francisco2008/10/16$470,600
Colleen Hurst (39)Javascript DeveloperSan Francisco2009/09/15$205,500
Dai Rios (35)Personnel LeadEdinburgh2012/09/26$217,500
Garrett Winters (63)AccountantTokyo2011/07/25$170,750
Gloria Little (59)Systems AdministratorNew York2009/04/10$237,500
NamePositionOfficeStart dateSalary
Showing 1 to 10 of 20 entries

Read HTML to data objects

When DataTables reads the table content from an HTML table (rather than an Ajax or Javascript data source), by default it will read the information in the table into an array that DataTables stores internally. Each array element represents a column.

NamePositionOfficeAgeStart dateSalary
Airi SatouAccountantTokyo332008/11/28$162,700
Ashton CoxJunior Technical AuthorSan Francisco662009/01/12$86,000
Bradley GreerSoftware EngineerLondon412012/10/13$132,000
Brielle WilliamsonIntegration SpecialistNew York612012/12/02$372,000
Cedric KellySenior Javascript DeveloperEdinburgh222012/03/29$433,060
Charde MarshallRegional DirectorSan Francisco362008/10/16$470,600
Colleen HurstJavascript DeveloperSan Francisco392009/09/15$205,500
Dai RiosPersonnel LeadEdinburgh352012/09/26$217,500
Garrett WintersAccountantTokyo632011/07/25$170,750
Gloria LittleSystems AdministratorNew York592009/04/10$237,500
NamePositionOfficeAgeStart dateSalary
Showing 1 to 10 of 20 entries

Row created callback

The following example shows how a callback function can be used to format a particular row at draw time. For each row that is generated for display, the createdRow function is called once and once only. It is passed the create row node which can then be modified.

NamePositionOfficeAgeStart dateSalary
Airi SatouAccountantTokyo332008/11/28$162,700
Ashton CoxJunior Technical AuthorSan Francisco662009/01/12$86,000
Bradley GreerSoftware EngineerLondon412012/10/13$132,000
Brielle WilliamsonIntegration SpecialistNew York612012/12/02$372,000
Cedric KellySenior Javascript DeveloperEdinburgh222012/03/29$433,060
Charde MarshallRegional DirectorSan Francisco362008/10/16$470,600
Colleen HurstJavascript DeveloperSan Francisco392009/09/15$205,500
Dai RiosPersonnel LeadEdinburgh352012/09/26$217,500
Garrett WintersAccountantTokyo632011/07/25$170,750
Gloria LittleSystems AdministratorNew York592009/04/10$237,500
NamePositionOfficeAgeStart dateSalary
Showing 1 to 10 of 20 entries