From b97abea68839019e3dd55e4d6a6b64dbfce68727 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Thu, 5 Mar 2015 09:50:32 +0000 Subject: [PATCH] New - API: `order.neutral()` method to use the data load order as the display order This is an update for the old `fnSortNeutral` method for the new API --- api/order.neutral().js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 api/order.neutral().js diff --git a/api/order.neutral().js b/api/order.neutral().js new file mode 100644 index 0000000..9c95288 --- /dev/null +++ b/api/order.neutral().js @@ -0,0 +1,26 @@ +/** + * This function will restore the order in which data was read into a DataTable + * (for example from an HTML source). Although you can set `dt-api order()` to + * be an empty array (`[]`) in order to prevent sorting during initialisation, + * it can sometimes be useful to restore the original order after sorting has + * already occurred - which is exactly what this function does. + * + * @name order.neutral() + * @summary Change ordering of the table to its data load order + * @author [Allan Jardine](http://datatables.net) + * @requires DataTables 1.10+ + * + * @returns {DataTables.Api} DataTables API instance + * + * @example + * // Return table to the loaded data order + * table.order.neutral().draw(); + */ + +$.fn.dataTable.Api.register( 'order.neutral()', function () { + return this.iterator( 'table', function ( s ) { + s.aaSorting.length = 0; + s.aiDisplay.sort(); + s.aiDisplayMaster.sort(); + } ); +} );