JSFiddle - React, Tailwind, and code Playground
JavaScript
/**
* When sorting a DataTable you might find that you want to keep a specific
* item at the top or bottom of the table. For example when sorting a column
* of numbers, if a value is `null` or `N/A` you might want to keep it at the
* bottom of the table, regardless of if ascending or descending sorting is
* applied. This plug-in provides that ability.
*
* You must call the `$.fn.dataTable.absoluteOrder` with information about the
* value(s) you wish to make absolute in the sorting order and store the
* returned value, assigning it to the `columns.type` option for the column
* you wish this sorting to be applied to.
*
* For number based columns a `$.fn.dataTable.absoluteOrderNumber` function is
* also available.
*
* @name Absolute sorting
* @summary Keep one or more items at the top and/or bottom of a table when sorting
* @author [Allan Jardine](//datatables.net)
* @depends DataTables 1.10+
*
* @example
* var namesType = $.fn.dataTable.absoluteOrder( [
* { value: '', position: 'top' }
* ] );
*
* var numbersType = $.fn.dataTable.absoluteOrderNumber( [
* { value: 'N/A', position: 'bottom' }
* ] );
*
* $('#example').DataTable( {
* columnDefs: [
* { type: namesType, targets: 0 },
* { type: numbersType, targets: 1 }
* ]
* } );
*/
(function( factory ){
if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['jquery', 'datatables.net'], function ( $ ) {
return factory( $, window, document );
} );
}
else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = function (root, $) {
if ( ! root ) {
root = window;
}
if ( ! $ || ! $.fn.dataTable ) {
$ = require('datatables.net')(root, $).$;
}
return factory( $, root, root.document );
};
}
else {
// Browser
factory( jQuery, window, document );
}
}(function( $, window, document, undefined ) {
'use strict';
// Unique value allowing multiple absolute ordering use...