DataTables example Ordering plug-ins (no type detection)

Although DataTables will order a number of data types using the built in methods, When dealing with more complex formatted data, it can be desirable to define the ordering order yourself. Using plug-in ordering functions, you have have DataTables order data in any manner you wish.

This is done by using the columns.type parameter, in combination with a ordering plug-in. The ordering plug-in can be be of any level of complexity (natural ordering for example can be fairly complex while also very powerful), and is defined by attaching to the $.fn.dataTable.ext.type.order object. For more information about ordering plug-ins; creating them and their requirements, please refer to the plug-in development documentation.

This example shows ordering with using an enumerated type.

A wide variety of ready made ordering plug-ins can be found on the DataTables plug-ins page.

NamePositionOfficeAgeStart dateSalary
NamePositionOfficeAgeStart dateSalary
Tiger NixonSystem ArchitectEdinburgh612011/04/25Low
Garrett WintersAccountantTokyo632011/07/25Low
Ashton CoxJunior Technical AuthorSan Francisco662009/01/12Low
Cedric KellySenior Javascript DeveloperEdinburgh222012/03/29Medium
Airi SatouAccountantTokyo332008/11/28Low
Brielle WilliamsonIntegration SpecialistNew York612012/12/02Medium
Herrod ChandlerSales AssistantSan Francisco592012/08/06Low
Rhona DavidsonIntegration SpecialistTokyo552010/10/14Low
Colleen HurstJavascript DeveloperSan Francisco392009/09/15Low
Sonya FrostSoftware EngineerEdinburgh232008/12/13Low
Jena GainesOffice ManagerLondon302008/12/19Low
Quinn FlynnSupport LeadEdinburgh222013/03/03Low
Charde MarshallRegional DirectorSan Francisco362008/10/16Medium
Haley KennedySenior Marketing DesignerLondon432012/12/18Low
Tatyana FitzpatrickRegional DirectorLondon192010/03/17Medium
Michael SilvaMarketing DesignerLondon662012/11/27Low
Paul ByrdChief Financial Officer (CFO)New York642010/06/09High
Gloria LittleSystems AdministratorNew York592009/04/10Low
Bradley GreerSoftware EngineerLondon412012/10/13Low
Dai RiosPersonnel LeadEdinburgh352012/09/26Low
Jenette CaldwellDevelopment LeadNew York302011/09/03Low
Yuri BerryChief Marketing Officer (CMO)New York402009/06/25High
Caesar VancePre-Sales SupportNew York212011/12/12Low
Doris WilderSales AssistantSidney232010/09/20Low
Angelica RamosChief Executive Officer (CEO)London472009/10/09High
Gavin JoyceDeveloperEdinburgh422010/12/22Low
Jennifer ChangRegional DirectorSingapore282010/11/14Medium
Brenden WagnerSoftware EngineerSan Francisco282011/06/07Low
Fiona GreenChief Operating Officer (COO)San Francisco482010/03/11High
Shou ItouRegional MarketingTokyo202011/08/14Low
Michelle HouseIntegration SpecialistSidney372011/06/02Low
Suki BurksDeveloperLondon532009/10/22Low
Prescott BartlettTechnical AuthorLondon272011/05/07Low
Gavin CortezTeam LeaderSan Francisco222008/10/26Low
Martena MccrayPost-Sales supportEdinburgh462011/03/09Low
Unity ButlerMarketing DesignerSan Francisco472009/12/09Low
Howard HatfieldOffice ManagerSan Francisco512008/12/16Low
Hope FuentesSecretarySan Francisco412010/02/12Low
Vivian HarrellFinancial ControllerSan Francisco622009/02/14Medium
Timothy MooneyOffice ManagerLondon372008/12/11Low
Jackson BradshawDirectorNew York652008/09/26Medium
Olivia LiangSupport EngineerSingapore642011/02/03Low
Bruno NashSoftware EngineerLondon382011/05/03Low
Sakura YamamotoSupport EngineerTokyo372009/08/19Low
Thor WaltonDeveloperNew York612013/08/11Low
Finn CamachoSupport EngineerSan Francisco472009/07/07Low
Serge BaldwinData CoordinatorSingapore642012/04/09Low
Zenaida FrankSoftware EngineerNew York632010/01/04Low
Zorita SerranoSoftware EngineerSan Francisco562012/06/01Low
Jennifer AcostaJunior Javascript DeveloperEdinburgh432013/02/01Low
Cara StevensSales AssistantNew York462011/12/06Low
Hermione ButlerRegional DirectorLondon472011/03/21Medium
Lael GreerSystems AdministratorLondon212009/02/27Low
Jonas AlexanderDeveloperSan Francisco302010/07/14Low
Shad DeckerRegional DirectorEdinburgh512008/11/13Low
Michael BruceJavascript DeveloperSingapore292011/06/27Low
Donna SniderCustomer SupportNew York272011/01/25Low

The Javascript shown below is used to initialise the table shown in this example:

$.fn.dataTable.ext.type.order['salary-grade-pre'] = function ( d ) { switch ( d ) { case 'Low': return 1; case 'Medium': return 2; case 'High': return 3; } return 0; }; $(document).ready(function() { $('#example').DataTable( { "columnDefs": [ { "type": "salary-grade", "targets": -1 } ] } ); } );

In addition to the above code, the following Javascript library files are loaded for use in this example:

The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:

This example uses a little bit of additional CSS beyond what is loaded from the library files (below), in order to correctly display the table. The additional CSS used is shown below:

The following CSS library files are loaded for use in this example to provide the styling of the table:

This table loads data by Ajax. The latest data that has been loaded is shown below. This data will update automatically as any additional data is loaded.

The script used to perform the server-side processing for this table is shown below. Please note that this is just an example script using PHP. Server-side processing scripts can be written in any language, using the protocol described in the DataTables documentation.