Formatted Date using Luxon

This example includes multiple date formats that are not in the standard format to demonstrate how SearchBuilder operates with formatted dates.

This example also makes use of the Ultimate Sorting plug in for dates, along with Luxon. SearchBuilder will automatically detect the type and format of the columns. Here the columns.type will be luxon. This can be accessed in the same way as others to edit the conditions that are available by using searchBuilder.conditions[type][cond].

Name Company Created Updated
Dai Weeks Eu Foundation 11:10 Oct 18, 14 Sat, May 16, 2015
Jade Dale Sit Amet Inc. 07:04 Apr 29, 14 Sat, July 25, 2015
Melanie Buckner Tempus Lorem LLC 02:01 Jan 28, 15 Sun, October 11, 2015
Cyrus Haney Phasellus Corp. 10:01 Jan 28, 14 Sat, December 28, 2013
Melinda Salas Molestie Sed Id Limited 11:05 May 1, 14 Fri, May 15, 2015
Rebecca Cline Eget Dictum Placerat Limited 02:12 Dec 20, 13 Wed, August 6, 2014
India Lawson Eget Company 11:03 Mar 21, 15 Fri, July 11, 2014
Elvis Whitfield Mollis Corporation 08:07 Jul 30, 15 Sat, February 28, 2015
Castor Monroe Iaculis LLC 12:06 Jun 22, 14 Mon, June 2, 2014
Gareth Berry Malesuada Corp. 04:02 Feb 26, 14 Fri, February 27, 2015
Anne Knox Neque Sed Consulting 04:04 Apr 11, 14 Sat, May 24, 2014
Kasimir Martin Tortor Nunc Consulting 11:12 Dec 24, 14 Sat, July 25, 2015
Drake Pugh Mattis Velit Industries 03:09 Sep 23, 15 Wed, March 5, 2014
Carla Head Pretium Aliquet Institute 06:09 Sep 2, 15 Wed, January 8, 2014
Shellie Henry Scelerisque Ltd 11:01 Jan 28, 15 Sun, February 1, 2015
Patrick Koch Scelerisque Dui LLC 10:10 Oct 3, 14 Sun, May 17, 2015
Dara Roberts Urna Convallis Erat Industries 11:08 Aug 13, 15 Sun, June 22, 2014
Yuli Wright Auctor Consulting 05:07 Jul 22, 14 Tue, March 25, 2014
Cyrus Jensen Et Risus Associates 10:09 Sep 19, 15 Sat, May 16, 2015
Holmes Talley Urna Nullam Lobortis Consulting 01:12 Dec 25, 14 Thu, February 13, 2014
Iris Carver Laoreet Lectus Quis LLC 12:10 Oct 13, 14 Fri, November 7, 2014
Leroy Cantrell In LLC 03:05 May 5, 15 Tue, June 2, 2015
Maggie Aguilar Mauris PC 02:12 Dec 7, 14 Thu, November 20, 2014
Maggy Porter Mauris Blandit Ltd 11:06 Jun 4, 14 Tue, November 11, 2014
Liberty Warner Ipsum Company 05:11 Nov 17, 15 Mon, October 5, 2015
Raya Dean Felis Foundation 02:12 Dec 18, 14 Mon, February 10, 2014
Jack Juarez Nunc Limited 01:09 Sep 7, 15 Mon, December 22, 2014
Nola King Varius Orci Incorporated 04:05 May 12, 15 Tue, June 24, 2014
Carlos Holman Odio LLC 01:08 Aug 16, 15 Thu, August 20, 2015
Aquila Finch Egestas Ligula Nullam Institute 12:09 Sep 3, 15 Sat, March 22, 2014
Seth Porter Sem Ut Inc. 01:06 Jun 4, 15 Sun, March 1, 2015
Oleg Mcpherson Nunc Ac Sem LLP 03:08 Aug 3, 14 Sun, September 21, 2014
Kennan Snyder Amet Consectetuer Associates 06:01 Jan 23, 14 Mon, April 7, 2014
Emery Donovan Dapibus Inc. 08:06 Jun 14, 14 Tue, September 30, 2014
Naida Hunter Augue Scelerisque Mollis Inc. 11:12 Dec 23, 13 Sun, July 19, 2015
Clinton Morrison Non Lacinia Industries 02:03 Mar 18, 14 Fri, March 6, 2015
Helen Gutierrez Faucibus Incorporated 07:08 Aug 7, 15 Tue, February 4, 2014
Candice Bonner Donec LLP 05:12 Dec 28, 13 Mon, March 16, 2015
Nissim Carter Suspendisse Sed Limited 01:03 Mar 19, 14 Mon, June 29, 2015
Kasimir Hoffman Id Libero Donec Consulting 05:12 Dec 23, 14 Wed, September 23, 2015
Imogene Mcconnell Vitae Associates 07:02 Feb 17, 15 Tue, July 22, 2014
Sage Mosley Metus In Inc. 05:05 May 24, 15 Mon, April 21, 2014
Sybil Puckett Vel Lectus LLP 09:06 Jun 9, 14 Sat, September 6, 2014
Kylynn Solis Ac Limited 10:01 Jan 20, 15 Tue, September 15, 2015
Beatrice Hurley Mauris A Nunc Corporation 04:05 May 11, 14 Sun, April 26, 2015
Troy Marquez Dapibus Quam Institute 12:02 Feb 7, 15 Thu, April 23, 2015
Malcolm Payne Adipiscing Ligula Institute 04:08 Aug 17, 15 Tue, September 2, 2014
Wade Valenzuela Sagittis Duis Gravida Corporation 03:05 May 22, 14 Mon, January 13, 2014
Kathleen Gilmore Urna Nec Ltd 05:03 Mar 5, 14 Mon, November 16, 2015
Maite Scott Ipsum Cursus Inc. 01:05 May 28, 14 Sun, June 8, 2014
Kamal Nash Sem Vitae Company 05:10 Oct 7, 14 Thu, June 26, 2014
Iliana West Ac Eleifend Limited 01:10 Oct 24, 15 Wed, July 2, 2014
Susan Osborn Sollicitudin Adipiscing Ligula Institute 03:02 Feb 18, 14 Sat, June 13, 2015
Adena Carter Nibh Industries 04:01 Jan 27, 15 Tue, February 3, 2015
Duncan Mckinney Vel Convallis In Inc. 09:11 Nov 23, 15 Sat, December 12, 2015
Ariana Whitehead Fermentum Metus Associates 03:06 Jun 9, 14 Tue, December 15, 2015
Fiona Henderson Eget Tincidunt Dui Inc. 03:01 Jan 1, 14 Fri, January 9, 2015
Judah Gates Donec Felis Associates 04:11 Nov 30, 15 Mon, September 28, 2015
Hasad Mccarthy Ac Tellus Company 12:01 Jan 21, 14 Mon, January 27, 2014
Shay Valencia Natoque Associates 05:03 Mar 4, 14 Mon, December 15, 2014
Hillary Tran Integer Mollis Foundation 08:12 Dec 31, 14 Wed, August 26, 2015
Margaret Sellers Lacus Quisque Corporation 11:10 Oct 17, 15 Sun, July 5, 2015
Prescott Morton Vestibulum Associates 01:04 Apr 27, 15 Sun, June 14, 2015
Charity Gilbert Tortor At Risus Associates 01:07 Jul 31, 14 Thu, December 18, 2014
Freya Randolph Ut Institute 07:11 Nov 3, 15 Sat, September 27, 2014
Nita Howe Ornare Fusce Inc. 11:02 Feb 12, 14 Tue, June 9, 2015
Kirby Whitney Faucibus Morbi Vehicula Foundation 11:12 Dec 22, 13 Wed, August 26, 2015
Amos Jarvis Mauris Suspendisse Aliquet LLP 01:05 May 10, 15 Mon, July 14, 2014
Kim Hunter Ligula Donec Luctus Corp. 07:11 Nov 25, 15 Thu, October 23, 2014
Rosalyn Benton Iaculis Quis Pede Corp. 02:09 Sep 16, 14 Sun, November 15, 2015
Anjolie Floyd Nunc Corp. 12:03 Mar 28, 14 Mon, December 1, 2014
Basil Harmon Semper Rutrum Fusce PC 05:12 Dec 9, 15 Wed, September 17, 2014
Kermit Herrera Sed Tortor Integer Limited 03:09 Sep 26, 14 Sun, June 14, 2015
Winifred Pearson Augue Industries 10:09 Sep 18, 15 Tue, August 4, 2015
Lester Fischer Aenean PC 02:09 Sep 15, 15 Wed, July 29, 2015
Tatum Daugherty Nunc Nulla LLP 09:06 Jun 25, 15 Wed, February 19, 2014
Zachary Wilder Nec LLC 03:09 Sep 19, 14 Wed, April 8, 2015
Laith Peters Ipsum Leo Elementum Institute 11:06 Jun 17, 14 Thu, November 13, 2014
Evelyn Ramos Nunc Industries 01:06 Jun 3, 14 Thu, April 10, 2014
Mara Michael Ut Aliquam LLC 10:07 Jul 14, 14 Thu, November 26, 2015
Jemima Powers Eu Arcu Morbi LLP 06:08 Aug 4, 14 Fri, May 1, 2015
Tanek Guthrie Sit Associates 09:02 Feb 19, 15 Thu, May 28, 2015
Harriet Crane Quis Accumsan Ltd 12:08 Aug 2, 14 Sun, December 13, 2015
Jin Bond Auctor Quis Corp. 09:08 Aug 25, 15 Tue, November 18, 2014
Ursa Jacobs Convallis Ante PC 08:04 Apr 5, 14 Tue, February 18, 2014
Jason Collier Vel Pede Blandit Ltd 01:05 May 12, 14 Mon, September 21, 2015
Quemby Stone Lacus Quisque Incorporated 09:08 Aug 10, 15 Thu, July 2, 2015
Melvin Sweet Nec Foundation 05:01 Jan 17, 15 Thu, May 22, 2014
Thor Wilson Arcu Vivamus Sit Industries 02:02 Feb 17, 15 Thu, August 7, 2014
Burton Marquez Augue Corporation 09:12 Dec 2, 15 Wed, November 26, 2014
Kai Ware Facilisis Vitae Limited 12:06 Jun 23, 14 Sun, June 29, 2014
Holmes Murphy Dui Nec Tempus Inc. 12:10 Oct 25, 15 Sun, April 26, 2015
Blaine Valentine Proin Institute 04:10 Oct 16, 14 Mon, March 30, 2015
Lionel Pacheco Dolor Company 07:03 Mar 18, 14 Sat, May 24, 2014
Keefe Fletcher A Mi Fringilla Industries 03:09 Sep 25, 15 Thu, October 22, 2015
Slade Rojas Sodales Nisi Magna PC 08:09 Sep 1, 15 Wed, June 11, 2014
Vanna Kirkland Tempus Inc. 03:02 Feb 14, 15 Wed, December 9, 2015
Cameron Peters Lobortis Tellus Justo Limited 06:02 Feb 9, 15 Fri, January 2, 2015
Reed Freeman Augue Sed Molestie LLP 01:09 Sep 24, 15 Sun, July 19, 2015
Florence Burgess Aliquam Auctor Velit Incorporated 05:04 Apr 20, 14 Mon, September 8, 2014
  • Javascript
  • HTML
  • CSS
  • Ajax
  • Server-side script
  • Comments

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

