Basic DataTables

Zero Configuration

DataTables has most features enabled by default, so all you need to do to use it with your own tables is to call the construction function: $().DataTable();.

Searching, ordering and paging goodness will be immediately added to the table, as shown in this example.

NamePositionOfficeAgeStart dateSalaryAction
Tiger NixonSystem ArchitectEdinburgh6125/04/2011$320,800
Garrett WintersAccountantTokyo6325/07/2015$170,750
Ashton CoxJunior Technical AuthorSan Francisco6612/01/2009$86,000
Cedric KellySenior Javascript DeveloperEdinburgh2229/03/2016$433,060
Airi SatouAccountantTokyo3328/11/2008$162,700
Brielle WilliamsonIntegration SpecialistNew York6102/12/2012$372,000
Herrod ChandlerSales AssistantSan Francisco5906/08/2012$137,500
Rhona DavidsonIntegration SpecialistTokyo5514/10/2010$327,900
Colleen HurstJavascript DeveloperSan Francisco3915/09/2009$205,500
Sonya FrostSoftware EngineerEdinburgh2313/12/2008$103,600
Jena GainesOffice ManagerLondon3019/12/2008$90,560
Quinn FlynnSupport LeadEdinburgh2203/03/2013$342,000
Charde MarshallRegional DirectorSan Francisco3616/10/2008$470,600
Donna SniderCustomer SupportNew York2725/01/2011$112,000
Amir ReyesJS DeveloperUS2221/07/2024$148,450
Leon MannSoftware EngineerUK2023/08/2024$250,400
Eliezer OrrManagerNew York2612/05/2023$587,480
Ana HansonSEONew York2805/09/2024$145,000
Kaia KlineHRSingapore2418/09/2022$600,580
Tori HaleCustomer SupportSan Francisco2629/10/2024$120,000
Complex Headers (rowspan and colspan)

When using tables to display data, you will often wish to display column information in groups. DataTables fully supports colspan and rowspan in the table's header, assigning the required order listeners to the th tag cells suitable for the columns the element covers.

DataTables will automatically apply ordering listeners and icons to all cells in the table header. If you wish to disable this, you can use the data-dt-order property on the th/td cells in the table header. The value of this attribute (if present, it is entirely optional) controls the ordering listeners and icons:

the HR info has data-dt-order="disable" applied to it. The other cells in the header are all clickable and have ordering status icons shown.