/** * This plug-in for DataTables represents the ultimate option in extensibility * for sorting date / time strings correctly. It uses * [luxon](https://moment.github.io/luxon/) to create automatic type detection and * sorting plug-ins for DataTables based on a given format. This way, DataTables * will automatically detect your temporal information and sort it correctly. * * For usage instructions, please see the DataTables blog * post that [introduces it](//datatables.net/blog/2014-12-18). * * @name Ultimate Date / Time sorting * @summary Sort date and time in any format using luxon * @author [Allan Jardine](//datatables.net) * @depends DataTables 1.10+, luxon.js 1.0+ * * @example * $.fn.dataTable.luxon( 'HH:mm MMM d, yy' ); * $.fn.dataTable.luxon( 'EEE, MMMM Do, yyyy' ); * * $('#example').DataTable(); */ (function (factory) { if (typeof define === "function" && define.amd) { define(["jquery", "luxon", "datatables.net"], factory); } else { factory(jQuery, luxon); } }(function ($, luxon) { function strip (d) { if ( typeof d === 'string' ) { // Strip HTML tags and newline characters if possible d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); // Strip out surrounding white space d = d.trim(); } return d; } $.fn.dataTable.luxon = function ( format, locale, reverseEmpties ) { var types = $.fn.dataTable.ext.type; // Add type detection types.detect.unshift( function ( d ) { d = strip(d); // Null and empty values are acceptable if ( d === '' || d === null ) { return 'luxon-'+format; } if(!luxon.DateTime.fromFormat( d, format).isValid) { console.log("pause") } return luxon.DateTime.fromFormat( d, format).isValid ? 'luxon-'+format : null; } ); // Add sorting method - use an integer for the sorting types.order[ 'luxon-'+format+'-pre' ] = function ( d ) { d = strip(d); return !luxon.DateTime.fromFormat(d, format).isValid ? (reverseEmpties ? -Infinity : Infinity) : parseInt( luxon.DateTime.fromFormat( d, format).ts, 10 ); }; }; })); $(document).ready(function() { $.fn.dataTable.luxon( 'EEE, MMMM d, yyyy' ); $.fn.dataTable.luxon( 'HH:mm MMM d, yy' ); $('#example').DataTable( { dom: 'Qlfrtip' }); });

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.

Other examples