NameHR InformationContact
PositionSalaryOfficeCVStatusE-mailAction
Tiger NixonSystem Architect$320,800Edinburgh hiredt.nixon@datatables.net
Garrett WintersAccountant$170,750Tokyo Pendingg.winters@datatables.net
Ashton CoxJunior Technical Author$86,000San Francisco in processa.cox@datatables.net
Cedric KellySenior Javascript Developer$433,060Edinburgh in processc.kelly@datatables.net
Airi SatouAccountant$162,700Tokyo hireda.satou@datatables.net
Brielle WilliamsonIntegration Specialist$372,000New York Pendingb.williamson@datatables.net
Herrod ChandlerSales Assistant$137,500San Francisco in processh.chandler@datatables.net
Rhona DavidsonIntegration Specialist$327,900Tokyo hiredr.davidson@datatables.net
Colleen HurstJavascript Developer$205,500San Francisco Pendingc.hurst@datatables.net
Sonya FrostSoftware Engineer$103,600Edinburgh in processs.frost@datatables.net
Jena GainesOffice Manager$90,560London hiredj.gaines@datatables.net
Quinn FlynnSupport Lead$342,000Edinburgh in processq.flynn@datatables.net
Charde MarshallRegional Director$470,600San Francisco in processc.marshall@datatables.net
Haley KennedySenior Marketing Designer$313,500London hiredh.kennedy@datatables.net
Tatyana FitzpatrickRegional Director$385,750London Pendingt.fitzpatrick@datatables.net
Michael SilvaMarketing Designer$198,500London in processm.silva@datatables.net
Paul ByrdChief Financial Officer (CFO)$725,000New York in processp.byrd@datatables.net
Gloria LittleSystems Administrator$237,500New York hiredg.little@datatables.net
Bradley GreerSoftware Engineer$132,000London Pendingb.greer@datatables.net
Dai RiosPersonnel Lead$217,500Edinburgh in processd.rios@datatables.net
Jenette CaldwellDevelopment Lead$345,000New York hiredj.caldwell@datatables.net
Yuri BerryChief Marketing Officer (CMO)$675,000New York Pendingy.berry@datatables.net
Caesar VancePre-Sales Support$106,450New York in processc.vance@datatables.net
Doris WilderSales Assistant$85,600Sidney hiredd.wilder@datatables.net
Angelica RamosCEO$1,200,000London Pendinga.ramos@datatables.net
Gavin JoyceDeveloper$92,575Edinburgh in processg.joyce@datatables.net
Jennifer ChangRegional Director$357,650Singapore hiredj.chang@datatables.net
Brenden WagnerSoftware Engineer$206,850San Francisco hiredb.wagner@datatables.net
Fiona GreenChief Operating Officer (COO)$850,000San Francisco Pendingf.green@datatables.net
Shou ItouRegional Marketing$163,000Tokyo in processs.itou@datatables.net
Michelle HouseIntegration Specialist$95,400Sidney hiredm.house@datatables.net
Suki BurksDeveloper$114,500London Pendings.burks@datatables.net
Prescott BartlettTechnical Author$145,000London in processp.bartlett@datatables.net
Gavin CortezTeam Leader$235,500San Francisco hiredg.cortez@datatables.net
Martena MccrayPost-Sales support$324,050Edinburgh hiredm.mccray@datatables.net
Unity ButlerMarketing Designer$85,675San Francisco Pendingu.butler@datatables.net
Howard HatfieldOffice Manager$164,500San Francisco in processh.hatfield@datatables.net
Hope FuentesSecretary$109,850San Francisco hiredh.fuentes@datatables.net
Vivian HarrellFinancial Controller$452,500San Francisco Pendingv.harrell@datatables.net
Timothy MooneyOffice Manager$136,200London in processt.mooney@datatables.net
Jackson BradshawDirector$645,750New York hiredj.bradshaw@datatables.net
Olivia LiangSupport Engineer$234,500Singapore Pendingo.liang@datatables.net
Bruno NashSoftware Engineer$163,500London in processb.nash@datatables.net
Sakura YamamotoSupport Engineer$139,575Tokyo Pendings.yamamoto@datatables.net
Thor WaltonDeveloper$98,540New York in processt.walton@datatables.net
Finn CamachoSupport Engineer$87,500San Francisco hiredf.camacho@datatables.net
Serge BaldwinData Coordinator$138,575Singapore Pendings.baldwin@datatables.net
Zenaida FrankSoftware Engineer$125,250New York in processz.frank@datatables.net
Zorita SerranoSoftware Engineer$115,000San Francisco hiredz.serrano@datatables.net
Jennifer AcostaJunior Javascript Developer$75,650Edinburgh Pendingj.acosta@datatables.net
Cara StevensSales Assistant$145,600New York in processc.stevens@datatables.net
Hermione ButlerRegional Director$356,250London hiredh.butler@datatables.net
Lael GreerSystems Administrator$103,500London Pendingl.greer@datatables.net
Jonas AlexanderDeveloper$86,500San Francisco in processj.alexander@datatables.net
Shad DeckerRegional Director$183,000Edinburgh hireds.decker@datatables.net
Michael BruceJavascript Developer$183,000Singapore hiredm.bruce@datatables.net
Donna SniderCustomer Support$112,000New York hiredd.snider@datatables.net
NamePositionSalaryOfficeCV StatusE-mailAction
State Saving

DataTables saves the state of a table (its paging position, ordering state etc). When the stateSave option is enabled, it can be restored when the user reloads a page, or comes back to the page after visiting a sub-page.

The built in state saving method uses the HTML5 localStorage and sessionStorage APIs for efficient storage of the data. Please note that this means that the built in state saving option will not work with IE6/7 as these browsers do not support these APIs. Alternative options of using cookies or saving the state on the server through Ajax can be used through the stateSaveCallback and stateLoadCallback options.

The duration for which the saved state is valid and can be used to restore the table state can be set using the stateDuration initialisation parameter (2 hours by default). This parameter also controls if localStorage (0 or greater) or sessionStorage (-1) is used to store the data.

The example below simply shows state saving enabled in DataTables with the stateSave option.

NamePositionOfficeAgeStart DateSalaryAction
Tiger NixonSystem ArchitectEdinburgh6125/04/2011$320,800
Garrett WintersAccountantTokyo6325/07/2015$170,750
Ashton CoxJunior Technical AuthorSan Francisco6612/01/2009$86,000
Cedric KellySenior Javascript DeveloperEdinburgh2229/03/2016$433,060
Airi SatouAccountantTokyo3328/11/2008$162,700
Brielle WilliamsonIntegration SpecialistNew York6102/12/2012$372,000
Herrod ChandlerSales AssistantSan Francisco5906/08/2012$137,500
Rhona DavidsonIntegration SpecialistTokyo5514/10/2010$327,900
Colleen HurstJavascript DeveloperSan Francisco3915/09/2009$205,500
Sonya FrostSoftware EngineerEdinburgh2313/12/2008$103,600
Jena GainesOffice ManagerLondon3019/12/2008$90,560
Quinn FlynnSupport LeadEdinburgh2203/03/2013$342,000
Charde MarshallRegional DirectorSan Francisco3616/10/2008$470,600
Haley KennedySenior Marketing DesignerLondon4318/12/2012$313,500
Tatyana FitzpatrickRegional DirectorLondon1917/03/2010$385,750
Michael SilvaMarketing DesignerLondon6627/11/2012$198,500
Paul ByrdChief Financial Officer (CFO)New York6409/06/2010$725,000
Gloria LittleSystems AdministratorNew York5910/04/2009$237,500
Bradley GreerSoftware EngineerLondon4113/10/2024$132,000
Dai RiosPersonnel LeadEdinburgh3526/09/2022$217,500
Jenette CaldwellDevelopment LeadNew York3003/09/2009$345,000
Yuri BerryChief Marketing Officer (CMO)New York4025/06/2009$675,000
Caesar VancePre-Sales SupportNew York2112/12/2016$106,450
Doris WilderSales AssistantSidney2320/09/2008$85,600
Angelica RamosChief Executive Officer (CEO)London4709/10/2021$1,200,000
Gavin JoyceDeveloperEdinburgh4222/12/2024$92,575
Jennifer ChangRegional DirectorSingapore2814/11/2023$357,650
Brenden WagnerSoftware EngineerSan Francisco2807/06/2020$206,850
Fiona GreenChief Operating Officer (COO)San Francisco4811/03/2010$850,000
Shou ItouRegional MarketingTokyo2014/08/2008$163,000
Michelle HouseIntegration SpecialistSidney3702/06/2011$95,400
Suki BurksDeveloperLondon5322/10/2009$114,500
Prescott BartlettTechnical AuthorLondon2707/05/2005$145,000
Gavin CortezTeam LeaderSan Francisco2226/10/2023$235,500
Martena MccrayPost-Sales supportEdinburgh4609/03/2011$324,050
Unity ButlerMarketing DesignerSan Francisco4709/12/2009$85,675
Howard HatfieldOffice ManagerSan Francisco5116/12/2016$164,500
Hope FuentesSecretarySan Francisco412010/02/12$109,850
Vivian HarrellFinancial ControllerSan Francisco6214/02/2015$452,500
Timothy MooneyOffice ManagerLondon3711/12/2016$136,200
Jackson BradshawDirectorNew York6526/09/2024$645,750
Olivia LiangSupport EngineerSingapore6413/02/2017$234,500
Bruno NashSoftware EngineerLondon3803/05/2014$163,500
Sakura YamamotoSupport EngineerTokyo3719/08/2014$139,575
Thor WaltonDeveloperNew York6111/08/2013$98,540
Finn CamachoSupport EngineerSan Francisco4707/07/2009$87,500
Serge BaldwinData CoordinatorSingapore6409/04/2015$138,575
Zenaida FrankSoftware EngineerNew York6304/01/2010$125,250
Zorita SerranoSoftware EngineerSan Francisco5601/06/2010$115,000
Jennifer AcostaJunior Javascript DeveloperEdinburgh4320/02/2012$75,650
Cara StevensSales AssistantNew York4606/12/2016$145,600
Hermione ButlerRegional DirectorLondon4721/03/2018$356,250
Lael GreerSystems AdministratorLondon2127/02/2019$103,500
Jonas AlexanderDeveloperSan Francisco3014/07/2010$86,500
Shad DeckerRegional DirectorEdinburgh5113/11/2008$183,000
Michael BruceJavascript DeveloperSingapore2927/06/2011$183,000
Donna SniderCustomer SupportNew York2725/01/2011$112,000
NamePositionOfficeAgeStart dateSalaryAction
Scroll - vertical, dynamic height

This example shows a vertically scrolling DataTable that makes use of the CSS3 vh unit in order to dynamically resize the viewport based on the browser window height. The vh unit is effectively a percentage of the browser window height. So the 50vh used in this example is 50% of the window height. The viewport size will update dynamically as the window is resized.

A relatively modern browser is required for vh units to operate correctly. IE9+ supports the vh unit and all other evergreen browsers.

NamePositionOfficeAgeStart DateSalaryAction
Tiger NixonSystem ArchitectEdinburgh6125/04/2011$320,800
Garrett WintersAccountantTokyo6325/07/2015$170,750
Ashton CoxJunior Technical AuthorSan Francisco6612/01/2009$86,000
Cedric KellyJS DeveloperEdinburgh2229/03/2016$433,060
Airi SatouAccountantTokyo3328/11/2008$162,700
Brielle WilliamsonIntegration SpecialistNew York6102/12/2012$372,000
Herrod ChandlerSales AssistantSan Francisco5906/08/2012$137,500
Rhona DavidsonIntegration SpecialistTokyo5514/10/2010$327,900
Colleen HurstJavascript DeveloperSan Francisco3915/09/2009$205,500
Sonya FrostSoftware EngineerEdinburgh2313/12/2008$103,600
Jena GainesOffice ManagerLondon3014/12/2023$90,560
Quinn FlynnSupport LeadEdinburgh2213/03/2022$342,000
Charde MarshallRegional DirectorSan Francisco3616/10/2008$470,600
Haley KennedySenior Marketing DesignerLondon4318/12/2012$313,500
Tatyana FitzpatrickRegional DirectorLondon1917/03/2010$385,750
Michael SilvaMarketing DesignerLondon6627/11/2024$198,500
Paul ByrdChief Financial Officer (CFO)New York6408/06/2007$725,000
Gloria LittleSystems AdministratorNew York5919/04/2016$237,500
Bradley GreerSoftware EngineerLondon4113/10/2019$132,000
Dai RiosPersonnel LeadEdinburgh3526/09/2020$217,500
Jenette CaldwellDevelopment LeadNew York3021/09/2018$345,000
Yuri BerryChief Marketing Officer (CMO)New York4025/06/2009$675,000
Caesar VancePre-Sales SupportNew York2112/12/2009$106,450
Doris WilderSales AssistantSidney2320/09/2015$85,600
Angelica RamosCEOLondon4709/10/2015$1,200,000
Gavin JoyceDeveloperEdinburgh4222/12/2010$92,575
Jennifer ChangRegional DirectorSingapore2814/11/2014$357,650
Brenden WagnerSoftware EngineerSan Francisco2807/06/2018$206,850
Fiona GreenChief Operating Officer (COO)San Francisco4811/03/2016$850,000
Shou ItouRegional MarketingTokyo2014/08/2014$163,000
Michelle HouseIntegration SpecialistSidney3702/06/2014$95,400
Suki BurksDeveloperLondon5322/10/2019$114,500
Prescott BartlettTechnical AuthorLondon2707/05/2018$145,000
Gavin CortezTeam LeaderSan Francisco2226/10/2021$235,500
Martena MccrayPost-Sales supportEdinburgh4606/03/2019$324,050
Unity ButlerMarketing DesignerSan Francisco4709/12/2009$85,675
Howard HatfieldOffice ManagerSan Francisco5116/12/2016$164,500
Hope FuentesSecretarySan Francisco4112/02/2015$109,850
Vivian HarrellFinancial ControllerSan Francisco6214/02/2014$452,500
Timothy MooneyOffice ManagerLondon3711/12/2010$136,200
Jackson BradshawDirectorNew York6526/09/2020$645,750
Olivia LiangSupport EngineerSingapore6403/02/2011$234,500
Bruno NashSoftware EngineerLondon3826/05/2019$163,500
Sakura YamamotoSupport EngineerTokyo3721/08/2019$139,575
Thor WaltonDeveloperNew York6113/08/2015$98,540
Finn CamachoSupport EngineerSan Francisco4707/07/2007$87,500
Serge BaldwinData CoordinatorSingapore6409/04/2015$138,575
Zenaida FrankSoftware EngineerNew York6320/01/2018$125,250
Zorita SerranoSoftware EngineerSan Francisco5601/06/2006$115,000
Jennifer AcostaJunior Javascript DeveloperEdinburgh4315/02/2015$75,650
Cara StevensSales AssistantNew York4608/12/2018$145,600
Hermione ButlerRegional DirectorLondon4724/03/2021$356,250
Lael GreerSystems AdministratorLondon2127/02/2019$103,500
Jonas AlexanderDeveloperSan Francisco3014/07/2018$86,500
Shad DeckerRegional DirectorEdinburgh5115/11/2018$183,000
Michael BruceJavascript DeveloperSingapore2927/06/2015$183,000
Donna SniderCustomer SupportNew York2725/01/2020$112,000
NamePositionOfficeAgeStart dateSalaryAction