Complete transition to typescript and ESmodule + UMD loader for everything that will be included with the exception of i18n (upcoming)
parent
4fff59b4ae
commit
87bb97dbb4
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
@ -0,0 +1,8 @@
|
|||||||
|
/*! © SpryMedia Ltd, Alireza Mohammadi Doost - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStaticRender {
|
||||||
|
/** Convert numbers to Farsi, English or Arabic. */
|
||||||
|
numberTo(string: 'fa' | 'en' | 'ar'): any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -0,0 +1,25 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Show an set of alphabet buttons alongside a table providing search input options */
|
||||||
|
AlphabetSearch(settings: any): void;
|
||||||
|
}
|
||||||
|
interface Config {
|
||||||
|
alphabet?: {
|
||||||
|
column: number;
|
||||||
|
caseSensitive: boolean;
|
||||||
|
numbers: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
interface Api<T> {
|
||||||
|
alphabetSearch: ApiAlphabet<T>;
|
||||||
|
}
|
||||||
|
interface ApiAlphabet<T> {
|
||||||
|
(searchTerm: string): ApiAlphabetMethods<T>;
|
||||||
|
}
|
||||||
|
interface ApiAlphabetMethods<T> extends Api<T> {
|
||||||
|
node(): JQuery | null;
|
||||||
|
recalc(): Api<T>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,213 +1,212 @@
|
|||||||
/*! AlphabetSearch for DataTables v1.0.0
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2014 SpryMedia Ltd - datatables.net/license
|
|
||||||
*/
|
(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 ) {
|
||||||
|
// CommonJS environments without a window global must pass a
|
||||||
|
// root. This will give an error otherwise
|
||||||
|
root = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $ ) {
|
||||||
|
$ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
|
||||||
|
require('jquery') :
|
||||||
|
require('jquery')( root );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $.fn.dataTable ) {
|
||||||
|
require('datatables.net')(root, $);
|
||||||
|
}
|
||||||
|
|
||||||
|
return factory( $, root, root.document );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Browser
|
||||||
|
factory( jQuery, window, document );
|
||||||
|
}
|
||||||
|
}(function( $, window, document, undefined ) {
|
||||||
|
'use strict';
|
||||||
|
var DataTable = $.fn.dataTable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary AlphabetSearch
|
* @summary AlphabetSearch
|
||||||
* @description Show an set of alphabet buttons alongside a table providing
|
* @description Show an set of alphabet buttons alongside a table providing
|
||||||
* search input options
|
* search input options
|
||||||
* @version 1.0.0
|
* @version 1.1.0
|
||||||
* @file dataTables.alphabetSearch.js
|
* @file dataTables.alphabetSearch.js
|
||||||
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
* @contact www.sprymedia.co.uk/contact
|
* @contact www.sprymedia.co.uk/contact
|
||||||
* @copyright Copyright 2014 SpryMedia Ltd.
|
* @copyright Copyright SpryMedia Ltd.
|
||||||
*
|
*
|
||||||
* License MIT - http://datatables.net/license/mit
|
* License MIT - http://datatables.net/license/mit
|
||||||
*
|
*
|
||||||
* For more detailed information please see:
|
* For more detailed information please see:
|
||||||
* http://datatables.net/blog/2014-09-22
|
* http://datatables.net/blog/2014-09-22
|
||||||
*/
|
*/
|
||||||
(function(){
|
|
||||||
|
|
||||||
|
|
||||||
// Search function
|
// Search function
|
||||||
$.fn.dataTable.Api.register( 'alphabetSearch()', function ( searchTerm ) {
|
DataTable.Api.register('alphabetSearch()', function (searchTerm) {
|
||||||
this.iterator( 'table', function ( context ) {
|
this.iterator('table', function (context) {
|
||||||
context.alphabetSearch = searchTerm;
|
context.alphabetSearch = searchTerm;
|
||||||
} );
|
});
|
||||||
|
return this;
|
||||||
return this;
|
});
|
||||||
} );
|
|
||||||
|
|
||||||
// Recalculate the alphabet display for updated data
|
// Recalculate the alphabet display for updated data
|
||||||
$.fn.dataTable.Api.register( 'alphabetSearch.recalc()', function ( searchTerm ) {
|
DataTable.Api.register('alphabetSearch.recalc()', function () {
|
||||||
this.iterator( 'table', function ( context ) {
|
this.iterator('table', function (context) {
|
||||||
draw(
|
draw(new DataTable.Api(context), context._alphabet, context._alphabetOptions);
|
||||||
new $.fn.dataTable.Api( context ),
|
});
|
||||||
$('div.alphabet', this.table().container())
|
return this;
|
||||||
);
|
});
|
||||||
} );
|
DataTable.Api.register('alphabetSearch.node()', function () {
|
||||||
|
return this._context.length
|
||||||
return this;
|
? this._context._alphabet
|
||||||
} );
|
: null;
|
||||||
|
;
|
||||||
|
});
|
||||||
// Search plug-in
|
// Search plug-in
|
||||||
$.fn.dataTable.ext.search.push( function ( context, searchData ) {
|
DataTable.ext.search.push(function (context, searchData) {
|
||||||
// Ensure that there is a search applied to this table before running it
|
// Ensure that there is a search applied to this table before running it
|
||||||
if ( ! context.alphabetSearch ) {
|
if (!context.alphabetSearch) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
var columnId = 0;
|
||||||
if (context.oInit.alphabet !== undefined) {
|
var caseSensitive = false;
|
||||||
var columnId = (context.oInit.alphabet.column !== undefined) ? context.oInit.alphabet.column : 0
|
if (context.oInit.alphabet !== undefined) {
|
||||||
var caseSensitive = (context.oInit.alphabet.caseSensitive !== undefined) ? context.oInit.alphabet.caseSensitive : false
|
columnId =
|
||||||
} else {
|
context.oInit.alphabet.column !== undefined
|
||||||
var columnId = 0
|
? context.oInit.alphabet.column
|
||||||
var caseSensitive = false
|
: 0;
|
||||||
}
|
caseSensitive =
|
||||||
|
context.oInit.alphabet.caseSensitive !== undefined
|
||||||
if (caseSensitive) {
|
? context.oInit.alphabet.caseSensitive
|
||||||
if ( searchData[columnId].charAt(0) === context.alphabetSearch ) {
|
: false;
|
||||||
return true;
|
}
|
||||||
}
|
if (caseSensitive) {
|
||||||
} else {
|
if (searchData[columnId].charAt(0) === context.alphabetSearch) {
|
||||||
if ( searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch ) {
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
if (searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch) {
|
||||||
return false;
|
return true;
|
||||||
} );
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
// Private support methods
|
// Private support methods
|
||||||
function bin ( data, options ) {
|
function bin(data, options) {
|
||||||
var letter, bins = {};
|
var letter, bins = {};
|
||||||
|
for (var i = 0, ien = data.length; i < ien; i++) {
|
||||||
for ( var i=0, ien=data.length ; i<ien ; i++ ) {
|
if (options.caseSensitive) {
|
||||||
if (options.caseSensitive) {
|
letter = data[i].toString().replace(/<.*?>/g, '').charAt(0);
|
||||||
letter = data[i]
|
}
|
||||||
.toString()
|
else {
|
||||||
.replace(/<.*?>/g, '')
|
letter = data[i].toString().replace(/<.*?>/g, '').charAt(0).toUpperCase();
|
||||||
.charAt(0);
|
}
|
||||||
} else {
|
if (bins[letter]) {
|
||||||
letter = data[i]
|
bins[letter]++;
|
||||||
.toString()
|
}
|
||||||
.replace(/<.*?>/g, '')
|
else {
|
||||||
.charAt(0).toUpperCase();
|
bins[letter] = 1;
|
||||||
}
|
}
|
||||||
if ( bins[letter] ) {
|
}
|
||||||
bins[letter]++;
|
return bins;
|
||||||
}
|
|
||||||
else {
|
|
||||||
bins[letter] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bins;
|
|
||||||
}
|
}
|
||||||
|
function draw(table, alphabet, options) {
|
||||||
function draw ( table, alphabet, options )
|
alphabet.empty();
|
||||||
{
|
alphabet.append('Search: ');
|
||||||
alphabet.empty();
|
var columnData = table.column(options.column).data();
|
||||||
alphabet.append( 'Search: ' );
|
var bins = bin(columnData, options);
|
||||||
|
$('<span class="clear active"/>')
|
||||||
var columnData = table.column(options.column).data();
|
.data('letter', '')
|
||||||
var bins = bin( columnData, options );
|
.data('match-count', columnData.length)
|
||||||
|
.html('None')
|
||||||
$('<span class="clear active"/>')
|
.appendTo(alphabet);
|
||||||
.data( 'letter', '' )
|
if (options.numbers) {
|
||||||
.data( 'match-count', columnData.length )
|
for (var i = 0; i < 10; i++) {
|
||||||
.html( 'None' )
|
var letter = String.fromCharCode(48 + i);
|
||||||
.appendTo( alphabet );
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
if (options.numbers) {
|
.data('match-count', bins[letter] || 0)
|
||||||
for (var i = 0; i < 10; i++) {
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
var letter = String.fromCharCode(48 + i);
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
$('<span/>')
|
}
|
||||||
.data('letter', letter)
|
}
|
||||||
.data('match-count', bins[letter] || 0)
|
for (var i = 0; i < 26; i++) {
|
||||||
.addClass(!bins[letter] ? 'empty' : '')
|
var letter = String.fromCharCode(65 + i);
|
||||||
.html(letter)
|
$('<span/>')
|
||||||
.appendTo(alphabet);
|
.data('letter', letter)
|
||||||
}
|
.data('match-count', bins[letter] || 0)
|
||||||
}
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
for ( var i=0 ; i<26 ; i++ ) {
|
.html(letter)
|
||||||
var letter = String.fromCharCode( 65 + i );
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
$('<span/>')
|
if (options.caseSensitive) {
|
||||||
.data( 'letter', letter )
|
for (var i = 0; i < 26; i++) {
|
||||||
.data( 'match-count', bins[letter] || 0 )
|
var letter = String.fromCharCode(97 + i);
|
||||||
.addClass( ! bins[letter] ? 'empty' : '' )
|
$('<span/>')
|
||||||
.html( letter )
|
.data('letter', letter)
|
||||||
.appendTo( alphabet );
|
.data('match-count', bins[letter] || 0)
|
||||||
}
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
if (options.caseSensitive) {
|
.html(letter)
|
||||||
for (var i = 0; i < 26; i++) {
|
.appendTo(alphabet);
|
||||||
var letter = String.fromCharCode(97 + i);
|
}
|
||||||
|
}
|
||||||
$('<span/>')
|
$('<div class="alphabetInfo"></div>').appendTo(alphabet);
|
||||||
.data('letter', letter)
|
|
||||||
.data('match-count', bins[letter] || 0)
|
|
||||||
.addClass(!bins[letter] ? 'empty' : '')
|
|
||||||
.html(letter)
|
|
||||||
.appendTo(alphabet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$('<div class="alphabetInfo"></div>')
|
|
||||||
.appendTo( alphabet );
|
|
||||||
}
|
}
|
||||||
|
DataTable.AlphabetSearch = function (context) {
|
||||||
|
var table = new DataTable.Api(context);
|
||||||
$.fn.dataTable.AlphabetSearch = function ( context ) {
|
var alphabet = $('<div class="alphabet"/>');
|
||||||
var table = new $.fn.dataTable.Api( context );
|
var options = $.extend({
|
||||||
var alphabet = $('<div class="alphabet"/>');
|
column: 0,
|
||||||
var options = $.extend({
|
caseSensitive: false,
|
||||||
column: 0,
|
numbers: false,
|
||||||
caseSensitive: false,
|
}, table.init().alphabet);
|
||||||
numbers: false
|
draw(table, alphabet, options);
|
||||||
}, table.init().alphabet);
|
context._alphabet = alphabet;
|
||||||
|
context._alphabetOptions = options;
|
||||||
draw( table, alphabet, options );
|
// Trigger a search
|
||||||
|
alphabet.on('click', 'span', function () {
|
||||||
// Trigger a search
|
alphabet.find('.active').removeClass('active');
|
||||||
alphabet.on( 'click', 'span', function () {
|
$(this).addClass('active');
|
||||||
alphabet.find( '.active' ).removeClass( 'active' );
|
table.alphabetSearch($(this).data('letter')).draw();
|
||||||
$(this).addClass( 'active' );
|
});
|
||||||
|
// Mouse events to show helper information
|
||||||
table
|
alphabet
|
||||||
.alphabetSearch( $(this).data('letter') )
|
.on('mouseenter', 'span', function () {
|
||||||
.draw();
|
alphabet
|
||||||
} );
|
.find('div.alphabetInfo')
|
||||||
|
.css({
|
||||||
// Mouse events to show helper information
|
opacity: 1,
|
||||||
alphabet
|
left: $(this).position().left,
|
||||||
.on( 'mouseenter', 'span', function () {
|
width: $(this).width(),
|
||||||
alphabet
|
}) // unsure why it needs any
|
||||||
.find('div.alphabetInfo')
|
.html($(this).data('match-count'));
|
||||||
.css( {
|
})
|
||||||
opacity: 1,
|
.on('mouseleave', 'span', function () {
|
||||||
left: $(this).position().left,
|
alphabet.find('div.alphabetInfo').css('opacity', 0);
|
||||||
width: $(this).width()
|
});
|
||||||
} )
|
|
||||||
.html( $(this).data('match-count') );
|
|
||||||
} )
|
|
||||||
.on( 'mouseleave', 'span', function () {
|
|
||||||
alphabet
|
|
||||||
.find('div.alphabetInfo')
|
|
||||||
.css('opacity', 0);
|
|
||||||
} );
|
|
||||||
|
|
||||||
// API method to get the alphabet container node
|
|
||||||
this.node = function () {
|
|
||||||
return alphabet;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn.DataTable.AlphabetSearch = $.fn.dataTable.AlphabetSearch;
|
|
||||||
|
|
||||||
// Register a search plug-in
|
// Register a search plug-in
|
||||||
$.fn.dataTable.ext.feature.push( {
|
DataTable.ext.feature.push({
|
||||||
fnInit: function ( settings ) {
|
fnInit: function (settings) {
|
||||||
var search = new $.fn.dataTable.AlphabetSearch( settings );
|
var search = new DataTable.AlphabetSearch(settings);
|
||||||
return search.node();
|
return search.node();
|
||||||
},
|
},
|
||||||
cFeature: 'A'
|
cFeature: 'A',
|
||||||
} );
|
});
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
||||||
|
|
||||||
|
return DataTable;
|
||||||
|
}));
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
/*! AlphabetSearch for DataTables v1.0.0
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2014 SpryMedia Ltd - datatables.net/license
|
!function(a){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return a(t,window,document)}):"object"==typeof exports?module.exports=function(t,e){return t=t||window,(e=e||("undefined"!=typeof window?require("jquery"):require("jquery")(t))).fn.dataTable||require("datatables.net")(t,e),a(e,0,t.document)}:a(jQuery,window,document)}(function(o,t,e,r){"use strict";var i=o.fn.dataTable;function c(t,e,a){e.empty(),e.append("Search: ");var t=t.column(a.column).data(),n=function(t,e){for(var a,n={},r=0,i=t.length;r<i;r++)n[a=e.caseSensitive?t[r].toString().replace(/<.*?>/g,"").charAt(0):t[r].toString().replace(/<.*?>/g,"").charAt(0).toUpperCase()]?n[a]++:n[a]=1;return n}(t,a);if(o('<span class="clear active"/>').data("letter","").data("match-count",t.length).html("None").appendTo(e),a.numbers)for(var r=0;r<10;r++){var i=String.fromCharCode(48+r);o("<span/>").data("letter",i).data("match-count",n[i]||0).addClass(n[i]?"":"empty").html(i).appendTo(e)}for(r=0;r<26;r++){i=String.fromCharCode(65+r);o("<span/>").data("letter",i).data("match-count",n[i]||0).addClass(n[i]?"":"empty").html(i).appendTo(e)}if(a.caseSensitive)for(r=0;r<26;r++){i=String.fromCharCode(97+r);o("<span/>").data("letter",i).data("match-count",n[i]||0).addClass(n[i]?"":"empty").html(i).appendTo(e)}o('<div class="alphabetInfo"></div>').appendTo(e)}return i.Api.register("alphabetSearch()",function(e){return this.iterator("table",function(t){t.alphabetSearch=e}),this}),i.Api.register("alphabetSearch.recalc()",function(){return this.iterator("table",function(t){c(new i.Api(t),t._alphabet,t._alphabetOptions)}),this}),i.Api.register("alphabetSearch.node()",function(){return this._context.length?this._context._alphabet:null}),i.ext.search.push(function(t,e){if(!t.alphabetSearch)return!0;var a=0,n=!1;if(t.oInit.alphabet!==r&&(a=t.oInit.alphabet.column!==r?t.oInit.alphabet.column:0,n=t.oInit.alphabet.caseSensitive!==r&&t.oInit.alphabet.caseSensitive),n){if(e[a].charAt(0)===t.alphabetSearch)return!0}else if(e[a].charAt(0).toUpperCase()===t.alphabetSearch)return!0;return!1}),i.AlphabetSearch=function(t){var e=new i.Api(t),a=o('<div class="alphabet"/>'),n=o.extend({column:0,caseSensitive:!1,numbers:!1},e.init().alphabet);c(e,a,n),t._alphabet=a,t._alphabetOptions=n,a.on("click","span",function(){a.find(".active").removeClass("active"),o(this).addClass("active"),e.alphabetSearch(o(this).data("letter")).draw()}),a.on("mouseenter","span",function(){a.find("div.alphabetInfo").css({opacity:1,left:o(this).position().left,width:o(this).width()}).html(o(this).data("match-count"))}).on("mouseleave","span",function(){a.find("div.alphabetInfo").css("opacity",0)})},i.ext.feature.push({fnInit:function(t){return new i.AlphabetSearch(t).node()},cFeature:"A"}),i});
|
||||||
*/
|
|
||||||
!function(){function n(a,t,e){t.empty(),t.append("Search: ");var a=a.column(e.column).data(),n=function(a,t){for(var e,n={},i=0,r=a.length;i<r;i++)n[e=t.caseSensitive?a[i].toString().replace(/<.*?>/g,"").charAt(0):a[i].toString().replace(/<.*?>/g,"").charAt(0).toUpperCase()]?n[e]++:n[e]=1;return n}(a,e);if($('<span class="clear active"/>').data("letter","").data("match-count",a.length).html("None").appendTo(t),e.numbers)for(var i=0;i<10;i++){var r=String.fromCharCode(48+i);$("<span/>").data("letter",r).data("match-count",n[r]||0).addClass(n[r]?"":"empty").html(r).appendTo(t)}for(i=0;i<26;i++){r=String.fromCharCode(65+i);$("<span/>").data("letter",r).data("match-count",n[r]||0).addClass(n[r]?"":"empty").html(r).appendTo(t)}if(e.caseSensitive)for(i=0;i<26;i++){r=String.fromCharCode(97+i);$("<span/>").data("letter",r).data("match-count",n[r]||0).addClass(n[r]?"":"empty").html(r).appendTo(t)}$('<div class="alphabetInfo"></div>').appendTo(t)}$.fn.dataTable.Api.register("alphabetSearch()",function(t){return this.iterator("table",function(a){a.alphabetSearch=t}),this}),$.fn.dataTable.Api.register("alphabetSearch.recalc()",function(a){return this.iterator("table",function(a){n(new $.fn.dataTable.Api(a),$("div.alphabet",this.table().container()))}),this}),$.fn.dataTable.ext.search.push(function(a,t){if(!a.alphabetSearch)return!0;var e;if(void 0!==a.oInit.alphabet?(e=void 0!==a.oInit.alphabet.column?a.oInit.alphabet.column:0,void 0!==a.oInit.alphabet.caseSensitive&&a.oInit.alphabet.caseSensitive):(e=0,!1)){if(t[e].charAt(0)===a.alphabetSearch)return!0}else if(t[e].charAt(0).toUpperCase()===a.alphabetSearch)return!0;return!1}),$.fn.dataTable.AlphabetSearch=function(a){var t=new $.fn.dataTable.Api(a),e=$('<div class="alphabet"/>'),a=$.extend({column:0,caseSensitive:!1,numbers:!1},t.init().alphabet);n(t,e,a),e.on("click","span",function(){e.find(".active").removeClass("active"),$(this).addClass("active"),t.alphabetSearch($(this).data("letter")).draw()}),e.on("mouseenter","span",function(){e.find("div.alphabetInfo").css({opacity:1,left:$(this).position().left,width:$(this).width()}).html($(this).data("match-count"))}).on("mouseleave","span",function(){e.find("div.alphabetInfo").css("opacity",0)}),this.node=function(){return e}},$.fn.DataTable.AlphabetSearch=$.fn.dataTable.AlphabetSearch,$.fn.dataTable.ext.feature.push({fnInit:function(a){return new $.fn.dataTable.AlphabetSearch(a).node()},cFeature:"A"})}();
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";function bin(a,t){for(var e,n={},r=0,i=a.length;r<i;r++)n[e=t.caseSensitive?a[r].toString().replace(/<.*?>/g,"").charAt(0):a[r].toString().replace(/<.*?>/g,"").charAt(0).toUpperCase()]?n[e]++:n[e]=1;return n}function draw(a,t,e){t.empty(),t.append("Search: ");var a=a.column(e.column).data(),n=bin(a,e);if($('<span class="clear active"/>').data("letter","").data("match-count",a.length).html("None").appendTo(t),e.numbers)for(var r=0;r<10;r++){var i=String.fromCharCode(48+r);$("<span/>").data("letter",i).data("match-count",n[i]||0).addClass(n[i]?"":"empty").html(i).appendTo(t)}for(r=0;r<26;r++){i=String.fromCharCode(65+r);$("<span/>").data("letter",i).data("match-count",n[i]||0).addClass(n[i]?"":"empty").html(i).appendTo(t)}if(e.caseSensitive)for(r=0;r<26;r++){i=String.fromCharCode(97+r);$("<span/>").data("letter",i).data("match-count",n[i]||0).addClass(n[i]?"":"empty").html(i).appendTo(t)}$('<div class="alphabetInfo"></div>').appendTo(t)}DataTable.Api.register("alphabetSearch()",function(t){return this.iterator("table",function(a){a.alphabetSearch=t}),this}),DataTable.Api.register("alphabetSearch.recalc()",function(){return this.iterator("table",function(a){draw(new DataTable.Api(a),a._alphabet,a._alphabetOptions)}),this}),DataTable.Api.register("alphabetSearch.node()",function(){return this._context.length?this._context._alphabet:null}),DataTable.ext.search.push(function(a,t){if(!a.alphabetSearch)return!0;var e=0,n=!1;if(void 0!==a.oInit.alphabet&&(e=void 0!==a.oInit.alphabet.column?a.oInit.alphabet.column:0,n=void 0!==a.oInit.alphabet.caseSensitive&&a.oInit.alphabet.caseSensitive),n){if(t[e].charAt(0)===a.alphabetSearch)return!0}else if(t[e].charAt(0).toUpperCase()===a.alphabetSearch)return!0;return!1}),DataTable.AlphabetSearch=function(a){var t=new DataTable.Api(a),e=$('<div class="alphabet"/>'),n=$.extend({column:0,caseSensitive:!1,numbers:!1},t.init().alphabet);draw(t,e,n),a._alphabet=e,a._alphabetOptions=n,e.on("click","span",function(){e.find(".active").removeClass("active"),$(this).addClass("active"),t.alphabetSearch($(this).data("letter")).draw()}),e.on("mouseenter","span",function(){e.find("div.alphabetInfo").css({opacity:1,left:$(this).position().left,width:$(this).width()}).html($(this).data("match-count"))}).on("mouseleave","span",function(){e.find("div.alphabetInfo").css("opacity",0)})},DataTable.ext.feature.push({fnInit:function(a){return new DataTable.AlphabetSearch(a).node()},cFeature:"A"});export default DataTable;
|
@ -0,0 +1,177 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary AlphabetSearch
|
||||||
|
* @description Show an set of alphabet buttons alongside a table providing
|
||||||
|
* search input options
|
||||||
|
* @version 1.1.0
|
||||||
|
* @file dataTables.alphabetSearch.js
|
||||||
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
|
* @contact www.sprymedia.co.uk/contact
|
||||||
|
* @copyright Copyright SpryMedia Ltd.
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* For more detailed information please see:
|
||||||
|
* http://datatables.net/blog/2014-09-22
|
||||||
|
*/
|
||||||
|
// Search function
|
||||||
|
DataTable.Api.register('alphabetSearch()', function (searchTerm) {
|
||||||
|
this.iterator('table', function (context) {
|
||||||
|
context.alphabetSearch = searchTerm;
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
// Recalculate the alphabet display for updated data
|
||||||
|
DataTable.Api.register('alphabetSearch.recalc()', function () {
|
||||||
|
this.iterator('table', function (context) {
|
||||||
|
draw(new DataTable.Api(context), context._alphabet, context._alphabetOptions);
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
DataTable.Api.register('alphabetSearch.node()', function () {
|
||||||
|
return this._context.length
|
||||||
|
? this._context._alphabet
|
||||||
|
: null;
|
||||||
|
;
|
||||||
|
});
|
||||||
|
// Search plug-in
|
||||||
|
DataTable.ext.search.push(function (context, searchData) {
|
||||||
|
// Ensure that there is a search applied to this table before running it
|
||||||
|
if (!context.alphabetSearch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var columnId = 0;
|
||||||
|
var caseSensitive = false;
|
||||||
|
if (context.oInit.alphabet !== undefined) {
|
||||||
|
columnId =
|
||||||
|
context.oInit.alphabet.column !== undefined
|
||||||
|
? context.oInit.alphabet.column
|
||||||
|
: 0;
|
||||||
|
caseSensitive =
|
||||||
|
context.oInit.alphabet.caseSensitive !== undefined
|
||||||
|
? context.oInit.alphabet.caseSensitive
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
if (caseSensitive) {
|
||||||
|
if (searchData[columnId].charAt(0) === context.alphabetSearch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
// Private support methods
|
||||||
|
function bin(data, options) {
|
||||||
|
var letter, bins = {};
|
||||||
|
for (var i = 0, ien = data.length; i < ien; i++) {
|
||||||
|
if (options.caseSensitive) {
|
||||||
|
letter = data[i].toString().replace(/<.*?>/g, '').charAt(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
letter = data[i].toString().replace(/<.*?>/g, '').charAt(0).toUpperCase();
|
||||||
|
}
|
||||||
|
if (bins[letter]) {
|
||||||
|
bins[letter]++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bins[letter] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bins;
|
||||||
|
}
|
||||||
|
function draw(table, alphabet, options) {
|
||||||
|
alphabet.empty();
|
||||||
|
alphabet.append('Search: ');
|
||||||
|
var columnData = table.column(options.column).data();
|
||||||
|
var bins = bin(columnData, options);
|
||||||
|
$('<span class="clear active"/>')
|
||||||
|
.data('letter', '')
|
||||||
|
.data('match-count', columnData.length)
|
||||||
|
.html('None')
|
||||||
|
.appendTo(alphabet);
|
||||||
|
if (options.numbers) {
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
var letter = String.fromCharCode(48 + i);
|
||||||
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
|
.data('match-count', bins[letter] || 0)
|
||||||
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 26; i++) {
|
||||||
|
var letter = String.fromCharCode(65 + i);
|
||||||
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
|
.data('match-count', bins[letter] || 0)
|
||||||
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
|
if (options.caseSensitive) {
|
||||||
|
for (var i = 0; i < 26; i++) {
|
||||||
|
var letter = String.fromCharCode(97 + i);
|
||||||
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
|
.data('match-count', bins[letter] || 0)
|
||||||
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$('<div class="alphabetInfo"></div>').appendTo(alphabet);
|
||||||
|
}
|
||||||
|
DataTable.AlphabetSearch = function (context) {
|
||||||
|
var table = new DataTable.Api(context);
|
||||||
|
var alphabet = $('<div class="alphabet"/>');
|
||||||
|
var options = $.extend({
|
||||||
|
column: 0,
|
||||||
|
caseSensitive: false,
|
||||||
|
numbers: false,
|
||||||
|
}, table.init().alphabet);
|
||||||
|
draw(table, alphabet, options);
|
||||||
|
context._alphabet = alphabet;
|
||||||
|
context._alphabetOptions = options;
|
||||||
|
// Trigger a search
|
||||||
|
alphabet.on('click', 'span', function () {
|
||||||
|
alphabet.find('.active').removeClass('active');
|
||||||
|
$(this).addClass('active');
|
||||||
|
table.alphabetSearch($(this).data('letter')).draw();
|
||||||
|
});
|
||||||
|
// Mouse events to show helper information
|
||||||
|
alphabet
|
||||||
|
.on('mouseenter', 'span', function () {
|
||||||
|
alphabet
|
||||||
|
.find('div.alphabetInfo')
|
||||||
|
.css({
|
||||||
|
opacity: 1,
|
||||||
|
left: $(this).position().left,
|
||||||
|
width: $(this).width(),
|
||||||
|
}) // unsure why it needs any
|
||||||
|
.html($(this).data('match-count'));
|
||||||
|
})
|
||||||
|
.on('mouseleave', 'span', function () {
|
||||||
|
alphabet.find('div.alphabetInfo').css('opacity', 0);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
// Register a search plug-in
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var search = new DataTable.AlphabetSearch(settings);
|
||||||
|
return search.node();
|
||||||
|
},
|
||||||
|
cFeature: 'A',
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,238 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary AlphabetSearch
|
||||||
|
* @description Show an set of alphabet buttons alongside a table providing
|
||||||
|
* search input options
|
||||||
|
* @version 1.1.0
|
||||||
|
* @file dataTables.alphabetSearch.js
|
||||||
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
|
* @contact www.sprymedia.co.uk/contact
|
||||||
|
* @copyright Copyright SpryMedia Ltd.
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* For more detailed information please see:
|
||||||
|
* http://datatables.net/blog/2014-09-22
|
||||||
|
*/
|
||||||
|
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Show an set of alphabet buttons alongside a table providing search input options */
|
||||||
|
AlphabetSearch(settings: any): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
alphabet?: {
|
||||||
|
column: number;
|
||||||
|
caseSensitive: boolean;
|
||||||
|
numbers: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Api<T> {
|
||||||
|
alphabetSearch: ApiAlphabet<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiAlphabet<T> {
|
||||||
|
(searchTerm: string): ApiAlphabetMethods<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiAlphabetMethods<T> extends Api<T> {
|
||||||
|
node(): JQuery | null;
|
||||||
|
|
||||||
|
recalc(): Api<T>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search function
|
||||||
|
DataTable.Api.register('alphabetSearch()', function (searchTerm) {
|
||||||
|
this.iterator('table', function (context) {
|
||||||
|
context.alphabetSearch = searchTerm;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Recalculate the alphabet display for updated data
|
||||||
|
DataTable.Api.register('alphabetSearch.recalc()', function () {
|
||||||
|
this.iterator('table', function (context) {
|
||||||
|
draw(
|
||||||
|
new DataTable.Api(context),
|
||||||
|
context._alphabet,
|
||||||
|
context._alphabetOptions
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
|
||||||
|
DataTable.Api.register('alphabetSearch.node()', function () {
|
||||||
|
return this._context.length
|
||||||
|
? this._context._alphabet
|
||||||
|
: null;;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Search plug-in
|
||||||
|
DataTable.ext.search.push(function (context, searchData) {
|
||||||
|
// Ensure that there is a search applied to this table before running it
|
||||||
|
if (!context.alphabetSearch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var columnId = 0;
|
||||||
|
var caseSensitive = false;
|
||||||
|
|
||||||
|
if (context.oInit.alphabet !== undefined) {
|
||||||
|
columnId =
|
||||||
|
context.oInit.alphabet.column !== undefined
|
||||||
|
? context.oInit.alphabet.column
|
||||||
|
: 0;
|
||||||
|
caseSensitive =
|
||||||
|
context.oInit.alphabet.caseSensitive !== undefined
|
||||||
|
? context.oInit.alphabet.caseSensitive
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caseSensitive) {
|
||||||
|
if (searchData[columnId].charAt(0) === context.alphabetSearch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (
|
||||||
|
searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Private support methods
|
||||||
|
function bin(data, options) {
|
||||||
|
var letter,
|
||||||
|
bins = {};
|
||||||
|
|
||||||
|
for (var i = 0, ien = data.length; i < ien; i++) {
|
||||||
|
if (options.caseSensitive) {
|
||||||
|
letter = data[i].toString().replace(/<.*?>/g, '').charAt(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
letter = data[i].toString().replace(/<.*?>/g, '').charAt(0).toUpperCase();
|
||||||
|
}
|
||||||
|
if (bins[letter]) {
|
||||||
|
bins[letter]++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bins[letter] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bins;
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw(table, alphabet, options) {
|
||||||
|
alphabet.empty();
|
||||||
|
alphabet.append('Search: ');
|
||||||
|
|
||||||
|
var columnData = table.column(options.column).data();
|
||||||
|
var bins = bin(columnData, options);
|
||||||
|
|
||||||
|
$('<span class="clear active"/>')
|
||||||
|
.data('letter', '')
|
||||||
|
.data('match-count', columnData.length)
|
||||||
|
.html('None')
|
||||||
|
.appendTo(alphabet);
|
||||||
|
|
||||||
|
if (options.numbers) {
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
var letter = String.fromCharCode(48 + i);
|
||||||
|
|
||||||
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
|
.data('match-count', bins[letter] || 0)
|
||||||
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 26; i++) {
|
||||||
|
var letter = String.fromCharCode(65 + i);
|
||||||
|
|
||||||
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
|
.data('match-count', bins[letter] || 0)
|
||||||
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
|
if (options.caseSensitive) {
|
||||||
|
for (var i = 0; i < 26; i++) {
|
||||||
|
var letter = String.fromCharCode(97 + i);
|
||||||
|
|
||||||
|
$('<span/>')
|
||||||
|
.data('letter', letter)
|
||||||
|
.data('match-count', bins[letter] || 0)
|
||||||
|
.addClass(!bins[letter] ? 'empty' : '')
|
||||||
|
.html(letter)
|
||||||
|
.appendTo(alphabet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('<div class="alphabetInfo"></div>').appendTo(alphabet);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.AlphabetSearch = function (context) {
|
||||||
|
var table = new DataTable.Api(context);
|
||||||
|
var alphabet = $('<div class="alphabet"/>');
|
||||||
|
var options = $.extend(
|
||||||
|
{
|
||||||
|
column: 0,
|
||||||
|
caseSensitive: false,
|
||||||
|
numbers: false,
|
||||||
|
},
|
||||||
|
table.init().alphabet
|
||||||
|
);
|
||||||
|
|
||||||
|
draw(table, alphabet, options);
|
||||||
|
|
||||||
|
context._alphabet = alphabet;
|
||||||
|
context._alphabetOptions = options;
|
||||||
|
|
||||||
|
// Trigger a search
|
||||||
|
alphabet.on('click', 'span', function () {
|
||||||
|
alphabet.find('.active').removeClass('active');
|
||||||
|
$(this).addClass('active');
|
||||||
|
|
||||||
|
table.alphabetSearch($(this).data('letter')).draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mouse events to show helper information
|
||||||
|
alphabet
|
||||||
|
.on('mouseenter', 'span', function () {
|
||||||
|
alphabet
|
||||||
|
.find('div.alphabetInfo')
|
||||||
|
.css({
|
||||||
|
opacity: 1,
|
||||||
|
left: $(this).position().left,
|
||||||
|
width: $(this).width(),
|
||||||
|
} as any) // unsure why it needs any
|
||||||
|
.html($(this).data('match-count'));
|
||||||
|
})
|
||||||
|
.on('mouseleave', 'span', function () {
|
||||||
|
alphabet.find('div.alphabetInfo').css('opacity', 0);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register a search plug-in
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var search = new DataTable.AlphabetSearch(settings);
|
||||||
|
return search.node();
|
||||||
|
},
|
||||||
|
cFeature: 'A',
|
||||||
|
});
|
@ -0,0 +1,7 @@
|
|||||||
|
/*! © SpryMedia Ltd, Garrett Hyder - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
conditionalPageLength: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd, Garrett Hyder - datatables.net/license */
|
||||||
|
!function(n){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return n(e,window,document)}):"object"==typeof exports?module.exports=function(e,t){return e=e||window,(t=t||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,t),n(t,0,e.document)}:n(jQuery,window,document)}(function(r,e,t,i){"use strict";var u=r.fn.dataTable;return r(t).on("init.dt",function(e,t){var a,o,d,s,n;"dt"===e.namespace&&(e=t.oInit.conditionalPageLength||u.defaults.conditionalPageLength,n=t.aLengthMenu||u.defaults.lengthMenu,n=(n=Array.isArray(n[0])?n[0]:n).filter(function(e){return 0<e}),a=Math.min.apply(Math,n),r.isPlainObject(e)||!0===e)&&(o=r.isPlainObject(e)?e:{},d=new u.Api(t),s=500,o.speed!==i&&(s=o.speed),(n=function(e){var t=r(d.table().container()).find("div.dataTables_length"),n=d.page.info().pages,i=d.rows({search:"applied"}).count();e instanceof r.Event?n<=1&&i<=a?"fade"===o.style?t.stop().fadeTo(s,0):t.css("visibility","hidden"):"fade"===o.style?t.stop().fadeTo(s,1):t.css("visibility",""):n<=1&&i<=a&&("fade"===o.style?t.css("opacity",0):t.css("visibility","hidden")),o.conditionalOptions&&t.find("select option").each(function(e){parseInt(r(this).attr("value"),10)>i?r(this).hide():r(this).show()})})(null),d.on("draw.dt",n))}),u});
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd, Garrett Hyder - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";$(document).on("init.dt",function(t,a){var n,s,o,l,e;"dt"===t.namespace&&(t=a.oInit.conditionalPageLength||DataTable.defaults.conditionalPageLength,e=a.aLengthMenu||DataTable.defaults.lengthMenu,e=(e=Array.isArray(e[0])?e[0]:e).filter(function(t){return 0<t}),n=Math.min.apply(Math,e),$.isPlainObject(t)||!0===t)&&(s=$.isPlainObject(t)?t:{},o=new DataTable.Api(a),l=500,void 0!==s.speed&&(l=s.speed),(e=function(t){var a=$(o.table().container()).find("div.dataTables_length"),e=o.page.info().pages,i=o.rows({search:"applied"}).count();t instanceof $.Event?e<=1&&i<=n?"fade"===s.style?a.stop().fadeTo(l,0):a.css("visibility","hidden"):"fade"===s.style?a.stop().fadeTo(l,1):a.css("visibility",""):e<=1&&i<=n&&("fade"===s.style?a.css("opacity",0):a.css("visibility","hidden")),s.conditionalOptions&&a.find("select option").each(function(t){parseInt($(this).attr("value"),10)>i?$(this).hide():$(this).show()})})(null),o.on("draw.dt",e))});export default DataTable;
|
@ -0,0 +1,104 @@
|
|||||||
|
/*! © SpryMedia Ltd, Garrett Hyder - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ConditionalPageLength
|
||||||
|
* @description Hide the page length control when the amount of pages is <= 1
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Garrett Hyder (https://github.com/garretthyder)
|
||||||
|
* @copyright Copyright 2020 Garrett Hyder
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature plugin for DataTables hides the page length control when the amount
|
||||||
|
* of pages is <= 1. The control can either appear / disappear or fade in / out.
|
||||||
|
*
|
||||||
|
* Based off conditionalPaging by Matthew Hasbach (https://github.com/mjhasbach)
|
||||||
|
* Reference: https://github.com/DataTables/Plugins/blob/master/features/conditionalPaging/dataTables.conditionalPaging.js
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPageLength: true
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPageLength: {
|
||||||
|
* style: 'fade',
|
||||||
|
* speed: 500 // optional
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* Conditionally hide the Page Length options that are less than the current result size.
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPageLength: {
|
||||||
|
* conditionalOptions: true
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
$(document).on('init.dt', function (e, dtSettings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var options = dtSettings.oInit.conditionalPageLength ||
|
||||||
|
DataTable.defaults.conditionalPageLength, lengthMenu = dtSettings.aLengthMenu || DataTable.defaults.lengthMenu, lengthMenuValues = Array.isArray(lengthMenu[0])
|
||||||
|
? lengthMenu[0]
|
||||||
|
: lengthMenu;
|
||||||
|
lengthMenuValues = lengthMenuValues.filter(function (n) {
|
||||||
|
return n > 0;
|
||||||
|
});
|
||||||
|
var smallestLength = Math.min.apply(Math, lengthMenuValues);
|
||||||
|
if ($.isPlainObject(options) || options === true) {
|
||||||
|
var config = $.isPlainObject(options) ? options : {}, api = new DataTable.Api(dtSettings), speed = 500, conditionalPageLength = function (e) {
|
||||||
|
var $paging = $(api.table().container()).find('div.dataTables_length'), pages = api.page.info().pages, size = api.rows({ search: 'applied' }).count();
|
||||||
|
if (e instanceof $.Event) {
|
||||||
|
if (pages <= 1 && size <= smallestLength) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pages <= 1 && size <= smallestLength) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.css('opacity', 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.conditionalOptions) {
|
||||||
|
$paging.find('select option').each(function (index) {
|
||||||
|
if (parseInt($(this).attr('value'), 10) > size) {
|
||||||
|
$(this).hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(this).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (config.speed !== undefined) {
|
||||||
|
speed = config.speed;
|
||||||
|
}
|
||||||
|
conditionalPageLength(null);
|
||||||
|
api.on('draw.dt', conditionalPageLength);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,124 @@
|
|||||||
|
/*! © SpryMedia Ltd, Garrett Hyder - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ConditionalPageLength
|
||||||
|
* @description Hide the page length control when the amount of pages is <= 1
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Garrett Hyder (https://github.com/garretthyder)
|
||||||
|
* @copyright Copyright 2020 Garrett Hyder
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature plugin for DataTables hides the page length control when the amount
|
||||||
|
* of pages is <= 1. The control can either appear / disappear or fade in / out.
|
||||||
|
*
|
||||||
|
* Based off conditionalPaging by Matthew Hasbach (https://github.com/mjhasbach)
|
||||||
|
* Reference: https://github.com/DataTables/Plugins/blob/master/features/conditionalPaging/dataTables.conditionalPaging.js
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPageLength: true
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPageLength: {
|
||||||
|
* style: 'fade',
|
||||||
|
* speed: 500 // optional
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* Conditionally hide the Page Length options that are less than the current result size.
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPageLength: {
|
||||||
|
* conditionalOptions: true
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
conditionalPageLength: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('init.dt', function (e, dtSettings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var options =
|
||||||
|
dtSettings.oInit.conditionalPageLength ||
|
||||||
|
DataTable.defaults.conditionalPageLength,
|
||||||
|
lengthMenu = dtSettings.aLengthMenu || DataTable.defaults.lengthMenu,
|
||||||
|
lengthMenuValues = Array.isArray(lengthMenu[0])
|
||||||
|
? lengthMenu[0]
|
||||||
|
: lengthMenu;
|
||||||
|
|
||||||
|
lengthMenuValues = lengthMenuValues.filter(function (n) {
|
||||||
|
return n > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
var smallestLength = Math.min.apply(Math, lengthMenuValues);
|
||||||
|
|
||||||
|
if ($.isPlainObject(options) || options === true) {
|
||||||
|
var config = $.isPlainObject(options) ? options : {},
|
||||||
|
api = new DataTable.Api(dtSettings),
|
||||||
|
speed = 500,
|
||||||
|
conditionalPageLength = function (e) {
|
||||||
|
var $paging = $(api.table().container()).find('div.dataTables_length'),
|
||||||
|
pages = api.page.info().pages,
|
||||||
|
size = api.rows({ search: 'applied' }).count();
|
||||||
|
|
||||||
|
if (e instanceof $.Event) {
|
||||||
|
if (pages <= 1 && size <= smallestLength) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pages <= 1 && size <= smallestLength) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.css('opacity', 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.conditionalOptions) {
|
||||||
|
$paging.find('select option').each(function (index) {
|
||||||
|
if (parseInt($(this).attr('value')!, 10) > size) {
|
||||||
|
$(this).hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(this).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (config.speed !== undefined) {
|
||||||
|
speed = config.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
conditionalPageLength(null);
|
||||||
|
|
||||||
|
api.on('draw.dt', conditionalPageLength);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,7 @@
|
|||||||
|
/*! © SpryMedia Ltd, Matthew Hasbach - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
conditionalPaging: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd, Matthew Hasbach - datatables.net/license */
|
||||||
|
!function(i){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return i(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e=e||window,(n=n||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,n),i(n,0,e.document)}:i(jQuery,window,document)}(function(o,e,n,i){"use strict";var s=o.fn.dataTable;return o(n).on("init.dt",function(e,n){var t,a,d;"dt"===e.namespace&&(e=n.oInit.conditionalPaging||s.defaults.conditionalPaging,o.isPlainObject(e)||!0===e)&&(t=o.isPlainObject(e)?e:{},a=new s.Api(n),d=500,t.speed!==i&&(d=t.speed),(e=function(e){var n=o(a.table().container()).find("div.dataTables_paginate"),i=a.page.info().pages;e instanceof o.Event?i<=1?"fade"===t.style?n.stop().fadeTo(d,0):n.css("visibility","hidden"):"fade"===t.style?n.stop().fadeTo(d,1):n.css("visibility",""):i<=1&&("fade"===t.style?n.css("opacity",0):n.css("visibility","hidden"))})(null),a.on("draw.dt",e))}),s});
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd, Matthew Hasbach - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";$(document).on("init.dt",function(a,i){var e,n,s;"dt"===a.namespace&&(a=i.oInit.conditionalPaging||DataTable.defaults.conditionalPaging,$.isPlainObject(a)||!0===a)&&(e=$.isPlainObject(a)?a:{},n=new DataTable.Api(i),s=500,void 0!==e.speed&&(s=e.speed),(a=function(a){var i=$(n.table().container()).find("div.dataTables_paginate"),t=n.page.info().pages;a instanceof $.Event?t<=1?"fade"===e.style?i.stop().fadeTo(s,0):i.css("visibility","hidden"):"fade"===e.style?i.stop().fadeTo(s,1):i.css("visibility",""):t<=1&&("fade"===e.style?i.css("opacity",0):i.css("visibility","hidden"))})(null),n.on("draw.dt",a))});export default DataTable;
|
@ -0,0 +1,77 @@
|
|||||||
|
/*! © SpryMedia Ltd, Matthew Hasbach - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ConditionalPaging
|
||||||
|
* @description Hide paging controls when the amount of pages is <= 1
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Matthew Hasbach (https://github.com/mjhasbach)
|
||||||
|
* @copyright Copyright 2015 Matthew Hasbach
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature plugin for DataTables hides paging controls when the amount
|
||||||
|
* of pages is <= 1. The controls can either appear / disappear or fade in / out
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPaging: true
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPaging: {
|
||||||
|
* style: 'fade',
|
||||||
|
* speed: 500 // optional
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
$(document).on('init.dt', function (e, dtSettings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var options = dtSettings.oInit.conditionalPaging ||
|
||||||
|
DataTable.defaults.conditionalPaging;
|
||||||
|
if ($.isPlainObject(options) || options === true) {
|
||||||
|
var config = $.isPlainObject(options) ? options : {}, api = new DataTable.Api(dtSettings), speed = 500, conditionalPaging = function (e) {
|
||||||
|
var $paging = $(api.table().container()).find('div.dataTables_paginate'), pages = api.page.info().pages;
|
||||||
|
if (e instanceof $.Event) {
|
||||||
|
if (pages <= 1) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pages <= 1) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.css('opacity', 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (config.speed !== undefined) {
|
||||||
|
speed = config.speed;
|
||||||
|
}
|
||||||
|
conditionalPaging(null);
|
||||||
|
api.on('draw.dt', conditionalPaging);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,93 @@
|
|||||||
|
/*! © SpryMedia Ltd, Matthew Hasbach - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ConditionalPaging
|
||||||
|
* @description Hide paging controls when the amount of pages is <= 1
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Matthew Hasbach (https://github.com/mjhasbach)
|
||||||
|
* @copyright Copyright 2015 Matthew Hasbach
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature plugin for DataTables hides paging controls when the amount
|
||||||
|
* of pages is <= 1. The controls can either appear / disappear or fade in / out
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPaging: true
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* conditionalPaging: {
|
||||||
|
* style: 'fade',
|
||||||
|
* speed: 500 // optional
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
conditionalPaging: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('init.dt', function (e, dtSettings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var options =
|
||||||
|
dtSettings.oInit.conditionalPaging ||
|
||||||
|
DataTable.defaults.conditionalPaging;
|
||||||
|
|
||||||
|
if ($.isPlainObject(options) || options === true) {
|
||||||
|
var config = $.isPlainObject(options) ? options : {},
|
||||||
|
api = new DataTable.Api(dtSettings),
|
||||||
|
speed = 500,
|
||||||
|
conditionalPaging = function (e) {
|
||||||
|
var $paging = $(api.table().container()).find(
|
||||||
|
'div.dataTables_paginate'
|
||||||
|
),
|
||||||
|
pages = api.page.info().pages;
|
||||||
|
|
||||||
|
if (e instanceof $.Event) {
|
||||||
|
if (pages <= 1) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.stop().fadeTo(speed, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pages <= 1) {
|
||||||
|
if (config.style === 'fade') {
|
||||||
|
$paging.css('opacity', 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$paging.css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (config.speed !== undefined) {
|
||||||
|
speed = config.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
conditionalPaging(null);
|
||||||
|
|
||||||
|
api.on('draw.dt', conditionalPaging);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,8 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStaticExt {
|
||||||
|
/** Deep linking options parsing support for DataTables */
|
||||||
|
deepLink(whitelist: 'all' | string[]): any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,4 +1,2 @@
|
|||||||
/*! Deep linking options parsing support for DataTables
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2017 SpryMedia Ltd - datatables.net/license
|
!function(t){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return t(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e=e||window,(n=n||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,n),t(n,0,e.document)}:t(jQuery,window,document)}(function(d,e,n,t){"use strict";var u=d.fn.dataTable;return u.ext.deepLink=function(e){for(var n=location.search.replace(/^\?/,"").split("&"),t={},r=0,i=n.length;r<i;r++){var o=n[r].split("="),a=decodeURIComponent(o[0]),o=decodeURIComponent(o[1]);if("true"===o)o=!0;else if("false"===o)o=!1;else if(o.match(/[^\d]/)||"search.search"===a){if(0===o.indexOf("{")||0===o.indexOf("["))try{o=d.parseJSON(o)}catch(e){}}else o=+o;"all"!==e&&-1===d.inArray(a,e)||u.util.set(a)(t,o,{})}return t},u});
|
||||||
*/
|
|
||||||
!function(l){var f=l.fn.dataTable.ext.internal._fnSetObjectDataFn;l.fn.dataTable.ext.deepLink=function(e){for(var a=location.search.replace(/^\?/,"").split("&"),n={},t=0,r=a.length;t<r;t++){var i=a[t].split("="),c=decodeURIComponent(i[0]),i=decodeURIComponent(i[1]);if("true"===i)i=!0;else if("false"===i)i=!1;else if(i.match(/[^\d]/)||"search.search"===c){if(0===i.indexOf("{")||0===i.indexOf("["))try{i=l.parseJSON(i)}catch(e){}}else i=+i;"all"!==e&&-1===l.inArray(c,e)||f(c)(n,i)}return n}}((window,document,jQuery));
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";DataTable.ext.deepLink=function(e){for(var a=location.search.replace(/^\?/,"").split("&"),t={},r=0,l=a.length;r<l;r++){var i=a[r].split("="),o=decodeURIComponent(i[0]),i=decodeURIComponent(i[1]);if("true"===i)i=!0;else if("false"===i)i=!1;else if(i.match(/[^\d]/)||"search.search"===o){if(0===i.indexOf("{")||0===i.indexOf("["))try{i=$.parseJSON(i)}catch(e){}}else i=+i;"all"!==e&&-1===$.inArray(o,e)||DataTable.util.set(o)(t,i,{})}return t};export default DataTable;
|
@ -0,0 +1,85 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary LengthLinks
|
||||||
|
* @description Deep linking options parsing support for DataTables
|
||||||
|
* @version 1.1.0
|
||||||
|
* @file dataTables.deepLink.js
|
||||||
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
|
* @copyright Copyright SpryMedia Ltd.
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables provides a function which will
|
||||||
|
* take DataTables options from the browser's URL search string and
|
||||||
|
* return an object that can be used to construct a DataTable. This
|
||||||
|
* allows deep linking to be easily implemented with DataTables - for
|
||||||
|
* example a URL might be `myTable?displayStart=10` which will
|
||||||
|
* automatically cause the second page of the DataTable to be displayed.
|
||||||
|
*
|
||||||
|
* This plug-in works on a whitelist basis - you must specify which
|
||||||
|
* [initialisation parameters](//datatables.net/reference/option) you
|
||||||
|
* want the URL search string to specify. Any parameter given in the
|
||||||
|
* URL which is not listed will be ignored (e.g. you are unlikely to
|
||||||
|
* want to let the URL search string specify the `ajax` option).
|
||||||
|
*
|
||||||
|
* This specification is done by passing an array of property names
|
||||||
|
* to the `DataTable.ext.deepLink` function. If you do which to
|
||||||
|
* allow _every_ parameter (I wouldn't recommend it) you can use `all`
|
||||||
|
* instead of an array.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Allow a display start point and search string to be specified
|
||||||
|
* $('#myTable').DataTable(
|
||||||
|
* DataTable.ext.deepLink( [ 'displayStart', 'search.search' ] )
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // As above, but with a default search
|
||||||
|
* var options = DataTable.ext.deepLink(['displayStart', 'search.search']);
|
||||||
|
*
|
||||||
|
* $('#myTable').DataTable(
|
||||||
|
* $.extend( true, {
|
||||||
|
* search: { search: 'Initial search value' }
|
||||||
|
* }, options )
|
||||||
|
* );
|
||||||
|
*/
|
||||||
|
DataTable.ext.deepLink = function (whitelist) {
|
||||||
|
var search = location.search.replace(/^\?/, '').split('&');
|
||||||
|
var out = {};
|
||||||
|
for (var i = 0, ien = search.length; i < ien; i++) {
|
||||||
|
var pair = search[i].split('=');
|
||||||
|
var key = decodeURIComponent(pair[0]);
|
||||||
|
var value = decodeURIComponent(pair[1]);
|
||||||
|
// "Casting"
|
||||||
|
if (value === 'true') {
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
else if (value === 'false') {
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
else if (!value.match(/[^\d]/) && key !== 'search.search') {
|
||||||
|
// don't convert if searching or it'll break the search
|
||||||
|
value = value * 1;
|
||||||
|
}
|
||||||
|
else if (value.indexOf('{') === 0 || value.indexOf('[') === 0) {
|
||||||
|
// Try to JSON parse for arrays and obejcts
|
||||||
|
try {
|
||||||
|
value = $.parseJSON(value);
|
||||||
|
}
|
||||||
|
catch (e) { }
|
||||||
|
}
|
||||||
|
if (whitelist === 'all' || $.inArray(key, whitelist) !== -1) {
|
||||||
|
var setter = DataTable.util.set(key);
|
||||||
|
setter(out, value, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,92 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary LengthLinks
|
||||||
|
* @description Deep linking options parsing support for DataTables
|
||||||
|
* @version 1.1.0
|
||||||
|
* @file dataTables.deepLink.js
|
||||||
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
|
* @copyright Copyright SpryMedia Ltd.
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables provides a function which will
|
||||||
|
* take DataTables options from the browser's URL search string and
|
||||||
|
* return an object that can be used to construct a DataTable. This
|
||||||
|
* allows deep linking to be easily implemented with DataTables - for
|
||||||
|
* example a URL might be `myTable?displayStart=10` which will
|
||||||
|
* automatically cause the second page of the DataTable to be displayed.
|
||||||
|
*
|
||||||
|
* This plug-in works on a whitelist basis - you must specify which
|
||||||
|
* [initialisation parameters](//datatables.net/reference/option) you
|
||||||
|
* want the URL search string to specify. Any parameter given in the
|
||||||
|
* URL which is not listed will be ignored (e.g. you are unlikely to
|
||||||
|
* want to let the URL search string specify the `ajax` option).
|
||||||
|
*
|
||||||
|
* This specification is done by passing an array of property names
|
||||||
|
* to the `DataTable.ext.deepLink` function. If you do which to
|
||||||
|
* allow _every_ parameter (I wouldn't recommend it) you can use `all`
|
||||||
|
* instead of an array.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Allow a display start point and search string to be specified
|
||||||
|
* $('#myTable').DataTable(
|
||||||
|
* DataTable.ext.deepLink( [ 'displayStart', 'search.search' ] )
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // As above, but with a default search
|
||||||
|
* var options = DataTable.ext.deepLink(['displayStart', 'search.search']);
|
||||||
|
*
|
||||||
|
* $('#myTable').DataTable(
|
||||||
|
* $.extend( true, {
|
||||||
|
* search: { search: 'Initial search value' }
|
||||||
|
* }, options )
|
||||||
|
* );
|
||||||
|
*/
|
||||||
|
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStaticExt {
|
||||||
|
/** Deep linking options parsing support for DataTables */
|
||||||
|
deepLink(whitelist: 'all' | string[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.ext.deepLink = function (whitelist) {
|
||||||
|
var search = location.search.replace(/^\?/, '').split('&');
|
||||||
|
var out = {};
|
||||||
|
|
||||||
|
for (var i = 0, ien = search.length; i < ien; i++) {
|
||||||
|
var pair = search[i].split('=');
|
||||||
|
var key = decodeURIComponent(pair[0]);
|
||||||
|
var value: any = decodeURIComponent(pair[1]);
|
||||||
|
|
||||||
|
// "Casting"
|
||||||
|
if (value === 'true') {
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
else if (value === 'false') {
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
else if (!value.match(/[^\d]/) && key !== 'search.search') {
|
||||||
|
// don't convert if searching or it'll break the search
|
||||||
|
value = value * 1;
|
||||||
|
}
|
||||||
|
else if (value.indexOf('{') === 0 || value.indexOf('[') === 0) {
|
||||||
|
// Try to JSON parse for arrays and obejcts
|
||||||
|
try {
|
||||||
|
value = $.parseJSON(value);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (whitelist === 'all' || $.inArray(key, whitelist) !== -1) {
|
||||||
|
var setter = DataTable.util.set(key);
|
||||||
|
|
||||||
|
setter(out, value, {} as any);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
};
|
@ -0,0 +1,19 @@
|
|||||||
|
/*! © Ulises Gomez / Gravity Lending, SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Add an input box that will remove matching items from the table */
|
||||||
|
ExcludeSearch(settings: any): void;
|
||||||
|
}
|
||||||
|
interface Config {
|
||||||
|
alphabet?: {
|
||||||
|
column: number;
|
||||||
|
caseSensitive: boolean;
|
||||||
|
numbers: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
interface Api<T> {
|
||||||
|
/** Set an exclude term */
|
||||||
|
excludeSearch(searchTerm: string): Api<T>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © Ulises Gomez / Gravity Lending, SpryMedia Ltd - datatables.net/license */
|
||||||
|
!function(n){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return n(e,window,document)}):"object"==typeof exports?module.exports=function(e,t){return e=e||window,(t=t||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,t),n(t,0,e.document)}:n(jQuery,window,document)}(function(u,e,t,r){"use strict";var i=u.fn.dataTable;return i.Api.register("excludeSearch()",function(t){return this.iterator("table",function(e){e.exclude_search=t}),this}),i.ext.search.push(function(t,e){if(""===t.exclude_search||t.exclude_search===r||null===t.exclude_search)return!0;let n=!0;return e.forEach(e=>{e.toUpperCase().includes(t.exclude_search.toUpperCase())&&(n=!1)}),n}),i.ExcludeSearch=function(e){let t=new i.Api(e),n=u('<div class="mx-3 dataTables_filter"><label>Exclude: </label><input type="text" /></div>');n.find("input").on("input",function(){t.excludeSearch(u(this).val()).draw()}),this.node=function(){return n}},i.ext.feature.push({fnInit:function(e){return new i.ExcludeSearch(e).node()},cFeature:"X"}),i});
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © Ulises Gomez / Gravity Lending, SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";DataTable.Api.register("excludeSearch()",function(a){return this.iterator("table",function(e){e.exclude_search=a}),this}),DataTable.ext.search.push(function(a,e){if(""===a.exclude_search||void 0===a.exclude_search||null===a.exclude_search)return!0;let t=!0;return e.forEach(e=>{e.toUpperCase().includes(a.exclude_search.toUpperCase())&&(t=!1)}),t}),DataTable.ExcludeSearch=function(e){let a=new DataTable.Api(e),t=$('<div class="mx-3 dataTables_filter"><label>Exclude: </label><input type="text" /></div>');t.find("input").on("input",function(){a.excludeSearch($(this).val()).draw()}),this.node=function(){return t}},DataTable.ext.feature.push({fnInit:function(e){return new DataTable.ExcludeSearch(e).node()},cFeature:"X"});export default DataTable;
|
@ -0,0 +1,68 @@
|
|||||||
|
/*! © Ulises Gomez / Gravity Lending, SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ExcludeSearch
|
||||||
|
* @description Add an input box that will remove matching items from the table
|
||||||
|
* @version 1.0.1
|
||||||
|
* @file dataTables.excludeSearch.js
|
||||||
|
* @author Ulises Gomez / Gravity Lending (https://www.linkedin.com/in/ulises-gomez/)
|
||||||
|
* @copyright Copyright 2023 Ulises Gomez
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature adds a search input box to DataTables that will remove any rows that
|
||||||
|
* match the user's input from the display. Think of it as the inverse of the default
|
||||||
|
* search.
|
||||||
|
*
|
||||||
|
* An [example is available here](http://live.datatables.net/zohoyoqa/1/edit).
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* excludeSearch: true
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
DataTable.Api.register('excludeSearch()', function (searchTerm) {
|
||||||
|
this.iterator('table', function (context) {
|
||||||
|
context.exclude_search = searchTerm;
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
DataTable.ext.search.push(function (context, search_data) {
|
||||||
|
if (context.exclude_search === '' ||
|
||||||
|
context.exclude_search === undefined ||
|
||||||
|
context.exclude_search === null) {
|
||||||
|
// No search term - all results shown
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let show_row = true;
|
||||||
|
search_data.forEach(val => {
|
||||||
|
if (val.toUpperCase().includes(context.exclude_search.toUpperCase())) {
|
||||||
|
show_row = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return show_row;
|
||||||
|
});
|
||||||
|
DataTable.ExcludeSearch = function (context) {
|
||||||
|
let table = new DataTable.Api(context);
|
||||||
|
// class mx-3 is from bootstrap v4
|
||||||
|
let input_container = $('<div class="mx-3 dataTables_filter"><label>Exclude: </label><input type="text" /></div>');
|
||||||
|
input_container.find('input').on('input', function () {
|
||||||
|
table.excludeSearch($(this).val()).draw();
|
||||||
|
});
|
||||||
|
this.node = function () {
|
||||||
|
return input_container;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
return new DataTable.ExcludeSearch(settings).node();
|
||||||
|
},
|
||||||
|
cFeature: 'X',
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,94 @@
|
|||||||
|
/*! © Ulises Gomez / Gravity Lending, SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ExcludeSearch
|
||||||
|
* @description Add an input box that will remove matching items from the table
|
||||||
|
* @version 1.0.1
|
||||||
|
* @file dataTables.excludeSearch.js
|
||||||
|
* @author Ulises Gomez / Gravity Lending (https://www.linkedin.com/in/ulises-gomez/)
|
||||||
|
* @copyright Copyright 2023 Ulises Gomez
|
||||||
|
*
|
||||||
|
* License MIT - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This feature adds a search input box to DataTables that will remove any rows that
|
||||||
|
* match the user's input from the display. Think of it as the inverse of the default
|
||||||
|
* search.
|
||||||
|
*
|
||||||
|
* An [example is available here](http://live.datatables.net/zohoyoqa/1/edit).
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable({
|
||||||
|
* excludeSearch: true
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Add an input box that will remove matching items from the table */
|
||||||
|
ExcludeSearch(settings: any): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
alphabet?: {
|
||||||
|
column: number;
|
||||||
|
caseSensitive: boolean;
|
||||||
|
numbers: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Api<T> {
|
||||||
|
/** Set an exclude term */
|
||||||
|
excludeSearch(searchTerm: string): Api<T>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.Api.register('excludeSearch()', function (searchTerm) {
|
||||||
|
this.iterator('table', function (context) {
|
||||||
|
context.exclude_search = searchTerm;
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
|
||||||
|
DataTable.ext.search.push(function (context, search_data) {
|
||||||
|
if (
|
||||||
|
context.exclude_search === '' ||
|
||||||
|
context.exclude_search === undefined ||
|
||||||
|
context.exclude_search === null
|
||||||
|
) {
|
||||||
|
// No search term - all results shown
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let show_row = true;
|
||||||
|
search_data.forEach(val => {
|
||||||
|
if (val.toUpperCase().includes(context.exclude_search.toUpperCase())) {
|
||||||
|
show_row = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return show_row;
|
||||||
|
});
|
||||||
|
|
||||||
|
DataTable.ExcludeSearch = function (context) {
|
||||||
|
let table = new DataTable.Api(context);
|
||||||
|
|
||||||
|
// class mx-3 is from bootstrap v4
|
||||||
|
let input_container = $(
|
||||||
|
'<div class="mx-3 dataTables_filter"><label>Exclude: </label><input type="text" /></div>'
|
||||||
|
);
|
||||||
|
|
||||||
|
input_container.find('input').on('input', function () {
|
||||||
|
table.excludeSearch($(this).val() as string).draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.node = function () {
|
||||||
|
return input_container;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
return new DataTable.ExcludeSearch(settings).node();
|
||||||
|
},
|
||||||
|
cFeature: 'X',
|
||||||
|
});
|
@ -0,0 +1,25 @@
|
|||||||
|
/*!
|
||||||
|
* Fuzzy Search for DataTables
|
||||||
|
* 2021 SpryMedia Ltd - datatables.net/license MIT license
|
||||||
|
*
|
||||||
|
* Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein
|
||||||
|
* BSD 2-Clause License
|
||||||
|
* Copyright (c) 2018, Tadeusz Łazurski
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
fuzzySearch?: boolean | {
|
||||||
|
rankColumn?: number;
|
||||||
|
threshold?: number;
|
||||||
|
toggleSmart?: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
interface State {
|
||||||
|
_fuzzySearch: {
|
||||||
|
active: 'true' | 'false';
|
||||||
|
val: any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,450 +1,447 @@
|
|||||||
/*!
|
/*!
|
||||||
* Fuzzy Search for DataTables
|
* Fuzzy Search for DataTables
|
||||||
* 2021 SpryMedia Ltd - datatables.net/license MIT license
|
* 2021 SpryMedia Ltd - datatables.net/license MIT license
|
||||||
*
|
*
|
||||||
* Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein
|
* Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein
|
||||||
* BSD 2-Clause License
|
* BSD 2-Clause License
|
||||||
* Copyright (c) 2018, Tadeusz Łazurski
|
* Copyright (c) 2018, Tadeusz Łazurski
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
(function() {
|
|
||||||
function levenshtein(__this, that, limit) {
|
(function( factory ){
|
||||||
|
if ( typeof define === 'function' && define.amd ) {
|
||||||
var thisLength = __this.length,
|
// AMD
|
||||||
thatLength = that.length,
|
define( ['jquery', 'datatables.net'], function ( $ ) {
|
||||||
matrix = [];
|
return factory( $, window, document );
|
||||||
|
} );
|
||||||
// If the limit is not defined it will be calculate from this and that args.
|
}
|
||||||
limit = (limit || ((thatLength > thisLength ? thatLength : thisLength)))+1;
|
else if ( typeof exports === 'object' ) {
|
||||||
|
// CommonJS
|
||||||
for (var i = 0; i < limit; i++) {
|
module.exports = function (root, $) {
|
||||||
matrix[i] = [i];
|
if ( ! root ) {
|
||||||
matrix[i].length = limit;
|
// CommonJS environments without a window global must pass a
|
||||||
}
|
// root. This will give an error otherwise
|
||||||
for (i = 0; i < limit; i++) {
|
root = window;
|
||||||
matrix[0][i] = i;
|
}
|
||||||
}
|
|
||||||
|
if ( ! $ ) {
|
||||||
if (Math.abs(thisLength - thatLength) > (limit || 100)){
|
$ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
|
||||||
return prepare (limit || 100);
|
require('jquery') :
|
||||||
}
|
require('jquery')( root );
|
||||||
if (thisLength === 0){
|
}
|
||||||
return prepare (thatLength);
|
|
||||||
}
|
if ( ! $.fn.dataTable ) {
|
||||||
if (thatLength === 0){
|
require('datatables.net')(root, $);
|
||||||
return prepare (thisLength);
|
}
|
||||||
|
|
||||||
|
return factory( $, root, root.document );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Browser
|
||||||
|
factory( jQuery, window, document );
|
||||||
|
}
|
||||||
|
}(function( $, window, document, undefined ) {
|
||||||
|
'use strict';
|
||||||
|
var DataTable = $.fn.dataTable;
|
||||||
|
|
||||||
|
|
||||||
|
function levenshtein(__this, that, limit) {
|
||||||
|
var thisLength = __this.length, thatLength = that.length, matrix = [];
|
||||||
|
// If the limit is not defined it will be calculate from this and that args.
|
||||||
|
limit = (limit || (thatLength > thisLength ? thatLength : thisLength)) + 1;
|
||||||
|
for (var i = 0; i < limit; i++) {
|
||||||
|
matrix[i] = [i];
|
||||||
|
matrix[i].length = limit;
|
||||||
|
}
|
||||||
|
for (i = 0; i < limit; i++) {
|
||||||
|
matrix[0][i] = i;
|
||||||
|
}
|
||||||
|
if (Math.abs(thisLength - thatLength) > (limit || 100)) {
|
||||||
|
return prepare(limit || 100);
|
||||||
|
}
|
||||||
|
if (thisLength === 0) {
|
||||||
|
return prepare(thatLength);
|
||||||
|
}
|
||||||
|
if (thatLength === 0) {
|
||||||
|
return prepare(thisLength);
|
||||||
|
}
|
||||||
|
// Calculate matrix.
|
||||||
|
var j, this_i, that_j, cost, min, t;
|
||||||
|
for (i = 1; i <= thisLength; ++i) {
|
||||||
|
this_i = __this[i - 1];
|
||||||
|
// Step 4
|
||||||
|
for (j = 1; j <= thatLength; ++j) {
|
||||||
|
// Check the jagged ld total so far
|
||||||
|
if (i === j && matrix[i][j] > 4)
|
||||||
|
return prepare(thisLength);
|
||||||
|
that_j = that[j - 1];
|
||||||
|
cost = this_i === that_j ? 0 : 1; // Step 5
|
||||||
|
// Calculate the minimum (much faster than Math.min(...)).
|
||||||
|
min = matrix[i - 1][j] + 1; // Devarion.
|
||||||
|
if ((t = matrix[i][j - 1] + 1) < min)
|
||||||
|
min = t; // Insertion.
|
||||||
|
if ((t = matrix[i - 1][j - 1] + cost) < min)
|
||||||
|
min = t; // Substitution.
|
||||||
|
// Update matrix.
|
||||||
|
matrix[i][j] =
|
||||||
|
i > 1 &&
|
||||||
|
j > 1 &&
|
||||||
|
this_i === that[j - 2] &&
|
||||||
|
__this[i - 2] === that_j &&
|
||||||
|
(t = matrix[i - 2][j - 2] + cost) < min
|
||||||
|
? t
|
||||||
|
: min; // Transposition.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Calculate matrix.
|
return prepare(matrix[thisLength][thatLength]);
|
||||||
var j, this_i, that_j, cost, min, t;
|
function prepare(steps) {
|
||||||
for (i = 1; i <= thisLength; ++i) {
|
var length = Math.max(thisLength, thatLength);
|
||||||
this_i = __this[i-1];
|
var relative = length === 0 ? 0 : steps / length;
|
||||||
|
var similarity = 1 - relative;
|
||||||
// Step 4
|
return {
|
||||||
for (j = 1; j <= thatLength; ++j) {
|
steps: steps,
|
||||||
// Check the jagged ld total so far
|
relative: relative,
|
||||||
if (i === j && matrix[i][j] > 4) return prepare (thisLength);
|
similarity: similarity,
|
||||||
|
};
|
||||||
that_j = that[j-1];
|
}
|
||||||
cost = (this_i === that_j) ? 0 : 1; // Step 5
|
}
|
||||||
// Calculate the minimum (much faster than Math.min(...)).
|
function fuzzySearch(searchVal, data, initial) {
|
||||||
min = matrix[i - 1][j ] + 1; // Devarion.
|
// If no searchVal has been defined then return all rows.
|
||||||
if ((t = matrix[i ][j - 1] + 1 ) < min) min = t; // Insertion.
|
if (searchVal === undefined || searchVal.length === 0) {
|
||||||
if ((t = matrix[i - 1][j - 1] + cost) < min) min = t; // Substitution.
|
return {
|
||||||
|
pass: true,
|
||||||
// Update matrix.
|
score: '',
|
||||||
matrix[i][j] = (i > 1 && j > 1 && this_i === that[j-2] && __this[i-2] === that_j && (t = matrix[i-2][j-2]+cost) < min) ? t : min; // Transposition.
|
};
|
||||||
}
|
}
|
||||||
|
var threshold = initial.threshold !== undefined ? initial.threshold : 0.5;
|
||||||
|
// Split the searchVal into individual words.
|
||||||
|
var splitSearch = searchVal.split(/ /g);
|
||||||
|
// Array to keep scores in
|
||||||
|
var highestCollated = [];
|
||||||
|
// Remove any empty words or spaces
|
||||||
|
for (var x = 0; x < splitSearch.length; x++) {
|
||||||
|
if (splitSearch[x].length === 0 || splitSearch[x] === ' ') {
|
||||||
|
splitSearch.splice(x, 1);
|
||||||
|
x--;
|
||||||
}
|
}
|
||||||
|
// Aside - Add to the score collection if not done so yet for this search word
|
||||||
return prepare (matrix[thisLength][thatLength]);
|
else if (highestCollated.length < splitSearch.length) {
|
||||||
|
highestCollated.push({ pass: false, score: 0 });
|
||||||
function prepare(steps) {
|
|
||||||
var length = Math.max(thisLength, thatLength)
|
|
||||||
var relative = length === 0
|
|
||||||
? 0
|
|
||||||
: (steps / length);
|
|
||||||
var similarity = 1 - relative
|
|
||||||
return {
|
|
||||||
steps: steps,
|
|
||||||
relative: relative,
|
|
||||||
similarity: similarity
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Going to check each cell for potential matches
|
||||||
function fuzzySearch(searchVal, data, initial) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
// If no searchVal has been defined then return all rows.
|
// Convert all data points to lower case fo insensitive sorting
|
||||||
if(searchVal === undefined || searchVal.length === 0) {
|
data[i] = data[i].toLowerCase();
|
||||||
return {
|
// Split the data into individual words
|
||||||
pass: true,
|
var splitData = data[i].split(/ /g);
|
||||||
score: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var threshold = initial.threshold !== undefined ? initial.threshold : 0.5;
|
|
||||||
|
|
||||||
// Split the searchVal into individual words.
|
|
||||||
var splitSearch = searchVal.split(/ /g);
|
|
||||||
|
|
||||||
// Array to keep scores in
|
|
||||||
var highestCollated = [];
|
|
||||||
|
|
||||||
// Remove any empty words or spaces
|
// Remove any empty words or spaces
|
||||||
for(var x = 0; x < splitSearch.length; x++) {
|
for (var y = 0; y < splitData.length; y++) {
|
||||||
if (splitSearch[x].length === 0 || splitSearch[x] === ' ') {
|
if (splitData[y].length === 0 || splitData[y] === ' ') {
|
||||||
splitSearch.splice(x, 1);
|
splitData.splice(y, 1);
|
||||||
x--;
|
x--;
|
||||||
}
|
}
|
||||||
// Aside - Add to the score collection if not done so yet for this search word
|
|
||||||
else if (highestCollated.length < splitSearch.length) {
|
|
||||||
highestCollated.push({pass: false, score: 0});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Check each search term word
|
||||||
// Going to check each cell for potential matches
|
for (var x = 0; x < splitSearch.length; x++) {
|
||||||
for(var i = 0; i < data.length; i++) {
|
// Reset highest score
|
||||||
// Convert all data points to lower case fo insensitive sorting
|
var highest = {
|
||||||
data[i] = data[i].toLowerCase();
|
pass: undefined,
|
||||||
|
score: 0,
|
||||||
// Split the data into individual words
|
};
|
||||||
var splitData = data[i].split(/ /g);
|
// Against each word in the cell
|
||||||
|
for (var y = 0; y < splitData.length; y++) {
|
||||||
// Remove any empty words or spaces
|
// If this search Term word is the beginning of the word in the cell we want to pass this word
|
||||||
for (var y = 0; y < splitData.length; y++){
|
if (splitData[y].indexOf(splitSearch[x]) === 0) {
|
||||||
if(splitData[y].length === 0 || splitData[y] === ' ') {
|
var newScore = splitSearch[x].length / splitData[y].length;
|
||||||
splitData.splice(y, 1);
|
highest = {
|
||||||
x--;
|
pass: true,
|
||||||
}
|
score: highest.score < newScore ? newScore : highest.score,
|
||||||
}
|
|
||||||
|
|
||||||
// Check each search term word
|
|
||||||
for(var x = 0; x < splitSearch.length; x++) {
|
|
||||||
// Reset highest score
|
|
||||||
var highest = {
|
|
||||||
pass: undefined,
|
|
||||||
score: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
// Against each word in the cell
|
|
||||||
for (var y = 0; y < splitData.length; y++){
|
|
||||||
// If this search Term word is the beginning of the word in the cell we want to pass this word
|
|
||||||
if(splitData[y].indexOf(splitSearch[x]) === 0){
|
|
||||||
var newScore = splitSearch[x].length / splitData[y].length;
|
|
||||||
highest = {
|
|
||||||
pass: true,
|
|
||||||
score: highest.score < newScore ? newScore : highest.score
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the levenshtein similarity score for the two words
|
|
||||||
var steps = levenshtein(splitSearch[x], splitData[y]).similarity;
|
|
||||||
|
|
||||||
// If the levenshtein similarity score is better than a previous one for the search word then var's store it
|
|
||||||
if(steps > highest.score) {
|
|
||||||
highest.score = steps;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this cell has a higher scoring word than previously found to the search term in the row, store it
|
|
||||||
if(highestCollated[x].score < highest.score || highest.pass) {
|
|
||||||
highestCollated[x] = {
|
|
||||||
pass: highest.pass || highestCollated.pass ? true : highest.score > threshold,
|
|
||||||
score: highest.score
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// Get the levenshtein similarity score for the two words
|
||||||
|
var steps = levenshtein(splitSearch[x], splitData[y]).similarity;
|
||||||
|
// If the levenshtein similarity score is better than a previous one for the search word then var's store it
|
||||||
|
if (steps > highest.score) {
|
||||||
|
highest.score = steps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// If this cell has a higher scoring word than previously found to the search term in the row, store it
|
||||||
|
if (highestCollated[x].score < highest.score || highest.pass) {
|
||||||
// Check that all of the search words have passed
|
highestCollated[x] = {
|
||||||
for(var i = 0; i < highestCollated.length; i++) {
|
pass: highest.pass || highestCollated[x].pass
|
||||||
if(!highestCollated[i].pass) {
|
? true
|
||||||
return {
|
: highest.score > threshold,
|
||||||
pass: false,
|
score: highest.score,
|
||||||
score: Math.round(((highestCollated.reduce((a,b) => a+b.score, 0) / highestCollated.length) * 100)) + "%"
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get to here, all scores greater than 0.5 so display the row
|
|
||||||
return {
|
|
||||||
pass: true,
|
|
||||||
score: Math.round(((highestCollated.reduce((a,b) => a+b.score, 0) / highestCollated.length) * 100)) + "%"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
// Check that all of the search words have passed
|
||||||
$.fn.dataTable.ext.search.push(
|
for (var i = 0; i < highestCollated.length; i++) {
|
||||||
function( settings, data, dataIndex ) {
|
if (!highestCollated[i].pass) {
|
||||||
var initial = settings.oInit.fuzzySearch;
|
return {
|
||||||
|
pass: false,
|
||||||
if (! initial) {
|
score: Math.round((highestCollated.reduce((a, b) => a + b.score, 0) /
|
||||||
return true;
|
highestCollated.length) *
|
||||||
}
|
100) + '%',
|
||||||
|
};
|
||||||
// If fuzzy searching has not been implemented then pass all rows for this function
|
|
||||||
if (settings.aoData[dataIndex]._fuzzySearch !== undefined) {
|
|
||||||
// Read score to set the cell content and sort data
|
|
||||||
var score = settings.aoData[dataIndex]._fuzzySearch.score;
|
|
||||||
|
|
||||||
if (initial.rankColumn !== undefined) {
|
|
||||||
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = score;
|
|
||||||
|
|
||||||
// Remove '%' from the end of the score so can sort on a number
|
|
||||||
settings.aoData[dataIndex]._aSortData[initial.rankColumn] = +score.substring(0, score.length - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the value for the pass as decided by the fuzzySearch function
|
|
||||||
return settings.aoData[dataIndex]._fuzzySearch.pass;
|
|
||||||
}
|
|
||||||
else if (initial.rankColumn !== undefined) {
|
|
||||||
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = '';
|
|
||||||
settings.aoData[dataIndex]._aSortData[initial.rankColumn] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
// If we get to here, all scores greater than 0.5 so display the row
|
||||||
$(document).on('init.dt', function(e, settings) {
|
return {
|
||||||
var api = new $.fn.dataTable.Api(settings);
|
pass: true,
|
||||||
var initial = api.init();
|
score: Math.round((highestCollated.reduce((a, b) => a + b.score, 0) /
|
||||||
var initialFuzzy = initial.fuzzySearch;
|
highestCollated.length) *
|
||||||
|
100) + '%',
|
||||||
// If this is not set then fuzzy searching is not enabled on the table so return.
|
};
|
||||||
if(!initialFuzzy) {
|
}
|
||||||
return;
|
DataTable.ext.search.push(function (settings, data, dataIndex) {
|
||||||
|
var initial = settings.oInit.fuzzySearch;
|
||||||
|
if (!initial) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If fuzzy searching has not been implemented then pass all rows for this function
|
||||||
|
if (settings.aoData[dataIndex]._fuzzySearch !== undefined) {
|
||||||
|
// Read score to set the cell content and sort data
|
||||||
|
var score = settings.aoData[dataIndex]._fuzzySearch.score;
|
||||||
|
if (initial.rankColumn !== undefined) {
|
||||||
|
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = score;
|
||||||
|
// Remove '%' from the end of the score so can sort on a number
|
||||||
|
settings.aoData[dataIndex]._aSortData[initial.rankColumn] =
|
||||||
|
+score.substring(0, score.length - 1);
|
||||||
}
|
}
|
||||||
|
// Return the value for the pass as decided by the fuzzySearch function
|
||||||
var fromPlugin = false;
|
return settings.aoData[dataIndex]._fuzzySearch.pass;
|
||||||
|
}
|
||||||
// Find the input element
|
else if (initial.rankColumn !== undefined) {
|
||||||
var input = $('div.dataTables_filter input', api.table().container())
|
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = '';
|
||||||
|
settings.aoData[dataIndex]._aSortData[initial.rankColumn] = '';
|
||||||
var fontBold = {
|
}
|
||||||
'font-weight': '600',
|
return true;
|
||||||
'background-color': 'rgba(255,255,255,0.1)'
|
});
|
||||||
};
|
$(document).on('init.dt', function (e, settings) {
|
||||||
var fontNormal = {
|
var api = new DataTable.Api(settings);
|
||||||
'font-weight': '500',
|
var initial = api.init();
|
||||||
'background-color': 'transparent'
|
var initialFuzzy = initial.fuzzySearch;
|
||||||
};
|
// If this is not set then fuzzy searching is not enabled on the table so return.
|
||||||
var toggleCSS = {
|
if (!initialFuzzy) {
|
||||||
'border': 'none',
|
return;
|
||||||
'background': 'none',
|
}
|
||||||
'font-size': '100%',
|
var fromPlugin = false;
|
||||||
'width': '50%',
|
// Find the input element
|
||||||
'display': 'inline-block',
|
var input = $('div.dataTables_filter input', api.table().container());
|
||||||
'color': 'white',
|
var fontBold = {
|
||||||
'cursor': 'pointer',
|
'font-weight': '600',
|
||||||
'padding': '0.5em'
|
'background-color': 'rgba(255,255,255,0.1)',
|
||||||
|
};
|
||||||
|
var fontNormal = {
|
||||||
|
'font-weight': '500',
|
||||||
|
'background-color': 'transparent',
|
||||||
|
};
|
||||||
|
var toggleCSS = {
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
'font-size': '100%',
|
||||||
|
width: '50%',
|
||||||
|
display: 'inline-block',
|
||||||
|
color: 'white',
|
||||||
|
cursor: 'pointer',
|
||||||
|
padding: '0.5em',
|
||||||
|
};
|
||||||
|
// Only going to set the toggle if it is enabled
|
||||||
|
var toggle, tooltip, exact, fuzzy, label;
|
||||||
|
if (typeof initialFuzzy === 'object' && initialFuzzy.toggleSmart) {
|
||||||
|
toggle = $('<button class="toggleSearch">Abc</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css({
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
position: 'relative',
|
||||||
|
right: '33px',
|
||||||
|
top: '0px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
color: '#3b5e99',
|
||||||
|
'margin-top': '1px',
|
||||||
|
});
|
||||||
|
exact = $('<button class="toggleSearch">Exact</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css(toggleCSS)
|
||||||
|
.css(fontBold)
|
||||||
|
.attr('highlighted', 'true');
|
||||||
|
fuzzy = $('<button class="toggleSearch">Fuzzy</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css(toggleCSS);
|
||||||
|
input.css({
|
||||||
|
'padding-right': '30px',
|
||||||
|
});
|
||||||
|
$(input.parent()).css('right', '-33px').css('position', 'relative');
|
||||||
|
label = $('<div>Search Type<div>').css({
|
||||||
|
'padding-bottom': '0.5em',
|
||||||
|
'font-size': '0.8em',
|
||||||
|
});
|
||||||
|
tooltip = $('<div class="fuzzyToolTip"></div>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: '2em',
|
||||||
|
background: 'white',
|
||||||
|
'border-radius': '4px',
|
||||||
|
'text-align': 'center',
|
||||||
|
padding: '0.5em',
|
||||||
|
'background-color': '#16232a',
|
||||||
|
'box-shadow': '4px 4px 4px rgba(0, 0, 0, 0.5)',
|
||||||
|
color: 'white',
|
||||||
|
transition: 'opacity 0.25s',
|
||||||
|
'z-index': '30001',
|
||||||
|
width: input.outerWidth() - 3,
|
||||||
|
})
|
||||||
|
.append(label)
|
||||||
|
.append(exact)
|
||||||
|
.append(fuzzy);
|
||||||
|
}
|
||||||
|
function toggleFuzzy(event) {
|
||||||
|
if (toggle.attr('blurred')) {
|
||||||
|
toggle.css({ filter: 'blur(0px)' }).removeAttr('blurred');
|
||||||
|
fuzzy.removeAttr('highlighted').css(fontNormal);
|
||||||
|
exact.attr('highlighted', true).css(fontBold);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// Only going to set the toggle if it is enabled
|
toggle.css({ filter: 'blur(1px)' }).attr('blurred', true);
|
||||||
var toggle, tooltip, exact, fuzzy, label;
|
exact.removeAttr('highlighted').css(fontNormal);
|
||||||
if(initialFuzzy.toggleSmart) {
|
fuzzy.attr('highlighted', true).css(fontBold);
|
||||||
toggle =$('<button class="toggleSearch">Abc</button>')
|
|
||||||
.insertAfter(input)
|
|
||||||
.css({
|
|
||||||
'border': 'none',
|
|
||||||
'background': 'none',
|
|
||||||
'position': 'relative',
|
|
||||||
'right': '33px',
|
|
||||||
'top': '0px',
|
|
||||||
'cursor': 'pointer',
|
|
||||||
'color': '#3b5e99',
|
|
||||||
'margin-top': '1px'
|
|
||||||
});
|
|
||||||
exact =$('<button class="toggleSearch">Exact</button>')
|
|
||||||
.insertAfter(input)
|
|
||||||
.css(toggleCSS)
|
|
||||||
.css(fontBold)
|
|
||||||
.attr('highlighted', true);
|
|
||||||
fuzzy =$('<button class="toggleSearch">Fuzzy</button>')
|
|
||||||
.insertAfter(input)
|
|
||||||
.css(toggleCSS);
|
|
||||||
input.css({
|
|
||||||
'padding-right': '30px'
|
|
||||||
});
|
|
||||||
$(input.parent()).css('right', '-33px').css('position', 'relative');
|
|
||||||
label = $('<div>Search Type<div>').css({'padding-bottom': '0.5em', 'font-size': '0.8em'})
|
|
||||||
tooltip = $('<div class="fuzzyToolTip"></div>')
|
|
||||||
.css({
|
|
||||||
'position': 'absolute',
|
|
||||||
'top': '2em',
|
|
||||||
'background': 'white',
|
|
||||||
'border-radius': '4px',
|
|
||||||
'text-align': 'center',
|
|
||||||
'padding': '0.5em',
|
|
||||||
'background-color': '#16232a',
|
|
||||||
'box-shadow': '4px 4px 4px rgba(0, 0, 0, 0.5)',
|
|
||||||
'color': 'white',
|
|
||||||
'transition': 'opacity 0.25s',
|
|
||||||
'z-index': '30001',
|
|
||||||
'width': input.outerWidth() - 3,
|
|
||||||
})
|
|
||||||
.append(label).append(exact).append(fuzzy);
|
|
||||||
}
|
}
|
||||||
|
// Whenever the search mode is changed we need to re-search
|
||||||
function toggleFuzzy(event) {
|
triggerSearchFunction(event);
|
||||||
if(toggle.attr('blurred')) {
|
}
|
||||||
toggle.css({'filter': 'blur(0px)'}).removeAttr('blurred');
|
// Turn off the default datatables searching events
|
||||||
fuzzy.removeAttr('highlighted').css(fontNormal);
|
$(settings.nTable).off('search.dt.DT');
|
||||||
exact.attr('highlighted', true).css(fontBold);
|
var fuzzySearchVal = '';
|
||||||
|
var searchVal = '';
|
||||||
|
// The function that we want to run on search
|
||||||
|
var triggerSearchFunction = function (event) {
|
||||||
|
// If the search is only to be triggered on return wait for that
|
||||||
|
if ((event.type === 'input' &&
|
||||||
|
(initial.search === undefined || !initial.search.return)) ||
|
||||||
|
event.key === 'Enter' ||
|
||||||
|
event.type === 'click') {
|
||||||
|
// If the toggle is set and isn't checkd then perform a normal search
|
||||||
|
if (toggle && !toggle.attr('blurred')) {
|
||||||
|
api.rows().iterator('row', function (settings, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = undefined;
|
||||||
|
}, false);
|
||||||
|
searchVal = input.val();
|
||||||
|
fuzzySearchVal = searchVal;
|
||||||
|
fromPlugin = true;
|
||||||
|
api.search(searchVal);
|
||||||
|
fromPlugin = false;
|
||||||
|
searchVal = '';
|
||||||
}
|
}
|
||||||
|
// Otherwise perform a fuzzy search
|
||||||
else {
|
else {
|
||||||
toggle.css({'filter': 'blur(1px)'}).attr('blurred', true);
|
// Get the value from the input element and convert to lower case
|
||||||
exact.removeAttr('highlighted').css(fontNormal);
|
fuzzySearchVal = input.val();
|
||||||
fuzzy.attr('highlighted', true).css(fontBold);
|
searchVal = '';
|
||||||
}
|
if (fuzzySearchVal !== undefined && fuzzySearchVal.length !== 0) {
|
||||||
|
fuzzySearchVal = fuzzySearchVal.toLowerCase();
|
||||||
// Whenever the search mode is changed we need to re-search
|
|
||||||
triggerSearchFunction(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn off the default datatables searching events
|
|
||||||
$(settings.nTable).off('search.dt.DT');
|
|
||||||
|
|
||||||
var fuzzySearchVal = '';
|
|
||||||
var searchVal = '';
|
|
||||||
// The function that we want to run on search
|
|
||||||
var triggerSearchFunction = function(event){
|
|
||||||
// If the search is only to be triggered on return wait for that
|
|
||||||
if ((event.type === 'input' && (initial.search === undefined || !initial.search.return)) || event.key === "Enter" || event.type === 'click') {
|
|
||||||
// If the toggle is set and isn't checkd then perform a normal search
|
|
||||||
if(toggle && !toggle.attr('blurred')) {
|
|
||||||
api.rows().iterator('row', function(settings, rowIdx) {
|
|
||||||
settings.aoData[rowIdx]._fuzzySearch = undefined;
|
|
||||||
})
|
|
||||||
searchVal = input.val();
|
|
||||||
fuzzySearchVal = searchVal;
|
|
||||||
fromPlugin = true;
|
|
||||||
api.search(searchVal);
|
|
||||||
fromPlugin = false;
|
|
||||||
searchVal = "";
|
|
||||||
}
|
}
|
||||||
// Otherwise perform a fuzzy search
|
// For each row call the fuzzy search function to get result
|
||||||
else {
|
api.rows().iterator('row', function (settings, rowIdx) {
|
||||||
// Get the value from the input element and convert to lower case
|
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy);
|
||||||
fuzzySearchVal = input.val();
|
}, false);
|
||||||
searchVal = "";
|
|
||||||
|
|
||||||
if (fuzzySearchVal !== undefined && fuzzySearchVal.length !== 0) {
|
|
||||||
fuzzySearchVal = fuzzySearchVal.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
// For each row call the fuzzy search function to get result
|
|
||||||
api.rows().iterator('row', function(settings, rowIdx) {
|
|
||||||
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy)
|
|
||||||
});
|
|
||||||
|
|
||||||
fromPlugin = true;
|
|
||||||
// Empty the datatables search and replace it with our own
|
|
||||||
api.search("");
|
|
||||||
input.val(fuzzySearchVal);
|
|
||||||
fromPlugin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fromPlugin = true;
|
fromPlugin = true;
|
||||||
api.draw();
|
// Empty the datatables search and replace it with our own
|
||||||
|
api.search('');
|
||||||
|
input.val(fuzzySearchVal);
|
||||||
fromPlugin = false;
|
fromPlugin = false;
|
||||||
}
|
}
|
||||||
|
fromPlugin = true;
|
||||||
|
api.draw();
|
||||||
|
fromPlugin = false;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
var apiRegister = $.fn.dataTable.Api.register;
|
var apiRegister = DataTable.Api.register;
|
||||||
apiRegister('search.fuzzy()', function(value) {
|
apiRegister('search.fuzzy()', function (value) {
|
||||||
if(value === undefined) {
|
if (value === undefined) {
|
||||||
return fuzzySearchVal;
|
return fuzzySearchVal;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fuzzySearchVal = value.toLowerCase();
|
fuzzySearchVal = value.toLowerCase();
|
||||||
searchVal = api.search();
|
searchVal = api.search();
|
||||||
input.val(fuzzySearchVal);
|
input.val(fuzzySearchVal);
|
||||||
|
// For each row call the fuzzy search function to get result
|
||||||
// For each row call the fuzzy search function to get result
|
api.rows().iterator('row', function (settings, rowIdx) {
|
||||||
api.rows().iterator('row', function(settings, rowIdx) {
|
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy);
|
||||||
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy)
|
}, false);
|
||||||
});
|
// triggerSearchFunction({key: 'Enter'});
|
||||||
// triggerSearchFunction({key: 'Enter'});
|
return this;
|
||||||
return this;
|
}
|
||||||
|
});
|
||||||
|
input.off();
|
||||||
|
// Set listeners to occur on toggle and typing
|
||||||
|
if (toggle) {
|
||||||
|
// Highlights one of the buttons in the tooltip and un-highlights the other
|
||||||
|
function highlightButton(toHighlight, event) {
|
||||||
|
if (!toHighlight.attr('highlighted')) {
|
||||||
|
toggleFuzzy(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Removes the tooltip element
|
||||||
|
function removeToolTip() {
|
||||||
|
tooltip.remove();
|
||||||
|
}
|
||||||
|
// Actions for the toggle button
|
||||||
|
toggle
|
||||||
|
.on('click', toggleFuzzy)
|
||||||
|
.on('mouseenter', function () {
|
||||||
|
tooltip.insertAfter(toggle).on('mouseleave', removeToolTip);
|
||||||
|
tooltip.css('left', input.position().left + 3);
|
||||||
|
exact.on('click', event => highlightButton(exact, event));
|
||||||
|
fuzzy.on('click', event => highlightButton(fuzzy, event));
|
||||||
})
|
})
|
||||||
|
.on('mouseleave', removeToolTip);
|
||||||
input.off();
|
// Actions for the input element
|
||||||
// Set listeners to occur on toggle and typing
|
input
|
||||||
if(toggle) {
|
.on('mouseenter', function () {
|
||||||
// Highlights one of the buttons in the tooltip and un-highlights the other
|
tooltip.insertAfter(toggle).on('mouseleave', removeToolTip);
|
||||||
function highlightButton(toHighlight, event) {
|
tooltip.css('left', input.position().left + 3);
|
||||||
if(!toHighlight.attr('highlighted')){
|
exact.on('click', event => highlightButton(exact, event));
|
||||||
toggleFuzzy(event)
|
fuzzy.on('click', event => highlightButton(fuzzy, event));
|
||||||
}
|
})
|
||||||
}
|
.on('mouseleave', function () {
|
||||||
|
var inToolTip = false;
|
||||||
// Removes the tooltip element
|
tooltip.on('mouseenter', () => (inToolTip = true));
|
||||||
function removeToolTip() {
|
toggle.on('mouseenter', () => (inToolTip = true));
|
||||||
tooltip.remove();
|
setTimeout(function () {
|
||||||
}
|
if (!inToolTip) {
|
||||||
|
removeToolTip();
|
||||||
// Actions for the toggle button
|
|
||||||
toggle
|
|
||||||
.on('click', toggleFuzzy)
|
|
||||||
.on('mouseenter', function() {
|
|
||||||
tooltip
|
|
||||||
.insertAfter(toggle)
|
|
||||||
.on('mouseleave', removeToolTip);
|
|
||||||
tooltip.css('left', input.position().left + 3)
|
|
||||||
exact.on('click', (event) => highlightButton(exact, event));
|
|
||||||
fuzzy.on('click', (event) => highlightButton(fuzzy, event));
|
|
||||||
})
|
|
||||||
.on('mouseleave', removeToolTip);
|
|
||||||
|
|
||||||
// Actions for the input element
|
|
||||||
input
|
|
||||||
.on('mouseenter', function() {
|
|
||||||
tooltip
|
|
||||||
.insertAfter(toggle)
|
|
||||||
.on('mouseleave', removeToolTip);
|
|
||||||
tooltip.css('left', input.position().left + 3)
|
|
||||||
exact.on('click', (event) => highlightButton(exact, event))
|
|
||||||
fuzzy.on('click', (event) => highlightButton(fuzzy, event))
|
|
||||||
})
|
|
||||||
.on('mouseleave', function() {
|
|
||||||
var inToolTip = false;
|
|
||||||
tooltip.on('mouseenter', () => inToolTip = true);
|
|
||||||
toggle.on('mouseenter', () => inToolTip = true);
|
|
||||||
setTimeout(function(){
|
|
||||||
if(!inToolTip) {
|
|
||||||
removeToolTip();
|
|
||||||
}
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
|
|
||||||
var state = api.state.loaded();
|
|
||||||
|
|
||||||
api.on('stateSaveParams', function(e, settings, data) {
|
|
||||||
data._fuzzySearch = {
|
|
||||||
active: toggle.attr('blurred'),
|
|
||||||
val: input.val()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (state !== null && state._fuzzySearch !== undefined) {
|
|
||||||
input.val(state._fuzzySearch.val);
|
|
||||||
|
|
||||||
if (state._fuzzySearch.active === 'true') {
|
|
||||||
toggle.click();
|
|
||||||
api.page(state.start/state.length).draw('page');
|
|
||||||
}
|
}
|
||||||
|
}, 250);
|
||||||
|
});
|
||||||
|
var state = api.state.loaded();
|
||||||
|
api.on('stateSaveParams', function (e, settings, data) {
|
||||||
|
data._fuzzySearch = {
|
||||||
|
active: toggle.attr('blurred'),
|
||||||
|
val: input.val(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
if (state !== null && state._fuzzySearch !== undefined) {
|
||||||
|
input.val(state._fuzzySearch.val);
|
||||||
|
if (state._fuzzySearch.active === 'true') {
|
||||||
|
toggle.click();
|
||||||
|
api.page(state.start / state.length).draw('page');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
api.on('search', function () {
|
||||||
|
if (!fromPlugin) {
|
||||||
|
input.val(api.search() !== searchVal ? api.search() : fuzzySearchVal);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Always add this event no matter if toggling is enabled
|
||||||
|
input.on('input keydown', triggerSearchFunction);
|
||||||
|
});
|
||||||
|
|
||||||
api.on('search', function(){
|
|
||||||
if(!fromPlugin) {
|
|
||||||
input.val(api.search() !== searchVal ? api.search() : fuzzySearchVal);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Always add this event no matter if toggling is enabled
|
return DataTable;
|
||||||
input.on('input keydown', triggerSearchFunction);
|
}));
|
||||||
})
|
|
||||||
}());
|
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,412 @@
|
|||||||
|
/*!
|
||||||
|
* Fuzzy Search for DataTables
|
||||||
|
* 2021 SpryMedia Ltd - datatables.net/license MIT license
|
||||||
|
*
|
||||||
|
* Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein
|
||||||
|
* BSD 2-Clause License
|
||||||
|
* Copyright (c) 2018, Tadeusz Łazurski
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
function levenshtein(__this, that, limit) {
|
||||||
|
var thisLength = __this.length, thatLength = that.length, matrix = [];
|
||||||
|
// If the limit is not defined it will be calculate from this and that args.
|
||||||
|
limit = (limit || (thatLength > thisLength ? thatLength : thisLength)) + 1;
|
||||||
|
for (var i = 0; i < limit; i++) {
|
||||||
|
matrix[i] = [i];
|
||||||
|
matrix[i].length = limit;
|
||||||
|
}
|
||||||
|
for (i = 0; i < limit; i++) {
|
||||||
|
matrix[0][i] = i;
|
||||||
|
}
|
||||||
|
if (Math.abs(thisLength - thatLength) > (limit || 100)) {
|
||||||
|
return prepare(limit || 100);
|
||||||
|
}
|
||||||
|
if (thisLength === 0) {
|
||||||
|
return prepare(thatLength);
|
||||||
|
}
|
||||||
|
if (thatLength === 0) {
|
||||||
|
return prepare(thisLength);
|
||||||
|
}
|
||||||
|
// Calculate matrix.
|
||||||
|
var j, this_i, that_j, cost, min, t;
|
||||||
|
for (i = 1; i <= thisLength; ++i) {
|
||||||
|
this_i = __this[i - 1];
|
||||||
|
// Step 4
|
||||||
|
for (j = 1; j <= thatLength; ++j) {
|
||||||
|
// Check the jagged ld total so far
|
||||||
|
if (i === j && matrix[i][j] > 4)
|
||||||
|
return prepare(thisLength);
|
||||||
|
that_j = that[j - 1];
|
||||||
|
cost = this_i === that_j ? 0 : 1; // Step 5
|
||||||
|
// Calculate the minimum (much faster than Math.min(...)).
|
||||||
|
min = matrix[i - 1][j] + 1; // Devarion.
|
||||||
|
if ((t = matrix[i][j - 1] + 1) < min)
|
||||||
|
min = t; // Insertion.
|
||||||
|
if ((t = matrix[i - 1][j - 1] + cost) < min)
|
||||||
|
min = t; // Substitution.
|
||||||
|
// Update matrix.
|
||||||
|
matrix[i][j] =
|
||||||
|
i > 1 &&
|
||||||
|
j > 1 &&
|
||||||
|
this_i === that[j - 2] &&
|
||||||
|
__this[i - 2] === that_j &&
|
||||||
|
(t = matrix[i - 2][j - 2] + cost) < min
|
||||||
|
? t
|
||||||
|
: min; // Transposition.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return prepare(matrix[thisLength][thatLength]);
|
||||||
|
function prepare(steps) {
|
||||||
|
var length = Math.max(thisLength, thatLength);
|
||||||
|
var relative = length === 0 ? 0 : steps / length;
|
||||||
|
var similarity = 1 - relative;
|
||||||
|
return {
|
||||||
|
steps: steps,
|
||||||
|
relative: relative,
|
||||||
|
similarity: similarity,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function fuzzySearch(searchVal, data, initial) {
|
||||||
|
// If no searchVal has been defined then return all rows.
|
||||||
|
if (searchVal === undefined || searchVal.length === 0) {
|
||||||
|
return {
|
||||||
|
pass: true,
|
||||||
|
score: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var threshold = initial.threshold !== undefined ? initial.threshold : 0.5;
|
||||||
|
// Split the searchVal into individual words.
|
||||||
|
var splitSearch = searchVal.split(/ /g);
|
||||||
|
// Array to keep scores in
|
||||||
|
var highestCollated = [];
|
||||||
|
// Remove any empty words or spaces
|
||||||
|
for (var x = 0; x < splitSearch.length; x++) {
|
||||||
|
if (splitSearch[x].length === 0 || splitSearch[x] === ' ') {
|
||||||
|
splitSearch.splice(x, 1);
|
||||||
|
x--;
|
||||||
|
}
|
||||||
|
// Aside - Add to the score collection if not done so yet for this search word
|
||||||
|
else if (highestCollated.length < splitSearch.length) {
|
||||||
|
highestCollated.push({ pass: false, score: 0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Going to check each cell for potential matches
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
// Convert all data points to lower case fo insensitive sorting
|
||||||
|
data[i] = data[i].toLowerCase();
|
||||||
|
// Split the data into individual words
|
||||||
|
var splitData = data[i].split(/ /g);
|
||||||
|
// Remove any empty words or spaces
|
||||||
|
for (var y = 0; y < splitData.length; y++) {
|
||||||
|
if (splitData[y].length === 0 || splitData[y] === ' ') {
|
||||||
|
splitData.splice(y, 1);
|
||||||
|
x--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check each search term word
|
||||||
|
for (var x = 0; x < splitSearch.length; x++) {
|
||||||
|
// Reset highest score
|
||||||
|
var highest = {
|
||||||
|
pass: undefined,
|
||||||
|
score: 0,
|
||||||
|
};
|
||||||
|
// Against each word in the cell
|
||||||
|
for (var y = 0; y < splitData.length; y++) {
|
||||||
|
// If this search Term word is the beginning of the word in the cell we want to pass this word
|
||||||
|
if (splitData[y].indexOf(splitSearch[x]) === 0) {
|
||||||
|
var newScore = splitSearch[x].length / splitData[y].length;
|
||||||
|
highest = {
|
||||||
|
pass: true,
|
||||||
|
score: highest.score < newScore ? newScore : highest.score,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Get the levenshtein similarity score for the two words
|
||||||
|
var steps = levenshtein(splitSearch[x], splitData[y]).similarity;
|
||||||
|
// If the levenshtein similarity score is better than a previous one for the search word then var's store it
|
||||||
|
if (steps > highest.score) {
|
||||||
|
highest.score = steps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If this cell has a higher scoring word than previously found to the search term in the row, store it
|
||||||
|
if (highestCollated[x].score < highest.score || highest.pass) {
|
||||||
|
highestCollated[x] = {
|
||||||
|
pass: highest.pass || highestCollated[x].pass
|
||||||
|
? true
|
||||||
|
: highest.score > threshold,
|
||||||
|
score: highest.score,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check that all of the search words have passed
|
||||||
|
for (var i = 0; i < highestCollated.length; i++) {
|
||||||
|
if (!highestCollated[i].pass) {
|
||||||
|
return {
|
||||||
|
pass: false,
|
||||||
|
score: Math.round((highestCollated.reduce((a, b) => a + b.score, 0) /
|
||||||
|
highestCollated.length) *
|
||||||
|
100) + '%',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If we get to here, all scores greater than 0.5 so display the row
|
||||||
|
return {
|
||||||
|
pass: true,
|
||||||
|
score: Math.round((highestCollated.reduce((a, b) => a + b.score, 0) /
|
||||||
|
highestCollated.length) *
|
||||||
|
100) + '%',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
DataTable.ext.search.push(function (settings, data, dataIndex) {
|
||||||
|
var initial = settings.oInit.fuzzySearch;
|
||||||
|
if (!initial) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If fuzzy searching has not been implemented then pass all rows for this function
|
||||||
|
if (settings.aoData[dataIndex]._fuzzySearch !== undefined) {
|
||||||
|
// Read score to set the cell content and sort data
|
||||||
|
var score = settings.aoData[dataIndex]._fuzzySearch.score;
|
||||||
|
if (initial.rankColumn !== undefined) {
|
||||||
|
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = score;
|
||||||
|
// Remove '%' from the end of the score so can sort on a number
|
||||||
|
settings.aoData[dataIndex]._aSortData[initial.rankColumn] =
|
||||||
|
+score.substring(0, score.length - 1);
|
||||||
|
}
|
||||||
|
// Return the value for the pass as decided by the fuzzySearch function
|
||||||
|
return settings.aoData[dataIndex]._fuzzySearch.pass;
|
||||||
|
}
|
||||||
|
else if (initial.rankColumn !== undefined) {
|
||||||
|
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = '';
|
||||||
|
settings.aoData[dataIndex]._aSortData[initial.rankColumn] = '';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
var initial = api.init();
|
||||||
|
var initialFuzzy = initial.fuzzySearch;
|
||||||
|
// If this is not set then fuzzy searching is not enabled on the table so return.
|
||||||
|
if (!initialFuzzy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var fromPlugin = false;
|
||||||
|
// Find the input element
|
||||||
|
var input = $('div.dataTables_filter input', api.table().container());
|
||||||
|
var fontBold = {
|
||||||
|
'font-weight': '600',
|
||||||
|
'background-color': 'rgba(255,255,255,0.1)',
|
||||||
|
};
|
||||||
|
var fontNormal = {
|
||||||
|
'font-weight': '500',
|
||||||
|
'background-color': 'transparent',
|
||||||
|
};
|
||||||
|
var toggleCSS = {
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
'font-size': '100%',
|
||||||
|
width: '50%',
|
||||||
|
display: 'inline-block',
|
||||||
|
color: 'white',
|
||||||
|
cursor: 'pointer',
|
||||||
|
padding: '0.5em',
|
||||||
|
};
|
||||||
|
// Only going to set the toggle if it is enabled
|
||||||
|
var toggle, tooltip, exact, fuzzy, label;
|
||||||
|
if (typeof initialFuzzy === 'object' && initialFuzzy.toggleSmart) {
|
||||||
|
toggle = $('<button class="toggleSearch">Abc</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css({
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
position: 'relative',
|
||||||
|
right: '33px',
|
||||||
|
top: '0px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
color: '#3b5e99',
|
||||||
|
'margin-top': '1px',
|
||||||
|
});
|
||||||
|
exact = $('<button class="toggleSearch">Exact</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css(toggleCSS)
|
||||||
|
.css(fontBold)
|
||||||
|
.attr('highlighted', 'true');
|
||||||
|
fuzzy = $('<button class="toggleSearch">Fuzzy</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css(toggleCSS);
|
||||||
|
input.css({
|
||||||
|
'padding-right': '30px',
|
||||||
|
});
|
||||||
|
$(input.parent()).css('right', '-33px').css('position', 'relative');
|
||||||
|
label = $('<div>Search Type<div>').css({
|
||||||
|
'padding-bottom': '0.5em',
|
||||||
|
'font-size': '0.8em',
|
||||||
|
});
|
||||||
|
tooltip = $('<div class="fuzzyToolTip"></div>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: '2em',
|
||||||
|
background: 'white',
|
||||||
|
'border-radius': '4px',
|
||||||
|
'text-align': 'center',
|
||||||
|
padding: '0.5em',
|
||||||
|
'background-color': '#16232a',
|
||||||
|
'box-shadow': '4px 4px 4px rgba(0, 0, 0, 0.5)',
|
||||||
|
color: 'white',
|
||||||
|
transition: 'opacity 0.25s',
|
||||||
|
'z-index': '30001',
|
||||||
|
width: input.outerWidth() - 3,
|
||||||
|
})
|
||||||
|
.append(label)
|
||||||
|
.append(exact)
|
||||||
|
.append(fuzzy);
|
||||||
|
}
|
||||||
|
function toggleFuzzy(event) {
|
||||||
|
if (toggle.attr('blurred')) {
|
||||||
|
toggle.css({ filter: 'blur(0px)' }).removeAttr('blurred');
|
||||||
|
fuzzy.removeAttr('highlighted').css(fontNormal);
|
||||||
|
exact.attr('highlighted', true).css(fontBold);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toggle.css({ filter: 'blur(1px)' }).attr('blurred', true);
|
||||||
|
exact.removeAttr('highlighted').css(fontNormal);
|
||||||
|
fuzzy.attr('highlighted', true).css(fontBold);
|
||||||
|
}
|
||||||
|
// Whenever the search mode is changed we need to re-search
|
||||||
|
triggerSearchFunction(event);
|
||||||
|
}
|
||||||
|
// Turn off the default datatables searching events
|
||||||
|
$(settings.nTable).off('search.dt.DT');
|
||||||
|
var fuzzySearchVal = '';
|
||||||
|
var searchVal = '';
|
||||||
|
// The function that we want to run on search
|
||||||
|
var triggerSearchFunction = function (event) {
|
||||||
|
// If the search is only to be triggered on return wait for that
|
||||||
|
if ((event.type === 'input' &&
|
||||||
|
(initial.search === undefined || !initial.search.return)) ||
|
||||||
|
event.key === 'Enter' ||
|
||||||
|
event.type === 'click') {
|
||||||
|
// If the toggle is set and isn't checkd then perform a normal search
|
||||||
|
if (toggle && !toggle.attr('blurred')) {
|
||||||
|
api.rows().iterator('row', function (settings, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = undefined;
|
||||||
|
}, false);
|
||||||
|
searchVal = input.val();
|
||||||
|
fuzzySearchVal = searchVal;
|
||||||
|
fromPlugin = true;
|
||||||
|
api.search(searchVal);
|
||||||
|
fromPlugin = false;
|
||||||
|
searchVal = '';
|
||||||
|
}
|
||||||
|
// Otherwise perform a fuzzy search
|
||||||
|
else {
|
||||||
|
// Get the value from the input element and convert to lower case
|
||||||
|
fuzzySearchVal = input.val();
|
||||||
|
searchVal = '';
|
||||||
|
if (fuzzySearchVal !== undefined && fuzzySearchVal.length !== 0) {
|
||||||
|
fuzzySearchVal = fuzzySearchVal.toLowerCase();
|
||||||
|
}
|
||||||
|
// For each row call the fuzzy search function to get result
|
||||||
|
api.rows().iterator('row', function (settings, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy);
|
||||||
|
}, false);
|
||||||
|
fromPlugin = true;
|
||||||
|
// Empty the datatables search and replace it with our own
|
||||||
|
api.search('');
|
||||||
|
input.val(fuzzySearchVal);
|
||||||
|
fromPlugin = false;
|
||||||
|
}
|
||||||
|
fromPlugin = true;
|
||||||
|
api.draw();
|
||||||
|
fromPlugin = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var apiRegister = DataTable.Api.register;
|
||||||
|
apiRegister('search.fuzzy()', function (value) {
|
||||||
|
if (value === undefined) {
|
||||||
|
return fuzzySearchVal;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fuzzySearchVal = value.toLowerCase();
|
||||||
|
searchVal = api.search();
|
||||||
|
input.val(fuzzySearchVal);
|
||||||
|
// For each row call the fuzzy search function to get result
|
||||||
|
api.rows().iterator('row', function (settings, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy);
|
||||||
|
}, false);
|
||||||
|
// triggerSearchFunction({key: 'Enter'});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.off();
|
||||||
|
// Set listeners to occur on toggle and typing
|
||||||
|
if (toggle) {
|
||||||
|
// Highlights one of the buttons in the tooltip and un-highlights the other
|
||||||
|
function highlightButton(toHighlight, event) {
|
||||||
|
if (!toHighlight.attr('highlighted')) {
|
||||||
|
toggleFuzzy(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Removes the tooltip element
|
||||||
|
function removeToolTip() {
|
||||||
|
tooltip.remove();
|
||||||
|
}
|
||||||
|
// Actions for the toggle button
|
||||||
|
toggle
|
||||||
|
.on('click', toggleFuzzy)
|
||||||
|
.on('mouseenter', function () {
|
||||||
|
tooltip.insertAfter(toggle).on('mouseleave', removeToolTip);
|
||||||
|
tooltip.css('left', input.position().left + 3);
|
||||||
|
exact.on('click', event => highlightButton(exact, event));
|
||||||
|
fuzzy.on('click', event => highlightButton(fuzzy, event));
|
||||||
|
})
|
||||||
|
.on('mouseleave', removeToolTip);
|
||||||
|
// Actions for the input element
|
||||||
|
input
|
||||||
|
.on('mouseenter', function () {
|
||||||
|
tooltip.insertAfter(toggle).on('mouseleave', removeToolTip);
|
||||||
|
tooltip.css('left', input.position().left + 3);
|
||||||
|
exact.on('click', event => highlightButton(exact, event));
|
||||||
|
fuzzy.on('click', event => highlightButton(fuzzy, event));
|
||||||
|
})
|
||||||
|
.on('mouseleave', function () {
|
||||||
|
var inToolTip = false;
|
||||||
|
tooltip.on('mouseenter', () => (inToolTip = true));
|
||||||
|
toggle.on('mouseenter', () => (inToolTip = true));
|
||||||
|
setTimeout(function () {
|
||||||
|
if (!inToolTip) {
|
||||||
|
removeToolTip();
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
});
|
||||||
|
var state = api.state.loaded();
|
||||||
|
api.on('stateSaveParams', function (e, settings, data) {
|
||||||
|
data._fuzzySearch = {
|
||||||
|
active: toggle.attr('blurred'),
|
||||||
|
val: input.val(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
if (state !== null && state._fuzzySearch !== undefined) {
|
||||||
|
input.val(state._fuzzySearch.val);
|
||||||
|
if (state._fuzzySearch.active === 'true') {
|
||||||
|
toggle.click();
|
||||||
|
api.page(state.start / state.length).draw('page');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
api.on('search', function () {
|
||||||
|
if (!fromPlugin) {
|
||||||
|
input.val(api.search() !== searchVal ? api.search() : fuzzySearchVal);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Always add this event no matter if toggling is enabled
|
||||||
|
input.on('input keydown', triggerSearchFunction);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,512 @@
|
|||||||
|
/*!
|
||||||
|
* Fuzzy Search for DataTables
|
||||||
|
* 2021 SpryMedia Ltd - datatables.net/license MIT license
|
||||||
|
*
|
||||||
|
* Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein
|
||||||
|
* BSD 2-Clause License
|
||||||
|
* Copyright (c) 2018, Tadeusz Łazurski
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
fuzzySearch?:
|
||||||
|
| boolean
|
||||||
|
| {
|
||||||
|
rankColumn?: number;
|
||||||
|
threshold?: number;
|
||||||
|
toggleSmart?: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
_fuzzySearch: {
|
||||||
|
active: 'true' | 'false';
|
||||||
|
val: any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function levenshtein(__this, that, limit?) {
|
||||||
|
var thisLength = __this.length,
|
||||||
|
thatLength = that.length,
|
||||||
|
matrix: any[] = [];
|
||||||
|
|
||||||
|
// If the limit is not defined it will be calculate from this and that args.
|
||||||
|
limit = (limit || (thatLength > thisLength ? thatLength : thisLength)) + 1;
|
||||||
|
|
||||||
|
for (var i = 0; i < limit; i++) {
|
||||||
|
matrix[i] = [i];
|
||||||
|
matrix[i].length = limit;
|
||||||
|
}
|
||||||
|
for (i = 0; i < limit; i++) {
|
||||||
|
matrix[0][i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.abs(thisLength - thatLength) > (limit || 100)) {
|
||||||
|
return prepare(limit || 100);
|
||||||
|
}
|
||||||
|
if (thisLength === 0) {
|
||||||
|
return prepare(thatLength);
|
||||||
|
}
|
||||||
|
if (thatLength === 0) {
|
||||||
|
return prepare(thisLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate matrix.
|
||||||
|
var j, this_i, that_j, cost, min, t;
|
||||||
|
for (i = 1; i <= thisLength; ++i) {
|
||||||
|
this_i = __this[i - 1];
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
for (j = 1; j <= thatLength; ++j) {
|
||||||
|
// Check the jagged ld total so far
|
||||||
|
if (i === j && matrix[i][j] > 4) return prepare(thisLength);
|
||||||
|
|
||||||
|
that_j = that[j - 1];
|
||||||
|
cost = this_i === that_j ? 0 : 1; // Step 5
|
||||||
|
// Calculate the minimum (much faster than Math.min(...)).
|
||||||
|
min = matrix[i - 1][j] + 1; // Devarion.
|
||||||
|
if ((t = matrix[i][j - 1] + 1) < min) min = t; // Insertion.
|
||||||
|
if ((t = matrix[i - 1][j - 1] + cost) < min) min = t; // Substitution.
|
||||||
|
|
||||||
|
// Update matrix.
|
||||||
|
matrix[i][j] =
|
||||||
|
i > 1 &&
|
||||||
|
j > 1 &&
|
||||||
|
this_i === that[j - 2] &&
|
||||||
|
__this[i - 2] === that_j &&
|
||||||
|
(t = matrix[i - 2][j - 2] + cost) < min
|
||||||
|
? t
|
||||||
|
: min; // Transposition.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prepare(matrix[thisLength][thatLength]);
|
||||||
|
|
||||||
|
function prepare(steps) {
|
||||||
|
var length = Math.max(thisLength, thatLength);
|
||||||
|
var relative = length === 0 ? 0 : steps / length;
|
||||||
|
var similarity = 1 - relative;
|
||||||
|
return {
|
||||||
|
steps: steps,
|
||||||
|
relative: relative,
|
||||||
|
similarity: similarity,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fuzzySearch(searchVal, data, initial) {
|
||||||
|
// If no searchVal has been defined then return all rows.
|
||||||
|
if (searchVal === undefined || searchVal.length === 0) {
|
||||||
|
return {
|
||||||
|
pass: true,
|
||||||
|
score: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var threshold = initial.threshold !== undefined ? initial.threshold : 0.5;
|
||||||
|
|
||||||
|
// Split the searchVal into individual words.
|
||||||
|
var splitSearch = searchVal.split(/ /g);
|
||||||
|
|
||||||
|
// Array to keep scores in
|
||||||
|
var highestCollated: { pass: boolean; score: number }[] = [];
|
||||||
|
|
||||||
|
// Remove any empty words or spaces
|
||||||
|
for (var x = 0; x < splitSearch.length; x++) {
|
||||||
|
if (splitSearch[x].length === 0 || splitSearch[x] === ' ') {
|
||||||
|
splitSearch.splice(x, 1);
|
||||||
|
x--;
|
||||||
|
}
|
||||||
|
// Aside - Add to the score collection if not done so yet for this search word
|
||||||
|
else if (highestCollated.length < splitSearch.length) {
|
||||||
|
highestCollated.push({ pass: false, score: 0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Going to check each cell for potential matches
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
// Convert all data points to lower case fo insensitive sorting
|
||||||
|
data[i] = data[i].toLowerCase();
|
||||||
|
|
||||||
|
// Split the data into individual words
|
||||||
|
var splitData = data[i].split(/ /g);
|
||||||
|
|
||||||
|
// Remove any empty words or spaces
|
||||||
|
for (var y = 0; y < splitData.length; y++) {
|
||||||
|
if (splitData[y].length === 0 || splitData[y] === ' ') {
|
||||||
|
splitData.splice(y, 1);
|
||||||
|
x--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check each search term word
|
||||||
|
for (var x = 0; x < splitSearch.length; x++) {
|
||||||
|
// Reset highest score
|
||||||
|
var highest: { pass?: boolean; score: number } = {
|
||||||
|
pass: undefined,
|
||||||
|
score: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Against each word in the cell
|
||||||
|
for (var y = 0; y < splitData.length; y++) {
|
||||||
|
// If this search Term word is the beginning of the word in the cell we want to pass this word
|
||||||
|
if (splitData[y].indexOf(splitSearch[x]) === 0) {
|
||||||
|
var newScore = splitSearch[x].length / splitData[y].length;
|
||||||
|
highest = {
|
||||||
|
pass: true,
|
||||||
|
score: highest.score < newScore ? newScore : highest.score,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the levenshtein similarity score for the two words
|
||||||
|
var steps = levenshtein(splitSearch[x], splitData[y]).similarity;
|
||||||
|
|
||||||
|
// If the levenshtein similarity score is better than a previous one for the search word then var's store it
|
||||||
|
if (steps > highest.score) {
|
||||||
|
highest.score = steps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this cell has a higher scoring word than previously found to the search term in the row, store it
|
||||||
|
if (highestCollated[x].score < highest.score || highest.pass) {
|
||||||
|
highestCollated[x] = {
|
||||||
|
pass:
|
||||||
|
highest.pass || highestCollated[x].pass
|
||||||
|
? true
|
||||||
|
: highest.score > threshold,
|
||||||
|
score: highest.score,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that all of the search words have passed
|
||||||
|
for (var i = 0; i < highestCollated.length; i++) {
|
||||||
|
if (!highestCollated[i].pass) {
|
||||||
|
return {
|
||||||
|
pass: false,
|
||||||
|
score:
|
||||||
|
Math.round(
|
||||||
|
(highestCollated.reduce((a, b) => a + b.score, 0) /
|
||||||
|
highestCollated.length) *
|
||||||
|
100
|
||||||
|
) + '%',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we get to here, all scores greater than 0.5 so display the row
|
||||||
|
return {
|
||||||
|
pass: true,
|
||||||
|
score:
|
||||||
|
Math.round(
|
||||||
|
(highestCollated.reduce((a, b) => a + b.score, 0) /
|
||||||
|
highestCollated.length) *
|
||||||
|
100
|
||||||
|
) + '%',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.ext.search.push(function (settings, data, dataIndex) {
|
||||||
|
var initial = settings.oInit.fuzzySearch;
|
||||||
|
|
||||||
|
if (!initial) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If fuzzy searching has not been implemented then pass all rows for this function
|
||||||
|
if (settings.aoData[dataIndex]._fuzzySearch !== undefined) {
|
||||||
|
// Read score to set the cell content and sort data
|
||||||
|
var score = settings.aoData[dataIndex]._fuzzySearch.score;
|
||||||
|
|
||||||
|
if (initial.rankColumn !== undefined) {
|
||||||
|
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = score;
|
||||||
|
|
||||||
|
// Remove '%' from the end of the score so can sort on a number
|
||||||
|
settings.aoData[dataIndex]._aSortData[initial.rankColumn] =
|
||||||
|
+score.substring(0, score.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the value for the pass as decided by the fuzzySearch function
|
||||||
|
return settings.aoData[dataIndex]._fuzzySearch.pass;
|
||||||
|
}
|
||||||
|
else if (initial.rankColumn !== undefined) {
|
||||||
|
settings.aoData[dataIndex].anCells[initial.rankColumn].innerHTML = '';
|
||||||
|
settings.aoData[dataIndex]._aSortData[initial.rankColumn] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
var initial = api.init();
|
||||||
|
var initialFuzzy = initial.fuzzySearch;
|
||||||
|
|
||||||
|
// If this is not set then fuzzy searching is not enabled on the table so return.
|
||||||
|
if (!initialFuzzy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fromPlugin = false;
|
||||||
|
|
||||||
|
// Find the input element
|
||||||
|
var input = $('div.dataTables_filter input', api.table().container());
|
||||||
|
|
||||||
|
var fontBold = {
|
||||||
|
'font-weight': '600',
|
||||||
|
'background-color': 'rgba(255,255,255,0.1)',
|
||||||
|
};
|
||||||
|
var fontNormal = {
|
||||||
|
'font-weight': '500',
|
||||||
|
'background-color': 'transparent',
|
||||||
|
};
|
||||||
|
var toggleCSS = {
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
'font-size': '100%',
|
||||||
|
width: '50%',
|
||||||
|
display: 'inline-block',
|
||||||
|
color: 'white',
|
||||||
|
cursor: 'pointer',
|
||||||
|
padding: '0.5em',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Only going to set the toggle if it is enabled
|
||||||
|
var toggle, tooltip, exact, fuzzy, label;
|
||||||
|
if (typeof initialFuzzy === 'object' && initialFuzzy.toggleSmart) {
|
||||||
|
toggle = $('<button class="toggleSearch">Abc</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css({
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
position: 'relative',
|
||||||
|
right: '33px',
|
||||||
|
top: '0px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
color: '#3b5e99',
|
||||||
|
'margin-top': '1px',
|
||||||
|
});
|
||||||
|
exact = $('<button class="toggleSearch">Exact</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css(toggleCSS)
|
||||||
|
.css(fontBold)
|
||||||
|
.attr('highlighted', 'true');
|
||||||
|
fuzzy = $('<button class="toggleSearch">Fuzzy</button>')
|
||||||
|
.insertAfter(input)
|
||||||
|
.css(toggleCSS);
|
||||||
|
input.css({
|
||||||
|
'padding-right': '30px',
|
||||||
|
});
|
||||||
|
$(input.parent()).css('right', '-33px').css('position', 'relative');
|
||||||
|
label = $('<div>Search Type<div>').css({
|
||||||
|
'padding-bottom': '0.5em',
|
||||||
|
'font-size': '0.8em',
|
||||||
|
});
|
||||||
|
tooltip = $('<div class="fuzzyToolTip"></div>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: '2em',
|
||||||
|
background: 'white',
|
||||||
|
'border-radius': '4px',
|
||||||
|
'text-align': 'center',
|
||||||
|
padding: '0.5em',
|
||||||
|
'background-color': '#16232a',
|
||||||
|
'box-shadow': '4px 4px 4px rgba(0, 0, 0, 0.5)',
|
||||||
|
color: 'white',
|
||||||
|
transition: 'opacity 0.25s',
|
||||||
|
'z-index': '30001',
|
||||||
|
width: input.outerWidth()! - 3,
|
||||||
|
})
|
||||||
|
.append(label)
|
||||||
|
.append(exact)
|
||||||
|
.append(fuzzy);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleFuzzy(event) {
|
||||||
|
if (toggle.attr('blurred')) {
|
||||||
|
toggle.css({ filter: 'blur(0px)' }).removeAttr('blurred');
|
||||||
|
fuzzy.removeAttr('highlighted').css(fontNormal);
|
||||||
|
exact.attr('highlighted', true).css(fontBold);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toggle.css({ filter: 'blur(1px)' }).attr('blurred', true);
|
||||||
|
exact.removeAttr('highlighted').css(fontNormal);
|
||||||
|
fuzzy.attr('highlighted', true).css(fontBold);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whenever the search mode is changed we need to re-search
|
||||||
|
triggerSearchFunction(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turn off the default datatables searching events
|
||||||
|
$(settings.nTable).off('search.dt.DT');
|
||||||
|
|
||||||
|
var fuzzySearchVal = '';
|
||||||
|
var searchVal = '';
|
||||||
|
// The function that we want to run on search
|
||||||
|
var triggerSearchFunction = function (event) {
|
||||||
|
// If the search is only to be triggered on return wait for that
|
||||||
|
if (
|
||||||
|
(event.type === 'input' &&
|
||||||
|
(initial.search === undefined || !(initial.search as any).return)) ||
|
||||||
|
event.key === 'Enter' ||
|
||||||
|
event.type === 'click'
|
||||||
|
) {
|
||||||
|
// If the toggle is set and isn't checkd then perform a normal search
|
||||||
|
if (toggle && !toggle.attr('blurred')) {
|
||||||
|
api.rows().iterator(
|
||||||
|
'row',
|
||||||
|
function (settings: any, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = undefined;
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
searchVal = input.val() as string;
|
||||||
|
fuzzySearchVal = searchVal;
|
||||||
|
fromPlugin = true;
|
||||||
|
api.search(searchVal);
|
||||||
|
fromPlugin = false;
|
||||||
|
searchVal = '';
|
||||||
|
}
|
||||||
|
// Otherwise perform a fuzzy search
|
||||||
|
else {
|
||||||
|
// Get the value from the input element and convert to lower case
|
||||||
|
fuzzySearchVal = input.val() as string;
|
||||||
|
searchVal = '';
|
||||||
|
|
||||||
|
if (fuzzySearchVal !== undefined && fuzzySearchVal.length !== 0) {
|
||||||
|
fuzzySearchVal = fuzzySearchVal.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each row call the fuzzy search function to get result
|
||||||
|
api.rows().iterator(
|
||||||
|
'row',
|
||||||
|
function (settings: any, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(
|
||||||
|
fuzzySearchVal,
|
||||||
|
settings.aoData[rowIdx]._aFilterData,
|
||||||
|
initialFuzzy
|
||||||
|
);
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
fromPlugin = true;
|
||||||
|
// Empty the datatables search and replace it with our own
|
||||||
|
api.search('');
|
||||||
|
input.val(fuzzySearchVal);
|
||||||
|
fromPlugin = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fromPlugin = true;
|
||||||
|
api.draw();
|
||||||
|
fromPlugin = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var apiRegister = DataTable.Api.register;
|
||||||
|
apiRegister('search.fuzzy()', function (value) {
|
||||||
|
if (value === undefined) {
|
||||||
|
return fuzzySearchVal;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fuzzySearchVal = value.toLowerCase();
|
||||||
|
searchVal = api.search();
|
||||||
|
input.val(fuzzySearchVal);
|
||||||
|
|
||||||
|
// For each row call the fuzzy search function to get result
|
||||||
|
api.rows().iterator(
|
||||||
|
'row',
|
||||||
|
function (settings: any, rowIdx) {
|
||||||
|
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(
|
||||||
|
fuzzySearchVal,
|
||||||
|
settings.aoData[rowIdx]._aFilterData,
|
||||||
|
initialFuzzy
|
||||||
|
);
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
// triggerSearchFunction({key: 'Enter'});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
input.off();
|
||||||
|
// Set listeners to occur on toggle and typing
|
||||||
|
if (toggle) {
|
||||||
|
// Highlights one of the buttons in the tooltip and un-highlights the other
|
||||||
|
function highlightButton(toHighlight, event) {
|
||||||
|
if (!toHighlight.attr('highlighted')) {
|
||||||
|
toggleFuzzy(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removes the tooltip element
|
||||||
|
function removeToolTip() {
|
||||||
|
tooltip.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions for the toggle button
|
||||||
|
toggle
|
||||||
|
.on('click', toggleFuzzy)
|
||||||
|
.on('mouseenter', function () {
|
||||||
|
tooltip.insertAfter(toggle).on('mouseleave', removeToolTip);
|
||||||
|
tooltip.css('left', input.position().left + 3);
|
||||||
|
exact.on('click', event => highlightButton(exact, event));
|
||||||
|
fuzzy.on('click', event => highlightButton(fuzzy, event));
|
||||||
|
})
|
||||||
|
.on('mouseleave', removeToolTip);
|
||||||
|
|
||||||
|
// Actions for the input element
|
||||||
|
input
|
||||||
|
.on('mouseenter', function () {
|
||||||
|
tooltip.insertAfter(toggle).on('mouseleave', removeToolTip);
|
||||||
|
tooltip.css('left', input.position().left + 3);
|
||||||
|
exact.on('click', event => highlightButton(exact, event));
|
||||||
|
fuzzy.on('click', event => highlightButton(fuzzy, event));
|
||||||
|
})
|
||||||
|
.on('mouseleave', function () {
|
||||||
|
var inToolTip = false;
|
||||||
|
tooltip.on('mouseenter', () => (inToolTip = true));
|
||||||
|
toggle.on('mouseenter', () => (inToolTip = true));
|
||||||
|
setTimeout(function () {
|
||||||
|
if (!inToolTip) {
|
||||||
|
removeToolTip();
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
});
|
||||||
|
|
||||||
|
var state = api.state.loaded();
|
||||||
|
|
||||||
|
api.on('stateSaveParams', function (e, settings, data) {
|
||||||
|
data._fuzzySearch = {
|
||||||
|
active: toggle.attr('blurred'),
|
||||||
|
val: input.val(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (state !== null && state._fuzzySearch !== undefined) {
|
||||||
|
input.val(state._fuzzySearch.val);
|
||||||
|
|
||||||
|
if (state._fuzzySearch.active === 'true') {
|
||||||
|
toggle.click();
|
||||||
|
api.page(state.start / state.length).draw('page');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api.on('search', function () {
|
||||||
|
if (!fromPlugin) {
|
||||||
|
input.val(api.search() !== searchVal ? api.search() : fuzzySearchVal);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always add this event no matter if toggling is enabled
|
||||||
|
input.on('input keydown', triggerSearchFunction);
|
||||||
|
});
|
@ -0,0 +1,8 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Page length control via links for DataTables */
|
||||||
|
LengthLinks(settings: any): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,4 +1,2 @@
|
|||||||
/*! Page length control via links for DataTables
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2014 SpryMedia Ltd - datatables.net/license
|
!function(t){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return t(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e=e||window,(n=n||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,n),t(n,0,e.document)}:t(jQuery,window,document)}(function(o,e,n,t){"use strict";var a=o.fn.dataTable;return a.LengthLinks=function(e){var r=new a.Api(e),n=r.settings()[0],i=o("<div></div>").addClass(n.oClasses.sLength),u=null;this.container=function(){return i[0]},i.on("click.dtll","a",function(e){e.preventDefault(),r.page.len(+o(this).data("length")).draw(!1)}),r.on("draw",function(){var t,a,e;r.page.len()!==u&&(e=n.aLengthMenu,t=2===e.length&&Array.isArray(e[0])?e[1]:e,a=2===e.length&&Array.isArray(e[0])?e[0]:e,e=o.map(a,function(e,n){return e==r.page.len()?'<a class="active" data-length="'+a[n]+'">'+t[n]+"</a>":'<a data-length="'+a[n]+'">'+t[n]+"</a>"}),i.html(n.oLanguage.sLengthMenu.replace("_MENU_",e.join(" | "))),u=r.page.len())}),r.on("destroy",function(){i.off("click.dtll","a")})},a.ext.feature.push({fnInit:function(e){return new a.LengthLinks(e).container()},cFeature:"L",sFeature:"LengthLinks"}),a});
|
||||||
*/
|
|
||||||
!function(u){u.fn.dataTable.LengthLinks=function(n){var i=new u.fn.dataTable.Api(n),a=i.settings()[0],l=u("<div></div>").addClass(a.oClasses.sLength),r=null;this.container=function(){return l[0]},l.on("click.dtll","a",function(n){n.preventDefault(),i.page.len(+u(this).data("length")).draw(!1)}),i.on("draw",function(){var e,t,n;i.page.len()!==r&&(n=a.aLengthMenu,e=2===n.length&&Array.isArray(n[0])?n[1]:n,t=2===n.length&&Array.isArray(n[0])?n[0]:n,n=u.map(t,function(n,a){return n==i.page.len()?'<a class="active" data-length="'+t[a]+'">'+e[a]+"</a>":'<a data-length="'+t[a]+'">'+e[a]+"</a>"}),l.html(a.oLanguage.sLengthMenu.replace("_MENU_",n.join(" | "))),r=i.page.len())}),i.on("destroy",function(){l.off("click.dtll","a")})},u.fn.dataTable.ext.feature.push({fnInit:function(n){return new u.fn.dataTable.LengthLinks(n).container()},cFeature:"L",sFeature:"LengthLinks"})}((window,document,jQuery));
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";DataTable.LengthLinks=function(a){var r=new DataTable.Api(a),e=r.settings()[0],l=$("<div></div>").addClass(e.oClasses.sLength),i=null;this.container=function(){return l[0]},l.on("click.dtll","a",function(a){a.preventDefault(),r.page.len(+$(this).data("length")).draw(!1)}),r.on("draw",function(){var t,n,a;r.page.len()!==i&&(a=e.aLengthMenu,t=2===a.length&&Array.isArray(a[0])?a[1]:a,n=2===a.length&&Array.isArray(a[0])?a[0]:a,a=$.map(n,function(a,e){return a==r.page.len()?'<a class="active" data-length="'+n[e]+'">'+t[e]+"</a>":'<a data-length="'+n[e]+'">'+t[e]+"</a>"}),l.html(e.oLanguage.sLengthMenu.replace("_MENU_",a.join(" | "))),i=r.page.len())}),r.on("destroy",function(){l.off("click.dtll","a")})},DataTable.ext.feature.push({fnInit:function(a){return new DataTable.LengthLinks(a).container()},cFeature:"L",sFeature:"LengthLinks"});export default DataTable;
|
@ -0,0 +1,75 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary LengthLinks
|
||||||
|
* @description Page length control via links for DataTables
|
||||||
|
* @version 1.2.0
|
||||||
|
* @author Allan Jardine
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables adds page length control links to the
|
||||||
|
* DataTable. The `dom` option can be used to insert the control using the `L`
|
||||||
|
* character option and it uses the `lengthMenu` options of DataTables to
|
||||||
|
* determine what to display.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable( {
|
||||||
|
* dom: 'Lfrtip'
|
||||||
|
* } );
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable( {
|
||||||
|
* lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ]
|
||||||
|
* dom: 'Lfrtip'
|
||||||
|
* } );
|
||||||
|
*/
|
||||||
|
DataTable.LengthLinks = function (inst) {
|
||||||
|
var api = new DataTable.Api(inst);
|
||||||
|
var settings = api.settings()[0];
|
||||||
|
var container = $('<div></div>').addClass(settings.oClasses.sLength);
|
||||||
|
var lastLength = null;
|
||||||
|
// API so the feature wrapper can return the node to insert
|
||||||
|
this.container = function () {
|
||||||
|
return container[0];
|
||||||
|
};
|
||||||
|
// Listen for events to change the page length
|
||||||
|
container.on('click.dtll', 'a', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
api.page.len($(this).data('length') * 1).draw(false);
|
||||||
|
});
|
||||||
|
// Update on each draw
|
||||||
|
api.on('draw', function () {
|
||||||
|
// No point in updating - nothing has changed
|
||||||
|
if (api.page.len() === lastLength) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var menu = settings.aLengthMenu;
|
||||||
|
var lang = menu.length === 2 && Array.isArray(menu[0]) ? menu[1] : menu;
|
||||||
|
var lens = menu.length === 2 && Array.isArray(menu[0]) ? menu[0] : menu;
|
||||||
|
var out = $.map(lens, function (el, i) {
|
||||||
|
return el == api.page.len()
|
||||||
|
? '<a class="active" data-length="' + lens[i] + '">' + lang[i] + '</a>'
|
||||||
|
: '<a data-length="' + lens[i] + '">' + lang[i] + '</a>';
|
||||||
|
});
|
||||||
|
container.html(settings.oLanguage.sLengthMenu.replace('_MENU_', out.join(' | ')));
|
||||||
|
lastLength = api.page.len();
|
||||||
|
});
|
||||||
|
api.on('destroy', function () {
|
||||||
|
container.off('click.dtll', 'a');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
// Subscribe the feature plug-in to DataTables, ready for use
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var l = new DataTable.LengthLinks(settings);
|
||||||
|
return l.container();
|
||||||
|
},
|
||||||
|
cFeature: 'L',
|
||||||
|
sFeature: 'LengthLinks',
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,88 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary LengthLinks
|
||||||
|
* @description Page length control via links for DataTables
|
||||||
|
* @version 1.2.0
|
||||||
|
* @author Allan Jardine
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables adds page length control links to the
|
||||||
|
* DataTable. The `dom` option can be used to insert the control using the `L`
|
||||||
|
* character option and it uses the `lengthMenu` options of DataTables to
|
||||||
|
* determine what to display.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable( {
|
||||||
|
* dom: 'Lfrtip'
|
||||||
|
* } );
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#myTable').DataTable( {
|
||||||
|
* lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ]
|
||||||
|
* dom: 'Lfrtip'
|
||||||
|
* } );
|
||||||
|
*/
|
||||||
|
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Page length control via links for DataTables */
|
||||||
|
LengthLinks(settings: any): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.LengthLinks = function (inst) {
|
||||||
|
var api = new DataTable.Api(inst);
|
||||||
|
var settings = api.settings()[0];
|
||||||
|
var container = $('<div></div>').addClass(settings.oClasses.sLength);
|
||||||
|
var lastLength: number | null = null;
|
||||||
|
|
||||||
|
// API so the feature wrapper can return the node to insert
|
||||||
|
this.container = function () {
|
||||||
|
return container[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Listen for events to change the page length
|
||||||
|
container.on('click.dtll', 'a', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
api.page.len($(this).data('length') * 1).draw(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update on each draw
|
||||||
|
api.on('draw', function () {
|
||||||
|
// No point in updating - nothing has changed
|
||||||
|
if (api.page.len() === lastLength) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var menu = settings.aLengthMenu;
|
||||||
|
var lang = menu.length === 2 && Array.isArray(menu[0]) ? menu[1] : menu;
|
||||||
|
var lens = menu.length === 2 && Array.isArray(menu[0]) ? menu[0] : menu;
|
||||||
|
|
||||||
|
var out = $.map(lens, function (el, i) {
|
||||||
|
return el == api.page.len()
|
||||||
|
? '<a class="active" data-length="' + lens[i] + '">' + lang[i] + '</a>'
|
||||||
|
: '<a data-length="' + lens[i] + '">' + lang[i] + '</a>';
|
||||||
|
});
|
||||||
|
|
||||||
|
container.html(
|
||||||
|
settings.oLanguage.sLengthMenu.replace('_MENU_', out.join(' | '))
|
||||||
|
);
|
||||||
|
lastLength = api.page.len();
|
||||||
|
});
|
||||||
|
|
||||||
|
api.on('destroy', function () {
|
||||||
|
container.off('click.dtll', 'a');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Subscribe the feature plug-in to DataTables, ready for use
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var l = new DataTable.LengthLinks(settings);
|
||||||
|
return l.container();
|
||||||
|
},
|
||||||
|
cFeature: 'L',
|
||||||
|
sFeature: 'LengthLinks',
|
||||||
|
});
|
@ -0,0 +1,12 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Automatically alter the DataTables page length to fit the table into a container */
|
||||||
|
PageResize(settings: any, pageResizeManualDelta: boolean): void;
|
||||||
|
}
|
||||||
|
interface Config {
|
||||||
|
pageResize?: boolean;
|
||||||
|
pageResizeManualDelta?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,4 +1,2 @@
|
|||||||
/*! PageResize for DataTables v1.0.0
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2015 SpryMedia Ltd - datatables.net/license
|
!function(i){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return i(e,window,document)}):"object"==typeof exports?module.exports=function(e,t){return e=e||window,(t=t||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,t),i(t,0,e.document)}:i(jQuery,window,document)}(function(d,e,t,i){"use strict";function o(e,t){var i=e.table();this.s={dt:e,host:d(i.container()).parent(),header:d(i.header()),footer:d(i.footer()),body:d(i.body()),container:d(i.container()),table:d(i.node()),delta:t},this.sizes={offsetTop:this._getOffsetTop(),tableHeight:this._getTableHeight(),containerHeight:this._getContainerHeight(),headerHeight:this._getHeaderHeight(),footerHeight:this._getFooterHeight()};"static"===(i=this.s.host).css("position")&&i.css("position","relative");var o=function(){e.off(".pageResize",o),this.s.obj&&this.s.obj.remove()}.bind(this),s=(e.on("destroy.pageResize",o),this._attach(),"init.pageResize");e.on(s,function(){e.off(s),this._size()}.bind(this))}var s=d.fn.dataTable;return o.prototype={_size:function(){var e=this.s,t=e.dt,i=t.table(),o=d("tr",e.body),o=o.eq(1<o.length?1:0).height(),s=e.host.height(),n=i.header().parentNode!==i.body().parentNode,e=e.delta,a=this.sizes.offsetTop=this._getOffsetTop(),h=this.sizes.tableHeight=this._getTableHeight(),r=this.sizes.containerHeight=this._getContainerHeight(),g=this.sizes.headerHeight=this._getHeaderHeight(),f=this.sizes.footerHeight=this._getFooterHeight(),n=(n||(i.header()&&(s-=g),i.footer()&&(s-=f)),s=s-a-(r-(a+h)),!isNaN(parseFloat(e))&&isFinite(e)&&(s-=e),Math.floor(s/o));n!==1/0&&n!==-1/0&&!isNaN(n)&&0<n&&n!==t.page.len()&&t.page.len(n).draw()},_attach:function(){var o=this,e=d("<object/>").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");e[0].onload=function(){var e=this.contentDocument,t=e.body,i=t.offsetHeight;e.defaultView.onresize=function(){var e=t.clientHeight||t.offsetHeight;e!==i?(i=e,o._size()):o.sizes.offsetTop===o._getOffsetTop()&&o.sizes.containerHeight===o._getContainerHeight()&&o.sizes.tableHeight===o._getTableHeight()&&o.sizes.headerHeight===o._getHeaderHeight()&&o.sizes.footerHeight===o._getFooterHeight()||o._size()}},e.appendTo(this.s.host).attr("data","about:blank"),this.s.obj=e},_getOffsetTop:function(){return d(this.s.table).offset().top},_getTableHeight:function(){return this.s.table.height()},_getContainerHeight:function(){return this.s.container.height()},_getHeaderHeight:function(){return this.s.dt.table().header()?this.s.header.height():0},_getFooterHeight:function(){return this.s.dt.table().footer()?this.s.footer.height():0}},s.PageResize=o,d(t).on("preInit.dt",function(e,t){"dt"===e.namespace&&(e=new s.Api(t),d(e.table().node()).hasClass("pageResize")||t.oInit.pageResize||s.defaults.pageResize)&&new o(e,t.oInit.pageResizeManualDelta)}),s});
|
||||||
*/
|
|
||||||
!function(i){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return i(e,window,document)}):"object"==typeof exports?module.exports=function(e,t){return e=e||window,t&&t.fn.dataTable||(t=require("datatables.net")(e,t).$),i(t,0,e.document)}:i(jQuery,window,document)}(function(d,e,t,i){"use strict";function s(e,t){var i=e.table();this.s={dt:e,host:d(i.container()).parent(),header:d(i.header()),footer:d(i.footer()),body:d(i.body()),container:d(i.container()),table:d(i.node()),delta:t},this.sizes={offsetTop:this._getOffsetTop(),tableHeight:this._getTableHeight(),containerHeight:this._getContainerHeight(),headerHeight:this._getHeaderHeight(),footerHeight:this._getFooterHeight()};"static"===(i=this.s.host).css("position")&&i.css("position","relative");var s=function(){e.off(".pageResize",s),this.s.obj&&this.s.obj.remove()}.bind(this),o=(e.on("destroy.pageResize",s),this._attach(),"init.pageResize");e.on(o,function(){e.off(o),this._size()}.bind(this))}s.prototype={_size:function(){var e=this.s,t=e.dt,i=t.table(),s=d("tr",e.body),s=s.eq(1<s.length?1:0).height(),o=e.host.height(),n=i.header().parentNode!==i.body().parentNode,e=e.delta,a=this.sizes.offsetTop=this._getOffsetTop(),h=this.sizes.tableHeight=this._getTableHeight(),r=this.sizes.containerHeight=this._getContainerHeight(),g=this.sizes.headerHeight=this._getHeaderHeight(),f=this.sizes.footerHeight=this._getFooterHeight(),n=(n||(i.header()&&(o-=g),i.footer()&&(o-=f)),o=o-a-(r-(a+h)),!isNaN(parseFloat(e))&&isFinite(e)&&(o-=e),Math.floor(o/s));n!==1/0&&n!==-1/0&&!isNaN(n)&&0<n&&n!==t.page.len()&&t.page.len(n).draw()},_attach:function(){var s=this,e=d("<object/>").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");e[0].onload=function(){var t=this.contentDocument.body,i=t.offsetHeight;this.contentDocument.defaultView.onresize=function(){var e=t.clientHeight||t.offsetHeight;e!==i?(i=e,s._size()):s.sizes.offsetTop===s._getOffsetTop()&&s.sizes.containerHeight===s._getContainerHeight()&&s.sizes.tableHeight===s._getTableHeight()&&s.sizes.headerHeight===s._getHeaderHeight()&&s.sizes.footerHeight===s._getFooterHeight()||s._size()}},e.appendTo(this.s.host).attr("data","about:blank"),this.s.obj=e},_getOffsetTop:function(){return d(this.s.table).offset().top},_getTableHeight:function(){return this.s.table.height()},_getContainerHeight:function(){return this.s.container.height()},_getHeaderHeight:function(){return this.s.dt.table().header()?this.s.header.height():0},_getFooterHeight:function(){return this.s.dt.table().footer()?this.s.footer.height():0}},d.fn.dataTable.PageResize=s,d.fn.DataTable.PageResize=s,d(t).on("preInit.dt",function(e,t){"dt"===e.namespace&&(e=new d.fn.dataTable.Api(t),d(e.table().node()).hasClass("pageResize")||t.oInit.pageResize||d.fn.dataTable.defaults.pageResize)&&new s(e,t.oInit.pageResizeManualDelta)})});
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";var PageResize=function(e,t){var i=e.table(),i=(this.s={dt:e,host:$(i.container()).parent(),header:$(i.header()),footer:$(i.footer()),body:$(i.body()),container:$(i.container()),table:$(i.node()),delta:t},this.sizes={offsetTop:this._getOffsetTop(),tableHeight:this._getTableHeight(),containerHeight:this._getContainerHeight(),headerHeight:this._getHeaderHeight(),footerHeight:this._getFooterHeight()},this.s.host),s=("static"===i.css("position")&&i.css("position","relative"),function(){e.off(".pageResize",s),this.s.obj&&this.s.obj.remove()}.bind(this)),o=(e.on("destroy.pageResize",s),this._attach(),"init.pageResize");e.on(o,function(){e.off(o),this._size()}.bind(this))};PageResize.prototype={_size:function(){var e=this.s,t=e.dt,i=t.table(),s=$("tr",e.body),s=s.eq(1<s.length?1:0).height(),o=e.host.height(),a=i.header().parentNode!==i.body().parentNode,e=e.delta,h=this.sizes.offsetTop=this._getOffsetTop(),n=this.sizes.tableHeight=this._getTableHeight(),g=this.sizes.containerHeight=this._getContainerHeight(),r=this.sizes.headerHeight=this._getHeaderHeight(),f=this.sizes.footerHeight=this._getFooterHeight(),a=(a||(i.header()&&(o-=r),i.footer()&&(o-=f)),o=o-h-(g-(h+n)),!isNaN(parseFloat(e))&&isFinite(e)&&(o-=e),Math.floor(o/s));a!==1/0&&a!==-1/0&&!isNaN(a)&&0<a&&a!==t.page.len()&&t.page.len(a).draw()},_attach:function(){var s=this,e=$("<object/>").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1}).attr("type","text/html");e[0].onload=function(){var e=this.contentDocument,t=e.body,i=t.offsetHeight;e.defaultView.onresize=function(){var e=t.clientHeight||t.offsetHeight;e!==i?(i=e,s._size()):s.sizes.offsetTop===s._getOffsetTop()&&s.sizes.containerHeight===s._getContainerHeight()&&s.sizes.tableHeight===s._getTableHeight()&&s.sizes.headerHeight===s._getHeaderHeight()&&s.sizes.footerHeight===s._getFooterHeight()||s._size()}},e.appendTo(this.s.host).attr("data","about:blank"),this.s.obj=e},_getOffsetTop:function(){return $(this.s.table).offset().top},_getTableHeight:function(){return this.s.table.height()},_getContainerHeight:function(){return this.s.container.height()},_getHeaderHeight:function(){return this.s.dt.table().header()?this.s.header.height():0},_getFooterHeight:function(){return this.s.dt.table().footer()?this.s.footer.height():0}},DataTable.PageResize=PageResize,$(document).on("preInit.dt",function(e,t){"dt"===e.namespace&&(e=new DataTable.Api(t),$(e.table().node()).hasClass("pageResize")||t.oInit.pageResize||DataTable.defaults.pageResize)&&new PageResize(e,t.oInit.pageResizeManualDelta)});export default DataTable;
|
@ -0,0 +1,185 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary PageResize
|
||||||
|
* @description Automatically alter the DataTables page length to fit the table
|
||||||
|
into a container
|
||||||
|
* @version 1.1.0
|
||||||
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables will automatically change the DataTables
|
||||||
|
* page length in order to fit inside its container. This can be particularly
|
||||||
|
* useful for control panels and other interfaces which resize dynamically with
|
||||||
|
* the user's browser window instead of scrolling.
|
||||||
|
*
|
||||||
|
* Page resizing in DataTables can be enabled by using any one of the following
|
||||||
|
* options:
|
||||||
|
*
|
||||||
|
* * Adding the class `pageResize` to the HTML table
|
||||||
|
* * Setting the `pageResize` parameter in the DataTables initialisation to
|
||||||
|
* be true - i.e. `pageResize: true`
|
||||||
|
* * Setting the `pageResize` parameter to be true in the DataTables
|
||||||
|
* defaults (thus causing all tables to have this feature) - i.e.
|
||||||
|
* `DataTable.defaults.pageResize = true`.
|
||||||
|
* * Creating a new instance: `new DataTable.PageResize( table );` where
|
||||||
|
* `table` is a DataTable's API instance.
|
||||||
|
*
|
||||||
|
* For more detailed information please see:
|
||||||
|
* http://datatables.net/blog/2015-04-10
|
||||||
|
*/
|
||||||
|
var PageResize = function (dt, pageResizeManualDelta) {
|
||||||
|
var table = dt.table();
|
||||||
|
this.s = {
|
||||||
|
dt: dt,
|
||||||
|
host: $(table.container()).parent(),
|
||||||
|
header: $(table.header()),
|
||||||
|
footer: $(table.footer()),
|
||||||
|
body: $(table.body()),
|
||||||
|
container: $(table.container()),
|
||||||
|
table: $(table.node()),
|
||||||
|
delta: pageResizeManualDelta,
|
||||||
|
};
|
||||||
|
this.sizes = {
|
||||||
|
offsetTop: this._getOffsetTop(),
|
||||||
|
tableHeight: this._getTableHeight(),
|
||||||
|
containerHeight: this._getContainerHeight(),
|
||||||
|
headerHeight: this._getHeaderHeight(),
|
||||||
|
footerHeight: this._getFooterHeight(),
|
||||||
|
};
|
||||||
|
var host = this.s.host;
|
||||||
|
if (host.css('position') === 'static') {
|
||||||
|
host.css('position', 'relative');
|
||||||
|
}
|
||||||
|
var onDestroy = function () {
|
||||||
|
dt.off('.pageResize', onDestroy);
|
||||||
|
this.s.obj && this.s.obj.remove();
|
||||||
|
}.bind(this);
|
||||||
|
dt.on('destroy.pageResize', onDestroy);
|
||||||
|
this._attach();
|
||||||
|
// Delay the initial sizing until the table is fully initialized
|
||||||
|
// such that the pagination element is also added and can be taken
|
||||||
|
// into account.
|
||||||
|
var initEvent = 'init.pageResize';
|
||||||
|
dt.on(initEvent, function () {
|
||||||
|
dt.off(initEvent);
|
||||||
|
this._size();
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
PageResize.prototype = {
|
||||||
|
_size: function () {
|
||||||
|
var settings = this.s;
|
||||||
|
var dt = settings.dt;
|
||||||
|
var t = dt.table();
|
||||||
|
var rows = $('tr', settings.body);
|
||||||
|
var rowHeight = rows.eq(rows.length > 1 ? 1 : 0).height(); // Attempt to use the second row if poss, for top and bottom border
|
||||||
|
var availableHeight = settings.host.height();
|
||||||
|
var scrolling = t.header().parentNode !== t.body().parentNode;
|
||||||
|
var delta = settings.delta;
|
||||||
|
var offsetTop = (this.sizes.offsetTop = this._getOffsetTop());
|
||||||
|
var tableHeight = (this.sizes.tableHeight = this._getTableHeight());
|
||||||
|
var containerHeight = (this.sizes.containerHeight =
|
||||||
|
this._getContainerHeight());
|
||||||
|
var headerHeight = (this.sizes.headerHeight = this._getHeaderHeight());
|
||||||
|
var footerHeight = (this.sizes.footerHeight = this._getFooterHeight());
|
||||||
|
// Subtract the height of the header, footer and the elements
|
||||||
|
// surrounding the table
|
||||||
|
if (!scrolling) {
|
||||||
|
if (t.header()) {
|
||||||
|
availableHeight -= headerHeight;
|
||||||
|
}
|
||||||
|
if (t.footer()) {
|
||||||
|
availableHeight -= footerHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
availableHeight -= offsetTop;
|
||||||
|
availableHeight -= containerHeight - (offsetTop + tableHeight);
|
||||||
|
if (!isNaN(parseFloat(delta)) && isFinite(delta)) {
|
||||||
|
availableHeight -= delta;
|
||||||
|
}
|
||||||
|
var drawRows = Math.floor(availableHeight / rowHeight);
|
||||||
|
if (drawRows !== Infinity &&
|
||||||
|
drawRows !== -Infinity &&
|
||||||
|
!isNaN(drawRows) &&
|
||||||
|
drawRows > 0 &&
|
||||||
|
drawRows !== dt.page.len()) {
|
||||||
|
dt.page.len(drawRows).draw();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_attach: function () {
|
||||||
|
// There is no `resize` event for elements, so to trigger this effect,
|
||||||
|
// create an empty HTML document using an <object> which will issue a
|
||||||
|
// resize event inside itself when the document resizes. Since it is
|
||||||
|
// 100% x 100% that will occur whenever the host element is resized.
|
||||||
|
var that = this;
|
||||||
|
var obj = $('<object/>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
zIndex: -1,
|
||||||
|
})
|
||||||
|
.attr('type', 'text/html');
|
||||||
|
obj[0].onload = function () {
|
||||||
|
var contentDocument = this.contentDocument;
|
||||||
|
var body = contentDocument.body;
|
||||||
|
var height = body.offsetHeight;
|
||||||
|
contentDocument.defaultView.onresize = function () {
|
||||||
|
var newHeight = body.clientHeight || body.offsetHeight;
|
||||||
|
if (newHeight !== height) {
|
||||||
|
height = newHeight;
|
||||||
|
that._size();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Width changes might lead to layout changes, which might require
|
||||||
|
// resizing the table
|
||||||
|
if (that.sizes.offsetTop !== that._getOffsetTop() ||
|
||||||
|
that.sizes.containerHeight !== that._getContainerHeight() ||
|
||||||
|
that.sizes.tableHeight !== that._getTableHeight() ||
|
||||||
|
that.sizes.headerHeight !== that._getHeaderHeight() ||
|
||||||
|
that.sizes.footerHeight !== that._getFooterHeight()) {
|
||||||
|
that._size();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
obj.appendTo(this.s.host).attr('data', 'about:blank');
|
||||||
|
this.s.obj = obj;
|
||||||
|
},
|
||||||
|
_getOffsetTop: function () {
|
||||||
|
return $(this.s.table).offset().top;
|
||||||
|
},
|
||||||
|
_getTableHeight: function () {
|
||||||
|
return this.s.table.height();
|
||||||
|
},
|
||||||
|
_getContainerHeight: function () {
|
||||||
|
return this.s.container.height();
|
||||||
|
},
|
||||||
|
_getHeaderHeight: function () {
|
||||||
|
return this.s.dt.table().header() ? this.s.header.height() : 0;
|
||||||
|
},
|
||||||
|
_getFooterHeight: function () {
|
||||||
|
return this.s.dt.table().footer() ? this.s.footer.height() : 0;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
DataTable.PageResize = PageResize;
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
if ($(api.table().node()).hasClass('pageResize') ||
|
||||||
|
settings.oInit.pageResize ||
|
||||||
|
DataTable.defaults.pageResize) {
|
||||||
|
new PageResize(api, settings.oInit.pageResizeManualDelta);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,225 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary PageResize
|
||||||
|
* @description Automatically alter the DataTables page length to fit the table
|
||||||
|
into a container
|
||||||
|
* @version 1.1.0
|
||||||
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables will automatically change the DataTables
|
||||||
|
* page length in order to fit inside its container. This can be particularly
|
||||||
|
* useful for control panels and other interfaces which resize dynamically with
|
||||||
|
* the user's browser window instead of scrolling.
|
||||||
|
*
|
||||||
|
* Page resizing in DataTables can be enabled by using any one of the following
|
||||||
|
* options:
|
||||||
|
*
|
||||||
|
* * Adding the class `pageResize` to the HTML table
|
||||||
|
* * Setting the `pageResize` parameter in the DataTables initialisation to
|
||||||
|
* be true - i.e. `pageResize: true`
|
||||||
|
* * Setting the `pageResize` parameter to be true in the DataTables
|
||||||
|
* defaults (thus causing all tables to have this feature) - i.e.
|
||||||
|
* `DataTable.defaults.pageResize = true`.
|
||||||
|
* * Creating a new instance: `new DataTable.PageResize( table );` where
|
||||||
|
* `table` is a DataTable's API instance.
|
||||||
|
*
|
||||||
|
* For more detailed information please see:
|
||||||
|
* http://datatables.net/blog/2015-04-10
|
||||||
|
*/
|
||||||
|
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Automatically alter the DataTables page length to fit the table into a container */
|
||||||
|
PageResize(settings: any, pageResizeManualDelta: boolean): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
pageResize?: boolean;
|
||||||
|
pageResizeManualDelta?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var PageResize = function (dt, pageResizeManualDelta) {
|
||||||
|
var table = dt.table();
|
||||||
|
|
||||||
|
this.s = {
|
||||||
|
dt: dt,
|
||||||
|
host: $(table.container()).parent(),
|
||||||
|
header: $(table.header()),
|
||||||
|
footer: $(table.footer()),
|
||||||
|
body: $(table.body()),
|
||||||
|
container: $(table.container()),
|
||||||
|
table: $(table.node()),
|
||||||
|
delta: pageResizeManualDelta,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.sizes = {
|
||||||
|
offsetTop: this._getOffsetTop(),
|
||||||
|
tableHeight: this._getTableHeight(),
|
||||||
|
containerHeight: this._getContainerHeight(),
|
||||||
|
headerHeight: this._getHeaderHeight(),
|
||||||
|
footerHeight: this._getFooterHeight(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var host = this.s.host;
|
||||||
|
if (host.css('position') === 'static') {
|
||||||
|
host.css('position', 'relative');
|
||||||
|
}
|
||||||
|
|
||||||
|
var onDestroy = function () {
|
||||||
|
dt.off('.pageResize', onDestroy);
|
||||||
|
this.s.obj && this.s.obj.remove();
|
||||||
|
}.bind(this);
|
||||||
|
dt.on('destroy.pageResize', onDestroy);
|
||||||
|
|
||||||
|
this._attach();
|
||||||
|
|
||||||
|
// Delay the initial sizing until the table is fully initialized
|
||||||
|
// such that the pagination element is also added and can be taken
|
||||||
|
// into account.
|
||||||
|
var initEvent = 'init.pageResize';
|
||||||
|
dt.on(
|
||||||
|
initEvent,
|
||||||
|
function () {
|
||||||
|
dt.off(initEvent);
|
||||||
|
this._size();
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PageResize.prototype = {
|
||||||
|
_size: function () {
|
||||||
|
var settings = this.s;
|
||||||
|
var dt = settings.dt;
|
||||||
|
var t = dt.table();
|
||||||
|
var rows = $('tr', settings.body);
|
||||||
|
var rowHeight = rows.eq(rows.length > 1 ? 1 : 0).height()!; // Attempt to use the second row if poss, for top and bottom border
|
||||||
|
var availableHeight = settings.host.height();
|
||||||
|
var scrolling = t.header().parentNode !== t.body().parentNode;
|
||||||
|
var delta = settings.delta;
|
||||||
|
|
||||||
|
var offsetTop = (this.sizes.offsetTop = this._getOffsetTop());
|
||||||
|
var tableHeight = (this.sizes.tableHeight = this._getTableHeight());
|
||||||
|
var containerHeight = (this.sizes.containerHeight =
|
||||||
|
this._getContainerHeight());
|
||||||
|
var headerHeight = (this.sizes.headerHeight = this._getHeaderHeight());
|
||||||
|
var footerHeight = (this.sizes.footerHeight = this._getFooterHeight());
|
||||||
|
|
||||||
|
// Subtract the height of the header, footer and the elements
|
||||||
|
// surrounding the table
|
||||||
|
if (!scrolling) {
|
||||||
|
if (t.header()) {
|
||||||
|
availableHeight -= headerHeight;
|
||||||
|
}
|
||||||
|
if (t.footer()) {
|
||||||
|
availableHeight -= footerHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
availableHeight -= offsetTop;
|
||||||
|
availableHeight -= containerHeight - (offsetTop + tableHeight);
|
||||||
|
|
||||||
|
if (!isNaN(parseFloat(delta)) && isFinite(delta)) {
|
||||||
|
availableHeight -= delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
var drawRows = Math.floor(availableHeight / rowHeight);
|
||||||
|
|
||||||
|
if (
|
||||||
|
drawRows !== Infinity &&
|
||||||
|
drawRows !== -Infinity &&
|
||||||
|
!isNaN(drawRows) &&
|
||||||
|
drawRows > 0 &&
|
||||||
|
drawRows !== dt.page.len()
|
||||||
|
) {
|
||||||
|
dt.page.len(drawRows).draw();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_attach: function () {
|
||||||
|
// There is no `resize` event for elements, so to trigger this effect,
|
||||||
|
// create an empty HTML document using an <object> which will issue a
|
||||||
|
// resize event inside itself when the document resizes. Since it is
|
||||||
|
// 100% x 100% that will occur whenever the host element is resized.
|
||||||
|
var that = this;
|
||||||
|
var obj = $('<object/>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
zIndex: -1,
|
||||||
|
})
|
||||||
|
.attr('type', 'text/html');
|
||||||
|
|
||||||
|
obj[0].onload = function () {
|
||||||
|
var contentDocument = (this as any).contentDocument;
|
||||||
|
var body = contentDocument.body;
|
||||||
|
var height = body.offsetHeight;
|
||||||
|
|
||||||
|
contentDocument.defaultView.onresize = function () {
|
||||||
|
var newHeight = body.clientHeight || body.offsetHeight;
|
||||||
|
if (newHeight !== height) {
|
||||||
|
height = newHeight;
|
||||||
|
that._size();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Width changes might lead to layout changes, which might require
|
||||||
|
// resizing the table
|
||||||
|
if (
|
||||||
|
that.sizes.offsetTop !== that._getOffsetTop() ||
|
||||||
|
that.sizes.containerHeight !== that._getContainerHeight() ||
|
||||||
|
that.sizes.tableHeight !== that._getTableHeight() ||
|
||||||
|
that.sizes.headerHeight !== that._getHeaderHeight() ||
|
||||||
|
that.sizes.footerHeight !== that._getFooterHeight()
|
||||||
|
) {
|
||||||
|
that._size();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
obj.appendTo(this.s.host).attr('data', 'about:blank');
|
||||||
|
|
||||||
|
this.s.obj = obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getOffsetTop: function () {
|
||||||
|
return $(this.s.table).offset()!.top;
|
||||||
|
},
|
||||||
|
_getTableHeight: function () {
|
||||||
|
return this.s.table.height();
|
||||||
|
},
|
||||||
|
_getContainerHeight: function () {
|
||||||
|
return this.s.container.height();
|
||||||
|
},
|
||||||
|
_getHeaderHeight: function () {
|
||||||
|
return this.s.dt.table().header() ? this.s.header.height() : 0;
|
||||||
|
},
|
||||||
|
_getFooterHeight: function () {
|
||||||
|
return this.s.dt.table().footer() ? this.s.footer.height() : 0;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
DataTable.PageResize = PageResize;
|
||||||
|
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
|
||||||
|
if (
|
||||||
|
$(api.table().node()).hasClass('pageResize') ||
|
||||||
|
settings.oInit.pageResize ||
|
||||||
|
DataTable.defaults.pageResize
|
||||||
|
) {
|
||||||
|
new PageResize(api, settings.oInit.pageResizeManualDelta);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Match the number of rows in a table to the page length */
|
||||||
|
RowFill(settings: any): void;
|
||||||
|
}
|
||||||
|
interface Config {
|
||||||
|
rowFill?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,112 +1,106 @@
|
|||||||
/*! RowFill for DataTables v1.0.0
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2018 SpryMedia Ltd - datatables.net/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
(function( factory ){
|
||||||
* @summary RowFill
|
if ( typeof define === 'function' && define.amd ) {
|
||||||
* @description Match the number of rows in a table to the page length
|
|
||||||
* @version 1.0.0
|
|
||||||
* @file dataTables.rowFill.js
|
|
||||||
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
|
||||||
* @contact www.sprymedia.co.uk/contact
|
|
||||||
* @copyright Copyright 2018 SpryMedia Ltd.
|
|
||||||
*
|
|
||||||
* License MIT - http://datatables.net/license/mit
|
|
||||||
*
|
|
||||||
* This feature plug-in for DataTables will automatically insert temporary rows
|
|
||||||
* into a DataTable that draws a page that is less than the configured page
|
|
||||||
* length. This can be handy to ensure that your table always as (e.g.) 10 rows
|
|
||||||
* visible.
|
|
||||||
*
|
|
||||||
* Filler rows have the class `dt-rowFill--filler` assigned to them allowing for
|
|
||||||
* additional styling (e.g. reducing opacity).
|
|
||||||
*
|
|
||||||
* To enable for a table add `rowFill: true` to your DataTables configuration.
|
|
||||||
*/
|
|
||||||
(function(factory) {
|
|
||||||
if (typeof define === 'function' && define.amd) {
|
|
||||||
// AMD
|
// AMD
|
||||||
define(['jquery', 'datatables.net'], function($) {
|
define( ['jquery', 'datatables.net'], function ( $ ) {
|
||||||
return factory($, window, document);
|
return factory( $, window, document );
|
||||||
});
|
} );
|
||||||
} else if (typeof exports === 'object') {
|
}
|
||||||
|
else if ( typeof exports === 'object' ) {
|
||||||
// CommonJS
|
// CommonJS
|
||||||
module.exports = function(root, $) {
|
module.exports = function (root, $) {
|
||||||
if (!root) {
|
if ( ! root ) {
|
||||||
|
// CommonJS environments without a window global must pass a
|
||||||
|
// root. This will give an error otherwise
|
||||||
root = window;
|
root = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$ || !$.fn.dataTable) {
|
if ( ! $ ) {
|
||||||
$ = require('datatables.net')(root, $).$;
|
$ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
|
||||||
|
require('jquery') :
|
||||||
|
require('jquery')( root );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $.fn.dataTable ) {
|
||||||
|
require('datatables.net')(root, $);
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory($, root, root.document);
|
return factory( $, root, root.document );
|
||||||
};
|
};
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Browser
|
// Browser
|
||||||
factory(jQuery, window, document);
|
factory( jQuery, window, document );
|
||||||
}
|
}
|
||||||
})(function($, window, document, undefined) {
|
}(function( $, window, document, undefined ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var DataTable = $.fn.dataTable;
|
||||||
var RowFill = function(dt, pageResizeManualDelta) {
|
|
||||||
var table = dt.table();
|
|
||||||
|
|
||||||
this.s = {
|
|
||||||
dt: dt,
|
|
||||||
body: $(table.body())
|
|
||||||
};
|
|
||||||
|
|
||||||
this._attach();
|
|
||||||
};
|
|
||||||
|
|
||||||
RowFill.prototype = {
|
|
||||||
_attach: function() {
|
|
||||||
var dt = this.s.dt;
|
|
||||||
var body = this.s.body;
|
|
||||||
|
|
||||||
dt.on('draw', function() {
|
/**
|
||||||
var colspan = dt.columns(':visible').count();
|
* @summary RowFill
|
||||||
var rowCount = dt.rows({ page: 'current' }).count();
|
* @description Match the number of rows in a table to the page length
|
||||||
var class1 = 'even';
|
* @version 1.1.0
|
||||||
var class2 = 'odd';
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
// Take account of the fact that DataTables will show a "Nothing found" row
|
* This feature plug-in for DataTables will automatically insert temporary rows
|
||||||
// for an empty record set
|
* into a DataTable that draws a page that is less than the configured page
|
||||||
if (rowCount === 0) {
|
* length. This can be handy to ensure that your table always as (e.g.) 10 rows
|
||||||
rowCount = 1;
|
* visible.
|
||||||
}
|
*
|
||||||
|
* Filler rows have the class `dt-rowFill--filler` assigned to them allowing for
|
||||||
// Reverse for continuation from the DataTable rows when a odd number of rows
|
* additional styling (e.g. reducing opacity).
|
||||||
if ( rowCount % 2 === 0 ) {
|
*
|
||||||
class1 = 'odd';
|
* To enable for a table add `rowFill: true` to your DataTables configuration.
|
||||||
class2 = 'even';
|
*/
|
||||||
}
|
var RowFill = function (dt) {
|
||||||
|
var table = dt.table();
|
||||||
for (var i = 0; i < dt.page.len() - rowCount; i++) {
|
this.s = {
|
||||||
body.append(
|
dt: dt,
|
||||||
$('<tr><td colspan="'+colspan+'"> </td></tr>')
|
body: $(table.body()),
|
||||||
.addClass( i%2 === 0 ? class1 : class2 )
|
};
|
||||||
.addClass( 'dt-rowFill--filler' )
|
this._attach();
|
||||||
);
|
};
|
||||||
}
|
RowFill.prototype = {
|
||||||
});
|
_attach: function () {
|
||||||
}
|
var dt = this.s.dt;
|
||||||
};
|
var body = this.s.body;
|
||||||
|
dt.on('draw', function () {
|
||||||
$.fn.dataTable.RowFill = RowFill;
|
var colspan = dt.columns(':visible').count();
|
||||||
$.fn.DataTable.RowFill = RowFill;
|
var rowCount = dt.rows({ page: 'current' }).count();
|
||||||
|
var class1 = 'even';
|
||||||
// Automatic initialisation listener
|
var class2 = 'odd';
|
||||||
$(document).on('preInit.dt', function(e, settings) {
|
// Take account of the fact that DataTables will show a "Nothing found" row
|
||||||
if (e.namespace !== 'dt') {
|
// for an empty record set
|
||||||
return;
|
if (rowCount === 0) {
|
||||||
}
|
rowCount = 1;
|
||||||
|
}
|
||||||
|
// Reverse for continuation from the DataTable rows when a odd number of rows
|
||||||
|
if (rowCount % 2 === 0) {
|
||||||
|
class1 = 'odd';
|
||||||
|
class2 = 'even';
|
||||||
|
}
|
||||||
|
for (var i = 0; i < dt.page.len() - rowCount; i++) {
|
||||||
|
body.append($('<tr><td colspan="' + colspan + '"> </td></tr>')
|
||||||
|
.addClass(i % 2 === 0 ? class1 : class2)
|
||||||
|
.addClass('dt-rowFill--filler'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
DataTable.RowFill = RowFill;
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
if (settings.oInit.rowFill || DataTable.defaults.rowFill) {
|
||||||
|
new RowFill(api);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var api = new $.fn.dataTable.Api(settings);
|
|
||||||
|
|
||||||
if (settings.oInit.rowFill || $.fn.dataTable.defaults.rowFill) {
|
return DataTable;
|
||||||
new RowFill(api);
|
}));
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
/*! RowFill for DataTables v1.0.0
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2018 SpryMedia Ltd - datatables.net/license
|
!function(n){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return n(e,window,document)}):"object"==typeof exports?module.exports=function(e,t){return e=e||window,(t=t||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,t),n(t,0,e.document)}:n(jQuery,window,document)}(function(i,e,t,n){"use strict";function o(e){var t=e.table();this.s={dt:e,body:i(t.body())},this._attach()}var d=i.fn.dataTable;return o.prototype={_attach:function(){var r=this.s.dt,a=this.s.body;r.on("draw",function(){var e=r.columns(":visible").count(),t=r.rows({page:"current"}).count(),n="even",o="odd";(t=0===t?1:t)%2==0&&(n="odd",o="even");for(var d=0;d<r.page.len()-t;d++)a.append(i('<tr><td colspan="'+e+'"> </td></tr>').addClass(d%2==0?n:o).addClass("dt-rowFill--filler"))})}},d.RowFill=o,i(t).on("preInit.dt",function(e,t){"dt"===e.namespace&&(e=new d.Api(t),t.oInit.rowFill||d.defaults.rowFill)&&new o(e)}),d});
|
||||||
*/
|
|
||||||
!function(e){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return e(t,window,document)}):"object"==typeof exports?module.exports=function(t,n){return t=t||window,n&&n.fn.dataTable||(n=require("datatables.net")(t,n).$),e(n,0,t.document)}:e(jQuery,window,document)}(function(l,t,n,e){"use strict";function a(t,n){var e=t.table();this.s={dt:t,body:l(e.body())},this._attach()}a.prototype={_attach:function(){var d=this.s.dt,i=this.s.body;d.on("draw",function(){var t=d.columns(":visible").count(),n=d.rows({page:"current"}).count(),e="even",a="odd";(n=0===n?1:n)%2==0&&(e="odd",a="even");for(var o=0;o<d.page.len()-n;o++)i.append(l('<tr><td colspan="'+t+'"> </td></tr>').addClass(o%2==0?e:a).addClass("dt-rowFill--filler"))})}},l.fn.dataTable.RowFill=a,l.fn.DataTable.RowFill=a,l(n).on("preInit.dt",function(t,n){"dt"===t.namespace&&(t=new l.fn.dataTable.Api(n),n.oInit.rowFill||l.fn.dataTable.defaults.rowFill)&&new a(t)})});
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";var RowFill=function(t){var a=t.table();this.s={dt:t,body:$(a.body())},this._attach()};RowFill.prototype={_attach:function(){var n=this.s.dt,d=this.s.body;n.on("draw",function(){var t=n.columns(":visible").count(),a=n.rows({page:"current"}).count(),o="even",l="odd";(a=0===a?1:a)%2==0&&(o="odd",l="even");for(var e=0;e<n.page.len()-a;e++)d.append($('<tr><td colspan="'+t+'"> </td></tr>').addClass(e%2==0?o:l).addClass("dt-rowFill--filler"))})}},DataTable.RowFill=RowFill,$(document).on("preInit.dt",function(t,a){"dt"===t.namespace&&(t=new DataTable.Api(a),a.oInit.rowFill||DataTable.defaults.rowFill)&&new RowFill(t)});export default DataTable;
|
@ -0,0 +1,71 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary RowFill
|
||||||
|
* @description Match the number of rows in a table to the page length
|
||||||
|
* @version 1.1.0
|
||||||
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables will automatically insert temporary rows
|
||||||
|
* into a DataTable that draws a page that is less than the configured page
|
||||||
|
* length. This can be handy to ensure that your table always as (e.g.) 10 rows
|
||||||
|
* visible.
|
||||||
|
*
|
||||||
|
* Filler rows have the class `dt-rowFill--filler` assigned to them allowing for
|
||||||
|
* additional styling (e.g. reducing opacity).
|
||||||
|
*
|
||||||
|
* To enable for a table add `rowFill: true` to your DataTables configuration.
|
||||||
|
*/
|
||||||
|
var RowFill = function (dt) {
|
||||||
|
var table = dt.table();
|
||||||
|
this.s = {
|
||||||
|
dt: dt,
|
||||||
|
body: $(table.body()),
|
||||||
|
};
|
||||||
|
this._attach();
|
||||||
|
};
|
||||||
|
RowFill.prototype = {
|
||||||
|
_attach: function () {
|
||||||
|
var dt = this.s.dt;
|
||||||
|
var body = this.s.body;
|
||||||
|
dt.on('draw', function () {
|
||||||
|
var colspan = dt.columns(':visible').count();
|
||||||
|
var rowCount = dt.rows({ page: 'current' }).count();
|
||||||
|
var class1 = 'even';
|
||||||
|
var class2 = 'odd';
|
||||||
|
// Take account of the fact that DataTables will show a "Nothing found" row
|
||||||
|
// for an empty record set
|
||||||
|
if (rowCount === 0) {
|
||||||
|
rowCount = 1;
|
||||||
|
}
|
||||||
|
// Reverse for continuation from the DataTable rows when a odd number of rows
|
||||||
|
if (rowCount % 2 === 0) {
|
||||||
|
class1 = 'odd';
|
||||||
|
class2 = 'even';
|
||||||
|
}
|
||||||
|
for (var i = 0; i < dt.page.len() - rowCount; i++) {
|
||||||
|
body.append($('<tr><td colspan="' + colspan + '"> </td></tr>')
|
||||||
|
.addClass(i % 2 === 0 ? class1 : class2)
|
||||||
|
.addClass('dt-rowFill--filler'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
DataTable.RowFill = RowFill;
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
if (settings.oInit.rowFill || DataTable.defaults.rowFill) {
|
||||||
|
new RowFill(api);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,92 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary RowFill
|
||||||
|
* @description Match the number of rows in a table to the page length
|
||||||
|
* @version 1.1.0
|
||||||
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables will automatically insert temporary rows
|
||||||
|
* into a DataTable that draws a page that is less than the configured page
|
||||||
|
* length. This can be handy to ensure that your table always as (e.g.) 10 rows
|
||||||
|
* visible.
|
||||||
|
*
|
||||||
|
* Filler rows have the class `dt-rowFill--filler` assigned to them allowing for
|
||||||
|
* additional styling (e.g. reducing opacity).
|
||||||
|
*
|
||||||
|
* To enable for a table add `rowFill: true` to your DataTables configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Match the number of rows in a table to the page length */
|
||||||
|
RowFill(settings: any): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
rowFill?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var RowFill = function (dt) {
|
||||||
|
var table = dt.table();
|
||||||
|
|
||||||
|
this.s = {
|
||||||
|
dt: dt,
|
||||||
|
body: $(table.body()),
|
||||||
|
};
|
||||||
|
|
||||||
|
this._attach();
|
||||||
|
};
|
||||||
|
|
||||||
|
RowFill.prototype = {
|
||||||
|
_attach: function () {
|
||||||
|
var dt = this.s.dt;
|
||||||
|
var body = this.s.body;
|
||||||
|
|
||||||
|
dt.on('draw', function () {
|
||||||
|
var colspan = dt.columns(':visible').count();
|
||||||
|
var rowCount = dt.rows({ page: 'current' }).count();
|
||||||
|
var class1 = 'even';
|
||||||
|
var class2 = 'odd';
|
||||||
|
|
||||||
|
// Take account of the fact that DataTables will show a "Nothing found" row
|
||||||
|
// for an empty record set
|
||||||
|
if (rowCount === 0) {
|
||||||
|
rowCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse for continuation from the DataTable rows when a odd number of rows
|
||||||
|
if (rowCount % 2 === 0) {
|
||||||
|
class1 = 'odd';
|
||||||
|
class2 = 'even';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < dt.page.len() - rowCount; i++) {
|
||||||
|
body.append(
|
||||||
|
$('<tr><td colspan="' + colspan + '"> </td></tr>')
|
||||||
|
.addClass(i % 2 === 0 ? class1 : class2)
|
||||||
|
.addClass('dt-rowFill--filler')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
DataTable.RowFill = RowFill;
|
||||||
|
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
|
||||||
|
if (settings.oInit.rowFill || DataTable.defaults.rowFill) {
|
||||||
|
new RowFill(api);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Automatically alter the DataTables page length to fit the table into a container */
|
||||||
|
ScrollResize(settings: any): void;
|
||||||
|
}
|
||||||
|
interface Config {
|
||||||
|
scrollResize?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,4 +1,2 @@
|
|||||||
/*! ScrollResize for DataTables v1.0.0
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2015 SpryMedia Ltd - datatables.net/license
|
!function(o){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return o(t,window,document)}):"object"==typeof exports?module.exports=function(t,e){return t=t||window,(e=e||("undefined"!=typeof window?require("jquery"):require("jquery")(t))).fn.dataTable||require("datatables.net")(t,e),o(e,0,t.document)}:o(jQuery,window,document)}(function(a,t,e,o){"use strict";function i(t){var e=this,o=t.table();this.s={dt:t,host:a(o.container()).parent(),header:a(o.header()),footer:a(o.footer()),body:a(o.body()),container:a(o.container()),table:a(o.node())};"static"===(o=this.s.host).css("position")&&o.css("position","relative"),t.on("draw.scrollResize",function(){e._size()}),t.on("destroy.scrollResize",function(){t.off(".scrollResize"),this.s.obj&&this.s.obj.remove()}.bind(this)),this._attach(),this._size();var o=t.settings()[0],i=(i=o.nScrollBody).scrollHeight>i.clientHeight;o.scrollBarVis&&!i&&t.columns.adjust()}var n=a.fn.dataTable;return i.prototype={_size:function(){var t=this.s,e=t.dt.table(),o=a(t.table).offset().top,i=t.host.height(),n=a("div.dataTables_scrollBody",e.container()),i=(i-=o)-(t.container.height()-(o+n.height()));a("div.dataTables_scrollBody",e.container()).css({maxHeight:i,height:i})},_attach:function(){var s=this,t=a("<iframe/>").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1,border:0}).attr("frameBorder","0").attr("src","about:blank");t[0].onload=function(){var t=this.contentDocument,o=t.body,i=o.offsetHeight,n=t;(n.defaultView||n.parentWindow).onresize=function(){var t=o.clientHeight||o.offsetHeight,e=n.documentElement.clientHeight;(t=!t&&e?e:t)!==i&&(i=t,s._size())}},t.appendTo(this.s.host).attr("data","about:blank"),this.s.obj=t}},n.ScrollResize=i,a(e).on("init.dt",function(t,e){"dt"===t.namespace&&(t=new n.Api(e),e.oInit.scrollResize||n.defaults.scrollResize)&&new i(t)}),n});
|
||||||
*/
|
|
||||||
!function(o){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return o(t,window,document)}):"object"==typeof exports?module.exports=function(t,e){return t=t||window,e&&e.fn.dataTable||(e=require("datatables.net")(t,e).$),o(e,0,t.document)}:o(jQuery,window,document)}(function(a,t,e,o){"use strict";function n(t){var e=this,o=t.table();this.s={dt:t,host:a(o.container()).parent(),header:a(o.header()),footer:a(o.footer()),body:a(o.body()),container:a(o.container()),table:a(o.node())};"static"===(o=this.s.host).css("position")&&o.css("position","relative"),t.on("draw.scrollResize",function(){e._size()}),t.on("destroy.scrollResize",function(){t.off(".scrollResize"),this.s.obj&&this.s.obj.remove()}.bind(this)),this._attach(),this._size();var o=t.settings()[0],n=(n=o.nScrollBody).scrollHeight>n.clientHeight;o.scrollBarVis&&!n&&t.columns.adjust()}n.prototype={_size:function(){var t=this.s,e=t.dt.table(),o=a(t.table).offset().top,n=t.host.height(),i=a("div.dataTables_scrollBody",e.container()),n=(n-=o)-(t.container.height()-(o+i.height()));a("div.dataTables_scrollBody",e.container()).css({maxHeight:n,height:n})},_attach:function(){var s=this,t=a("<iframe/>").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1,border:0}).attr("frameBorder","0").attr("src","about:blank");t[0].onload=function(){var o=this.contentDocument.body,n=o.offsetHeight,i=this.contentDocument;(i.defaultView||i.parentWindow).onresize=function(){var t=o.clientHeight||o.offsetHeight,e=i.documentElement.clientHeight;(t=!t&&e?e:t)!==n&&(n=t,s._size())}},t.appendTo(this.s.host).attr("data","about:blank"),this.s.obj=t}},a.fn.dataTable.ScrollResize=n,a.fn.DataTable.ScrollResize=n,a(e).on("init.dt",function(t,e){"dt"===t.namespace&&(t=new a.fn.dataTable.Api(e),e.oInit.scrollResize||a.fn.dataTable.defaults.scrollResize)&&new n(t)})});
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";var ScrollResize=function(t){var e=this,o=t.table(),o=(this.s={dt:t,host:$(o.container()).parent(),header:$(o.header()),footer:$(o.footer()),body:$(o.body()),container:$(o.container()),table:$(o.node())},this.s.host),o=("static"===o.css("position")&&o.css("position","relative"),t.on("draw.scrollResize",function(){e._size()}),t.on("destroy.scrollResize",function(){t.off(".scrollResize"),this.s.obj&&this.s.obj.remove()}.bind(this)),this._attach(),this._size(),t.settings()[0]),i=o.nScrollBody,i=i.scrollHeight>i.clientHeight;o.scrollBarVis&&!i&&t.columns.adjust()};ScrollResize.prototype={_size:function(){var t=this.s,e=t.dt.table(),o=$(t.table).offset().top,i=t.host.height(),s=$("div.dataTables_scrollBody",e.container()),i=(i-=o)-(t.container.height()-(o+s.height()));$("div.dataTables_scrollBody",e.container()).css({maxHeight:i,height:i})},_attach:function(){var a=this,t=$("<iframe/>").css({position:"absolute",top:0,left:0,height:"100%",width:"100%",zIndex:-1,border:0}).attr("frameBorder","0").attr("src","about:blank");t[0].onload=function(){var t=this.contentDocument,o=t.body,i=o.offsetHeight,s=t;(s.defaultView||s.parentWindow).onresize=function(){var t=o.clientHeight||o.offsetHeight,e=s.documentElement.clientHeight;(t=!t&&e?e:t)!==i&&(i=t,a._size())}},t.appendTo(this.s.host).attr("data","about:blank"),this.s.obj=t}},DataTable.ScrollResize=ScrollResize,$(document).on("init.dt",function(t,e){"dt"===t.namespace&&(t=new DataTable.Api(e),e.oInit.scrollResize||DataTable.defaults.scrollResize)&&new ScrollResize(t)});export default DataTable;
|
@ -0,0 +1,138 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ScrollResize
|
||||||
|
* @description Automatically alter the DataTables page length to fit the table
|
||||||
|
into a container
|
||||||
|
* @version 1.1.0
|
||||||
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables will automatically change the DataTables
|
||||||
|
* page length in order to fit inside its container. This can be particularly
|
||||||
|
* useful for control panels and other interfaces which resize dynamically with
|
||||||
|
* the user's browser window instead of scrolling.
|
||||||
|
*
|
||||||
|
* Page resizing in DataTables can be enabled by using any one of the following
|
||||||
|
* options:
|
||||||
|
*
|
||||||
|
* * Setting the `scrollResize` parameter in the DataTables initialisation to
|
||||||
|
* be true - i.e. `scrollResize: true`
|
||||||
|
* * Setting the `scrollResize` parameter to be true in the DataTables
|
||||||
|
* defaults (thus causing all tables to have this feature) - i.e.
|
||||||
|
* `DataTable.defaults.scrollResize = true`.
|
||||||
|
* * Creating a new instance: `new DataTable.ScrollResize( table );` where
|
||||||
|
* `table` is a DataTable's API instance.
|
||||||
|
*/
|
||||||
|
var ScrollResize = function (dt) {
|
||||||
|
var that = this;
|
||||||
|
var table = dt.table();
|
||||||
|
this.s = {
|
||||||
|
dt: dt,
|
||||||
|
host: $(table.container()).parent(),
|
||||||
|
header: $(table.header()),
|
||||||
|
footer: $(table.footer()),
|
||||||
|
body: $(table.body()),
|
||||||
|
container: $(table.container()),
|
||||||
|
table: $(table.node()),
|
||||||
|
};
|
||||||
|
var host = this.s.host;
|
||||||
|
if (host.css('position') === 'static') {
|
||||||
|
host.css('position', 'relative');
|
||||||
|
}
|
||||||
|
dt.on('draw.scrollResize', function () {
|
||||||
|
that._size();
|
||||||
|
});
|
||||||
|
dt.on('destroy.scrollResize', function () {
|
||||||
|
dt.off('.scrollResize');
|
||||||
|
this.s.obj && this.s.obj.remove();
|
||||||
|
}.bind(this));
|
||||||
|
this._attach();
|
||||||
|
this._size();
|
||||||
|
// Redraw the header if the scrollbar was visible before feature
|
||||||
|
// initialization, but no longer after initialization. Otherwise,
|
||||||
|
// the header width would differ from the body width, because the
|
||||||
|
// scrollbar is no longer present.
|
||||||
|
var settings = dt.settings()[0];
|
||||||
|
var divBodyEl = settings.nScrollBody;
|
||||||
|
var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
|
||||||
|
if (settings.scrollBarVis && !scrollBarVis) {
|
||||||
|
dt.columns.adjust();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ScrollResize.prototype = {
|
||||||
|
_size: function () {
|
||||||
|
var settings = this.s;
|
||||||
|
var dt = settings.dt;
|
||||||
|
var t = dt.table();
|
||||||
|
var offsetTop = $(settings.table).offset().top;
|
||||||
|
var availableHeight = settings.host.height();
|
||||||
|
var scrollBody = $('div.dataTables_scrollBody', t.container());
|
||||||
|
// Subtract the height of the header, footer and the elements
|
||||||
|
// surrounding the table
|
||||||
|
availableHeight -= offsetTop;
|
||||||
|
availableHeight -=
|
||||||
|
settings.container.height() - (offsetTop + scrollBody.height());
|
||||||
|
$('div.dataTables_scrollBody', t.container()).css({
|
||||||
|
maxHeight: availableHeight,
|
||||||
|
height: availableHeight,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
_attach: function () {
|
||||||
|
// There is no `resize` event for elements, so to trigger this effect,
|
||||||
|
// create an empty HTML document using an <iframe> which will issue a
|
||||||
|
// resize event inside itself when the document resizes. Since it is
|
||||||
|
// 100% x 100% that will occur whenever the host element is resized.
|
||||||
|
var that = this;
|
||||||
|
var obj = $('<iframe/>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
zIndex: -1,
|
||||||
|
border: 0,
|
||||||
|
})
|
||||||
|
.attr('frameBorder', '0')
|
||||||
|
.attr('src', 'about:blank');
|
||||||
|
obj[0].onload = function () {
|
||||||
|
var contentDocument = this.contentDocument;
|
||||||
|
var body = contentDocument.body;
|
||||||
|
var height = body.offsetHeight;
|
||||||
|
var contentDoc = contentDocument;
|
||||||
|
var defaultView = contentDoc.defaultView || contentDoc.parentWindow;
|
||||||
|
defaultView.onresize = function () {
|
||||||
|
// Three methods to get the iframe height, to keep all browsers happy
|
||||||
|
var newHeight = body.clientHeight || body.offsetHeight;
|
||||||
|
var docClientHeight = contentDoc.documentElement.clientHeight;
|
||||||
|
if (!newHeight && docClientHeight) {
|
||||||
|
newHeight = docClientHeight;
|
||||||
|
}
|
||||||
|
if (newHeight !== height) {
|
||||||
|
height = newHeight;
|
||||||
|
that._size();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
obj.appendTo(this.s.host).attr('data', 'about:blank');
|
||||||
|
this.s.obj = obj;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
DataTable.ScrollResize = ScrollResize;
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
if (settings.oInit.scrollResize || DataTable.defaults.scrollResize) {
|
||||||
|
new ScrollResize(api);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,170 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ScrollResize
|
||||||
|
* @description Automatically alter the DataTables page length to fit the table
|
||||||
|
into a container
|
||||||
|
* @version 1.1.0
|
||||||
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
|
* This feature plug-in for DataTables will automatically change the DataTables
|
||||||
|
* page length in order to fit inside its container. This can be particularly
|
||||||
|
* useful for control panels and other interfaces which resize dynamically with
|
||||||
|
* the user's browser window instead of scrolling.
|
||||||
|
*
|
||||||
|
* Page resizing in DataTables can be enabled by using any one of the following
|
||||||
|
* options:
|
||||||
|
*
|
||||||
|
* * Setting the `scrollResize` parameter in the DataTables initialisation to
|
||||||
|
* be true - i.e. `scrollResize: true`
|
||||||
|
* * Setting the `scrollResize` parameter to be true in the DataTables
|
||||||
|
* defaults (thus causing all tables to have this feature) - i.e.
|
||||||
|
* `DataTable.defaults.scrollResize = true`.
|
||||||
|
* * Creating a new instance: `new DataTable.ScrollResize( table );` where
|
||||||
|
* `table` is a DataTable's API instance.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Automatically alter the DataTables page length to fit the table into a container */
|
||||||
|
ScrollResize(settings: any): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
scrollResize?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ScrollResize = function (dt) {
|
||||||
|
var that = this;
|
||||||
|
var table = dt.table();
|
||||||
|
|
||||||
|
this.s = {
|
||||||
|
dt: dt,
|
||||||
|
host: $(table.container()).parent(),
|
||||||
|
header: $(table.header()),
|
||||||
|
footer: $(table.footer()),
|
||||||
|
body: $(table.body()),
|
||||||
|
container: $(table.container()),
|
||||||
|
table: $(table.node()),
|
||||||
|
};
|
||||||
|
|
||||||
|
var host = this.s.host;
|
||||||
|
if (host.css('position') === 'static') {
|
||||||
|
host.css('position', 'relative');
|
||||||
|
}
|
||||||
|
|
||||||
|
dt.on('draw.scrollResize', function () {
|
||||||
|
that._size();
|
||||||
|
});
|
||||||
|
|
||||||
|
dt.on(
|
||||||
|
'destroy.scrollResize',
|
||||||
|
function () {
|
||||||
|
dt.off('.scrollResize');
|
||||||
|
this.s.obj && this.s.obj.remove();
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this._attach();
|
||||||
|
this._size();
|
||||||
|
|
||||||
|
// Redraw the header if the scrollbar was visible before feature
|
||||||
|
// initialization, but no longer after initialization. Otherwise,
|
||||||
|
// the header width would differ from the body width, because the
|
||||||
|
// scrollbar is no longer present.
|
||||||
|
var settings = dt.settings()[0];
|
||||||
|
var divBodyEl = settings.nScrollBody;
|
||||||
|
var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
|
||||||
|
if (settings.scrollBarVis && !scrollBarVis) {
|
||||||
|
dt.columns.adjust();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ScrollResize.prototype = {
|
||||||
|
_size: function () {
|
||||||
|
var settings = this.s;
|
||||||
|
var dt = settings.dt;
|
||||||
|
var t = dt.table();
|
||||||
|
var offsetTop = $(settings.table).offset()!.top;
|
||||||
|
var availableHeight = settings.host.height();
|
||||||
|
var scrollBody = $('div.dataTables_scrollBody', t.container());
|
||||||
|
|
||||||
|
// Subtract the height of the header, footer and the elements
|
||||||
|
// surrounding the table
|
||||||
|
availableHeight -= offsetTop;
|
||||||
|
availableHeight -=
|
||||||
|
settings.container.height() - (offsetTop + scrollBody.height()!);
|
||||||
|
|
||||||
|
$('div.dataTables_scrollBody', t.container()).css({
|
||||||
|
maxHeight: availableHeight,
|
||||||
|
height: availableHeight,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_attach: function () {
|
||||||
|
// There is no `resize` event for elements, so to trigger this effect,
|
||||||
|
// create an empty HTML document using an <iframe> which will issue a
|
||||||
|
// resize event inside itself when the document resizes. Since it is
|
||||||
|
// 100% x 100% that will occur whenever the host element is resized.
|
||||||
|
var that = this;
|
||||||
|
var obj = $('<iframe/>')
|
||||||
|
.css({
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
zIndex: -1,
|
||||||
|
border: 0,
|
||||||
|
})
|
||||||
|
.attr('frameBorder', '0')
|
||||||
|
.attr('src', 'about:blank');
|
||||||
|
|
||||||
|
obj[0].onload = function () {
|
||||||
|
var contentDocument = (this as any).contentDocument;
|
||||||
|
var body = contentDocument.body;
|
||||||
|
var height = body.offsetHeight;
|
||||||
|
var contentDoc = contentDocument;
|
||||||
|
var defaultView = contentDoc.defaultView || contentDoc.parentWindow;
|
||||||
|
|
||||||
|
defaultView.onresize = function () {
|
||||||
|
// Three methods to get the iframe height, to keep all browsers happy
|
||||||
|
var newHeight = body.clientHeight || body.offsetHeight;
|
||||||
|
var docClientHeight = contentDoc.documentElement.clientHeight;
|
||||||
|
|
||||||
|
if (!newHeight && docClientHeight) {
|
||||||
|
newHeight = docClientHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newHeight !== height) {
|
||||||
|
height = newHeight;
|
||||||
|
|
||||||
|
that._size();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
obj.appendTo(this.s.host).attr('data', 'about:blank');
|
||||||
|
|
||||||
|
this.s.obj = obj;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
DataTable.ScrollResize = ScrollResize;
|
||||||
|
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
|
||||||
|
if (settings.oInit.scrollResize || DataTable.defaults.scrollResize) {
|
||||||
|
new ScrollResize(api);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,7 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
scrollToTop?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,16 +1,2 @@
|
|||||||
/*!
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
Copyright 2019 SpryMedia Ltd.
|
!function(t){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return t(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e=e||window,(n=n||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,n),t(n,0,e.document)}:t(jQuery,window,document)}(function(o,e,r,n){"use strict";var u=o.fn.dataTable;return o(r).on("preInit.dt",function(e,n){var t;"dt"===e.namespace&&(n.oInit.scrollToTop||u.defaults.scrollToTop)&&(t=new u.Api(n)).on("page",function(){setTimeout(function(){o(r).scrollTop(o(t.table().container()).offset().top)},10)})}),u});
|
||||||
|
|
||||||
This source file is free software, available under the following license:
|
|
||||||
MIT license - http://datatables.net/license/mit
|
|
||||||
|
|
||||||
This source file is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
|
||||||
|
|
||||||
For details please refer to: http://www.datatables.net
|
|
||||||
scrollToTop 0.0.1
|
|
||||||
2019 SpryMedia Ltd - datatables.net/license
|
|
||||||
*/
|
|
||||||
(function(b){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(a){return b(a,window,document)}):"object"===typeof exports?module.exports=function(a,c){a||(a=window);c&&c.fn.dataTable||(c=require("datatables.net")(a,c).$);return b(c,a,a.document)}:b(jQuery,window,document)})(function(b,a,c,f){b(c).on("preInit.dt",function(a,d){if("dt"===a.namespace&&(d.oInit.scrollToTop||b.fn.dataTable.defaults.scrollToTop)){var e=new b.fn.dataTable.Api(d);e.on("page",function(){setTimeout(function(){b(c).scrollTop(b(e.table().container()).offset().top)},
|
|
||||||
10)})}})});
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";$(document).on("preInit.dt",function(t,o){var a;"dt"===t.namespace&&(o.oInit.scrollToTop||DataTable.defaults.scrollToTop)&&(a=new DataTable.Api(o)).on("page",function(){setTimeout(function(){$(document).scrollTop($(a.table().container()).offset().top)},10)})});export default DataTable;
|
@ -0,0 +1,38 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary scrollToTop
|
||||||
|
* @description Always return to top of table when page changed
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
|
* This source file is free software, available under the following license:
|
||||||
|
* MIT license - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This source file is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
||||||
|
*
|
||||||
|
* For details please refer to: http://www.datatables.net
|
||||||
|
*/
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (settings.oInit.scrollToTop || DataTable.defaults.scrollToTop) {
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
api.on('page', function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
$(document).scrollTop($(api.table().container()).offset().top);
|
||||||
|
}, 10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,43 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary scrollToTop
|
||||||
|
* @description Always return to top of table when page changed
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author SpryMedia Ltd
|
||||||
|
*
|
||||||
|
* This source file is free software, available under the following license:
|
||||||
|
* MIT license - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This source file is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
||||||
|
*
|
||||||
|
* For details please refer to: http://www.datatables.net
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
scrollToTop?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Automatic initialisation listener
|
||||||
|
$(document).on('preInit.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.oInit.scrollToTop || DataTable.defaults.scrollToTop) {
|
||||||
|
var api = new DataTable.Api(settings);
|
||||||
|
|
||||||
|
api.on('page', function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
$(document).scrollTop($(api.table().container()).offset()!.top);
|
||||||
|
}, 10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,20 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Search and Fade unmatching rows in a DataTables */
|
||||||
|
SearchFade(settings: any): void;
|
||||||
|
}
|
||||||
|
interface Config {
|
||||||
|
searchFade?: boolean;
|
||||||
|
}
|
||||||
|
interface Api<T> {
|
||||||
|
searchFade: ApiSearchFade<T>;
|
||||||
|
}
|
||||||
|
interface ApiSearchFade<T> {
|
||||||
|
(): ApiSearchFadeMethods<T>;
|
||||||
|
}
|
||||||
|
interface ApiSearchFadeMethods<T> extends Api<T> {
|
||||||
|
node(): JQuery | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,113 +1,115 @@
|
|||||||
/*! SearchFade 0.0.1
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2018 SpryMedia Ltd - datatables.net/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
(function( factory ){
|
||||||
* @summary SearchFade
|
if ( typeof define === 'function' && define.amd ) {
|
||||||
* @description Search and Fade unmatching rows in a DataTables
|
|
||||||
* @version 0.0.1
|
|
||||||
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
|
||||||
* @copyright Copyright 2018 SpryMedia Ltd.
|
|
||||||
*
|
|
||||||
* This source file is free software, available under the following license:
|
|
||||||
* MIT license - http://datatables.net/license/mit
|
|
||||||
*
|
|
||||||
* This source file is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
|
||||||
*
|
|
||||||
* For details please refer to: http://www.datatables.net
|
|
||||||
*/
|
|
||||||
(function(factory) {
|
|
||||||
if (typeof define === 'function' && define.amd) {
|
|
||||||
// AMD
|
// AMD
|
||||||
define(['jquery', 'datatables.net'], function($) {
|
define( ['jquery', 'datatables.net'], function ( $ ) {
|
||||||
return factory($, window, document);
|
return factory( $, window, document );
|
||||||
});
|
} );
|
||||||
} else if (typeof exports === 'object') {
|
}
|
||||||
|
else if ( typeof exports === 'object' ) {
|
||||||
// CommonJS
|
// CommonJS
|
||||||
module.exports = function(root, $) {
|
module.exports = function (root, $) {
|
||||||
if (!root) {
|
if ( ! root ) {
|
||||||
|
// CommonJS environments without a window global must pass a
|
||||||
|
// root. This will give an error otherwise
|
||||||
root = window;
|
root = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$ || !$.fn.dataTable) {
|
if ( ! $ ) {
|
||||||
$ = require('datatables.net')(root, $).$;
|
$ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
|
||||||
|
require('jquery') :
|
||||||
|
require('jquery')( root );
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory($, root, root.document);
|
if ( ! $.fn.dataTable ) {
|
||||||
|
require('datatables.net')(root, $);
|
||||||
|
}
|
||||||
|
|
||||||
|
return factory( $, root, root.document );
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
// Browser
|
|
||||||
factory(jQuery, window, document);
|
|
||||||
}
|
}
|
||||||
})(function($, window, document, undefined) {
|
else {
|
||||||
'use strict';
|
// Browser
|
||||||
|
factory( jQuery, window, document );
|
||||||
$.fn.dataTable.Api.register('searchFade()', function() {
|
|
||||||
return this;
|
|
||||||
});
|
|
||||||
|
|
||||||
$.fn.dataTable.Api.register('searchFade().node()', function() {
|
|
||||||
return this.settings()[0].searchFadeNode;
|
|
||||||
});
|
|
||||||
|
|
||||||
function _draw(table, searchFade) {
|
|
||||||
searchFade.empty();
|
|
||||||
searchFade.append('Search: ');
|
|
||||||
|
|
||||||
$('<input type="text" class="searchFadeInput' + table.settings()[0].sTableId + '">').appendTo(searchFade);
|
|
||||||
}
|
}
|
||||||
|
}(function( $, window, document, undefined ) {
|
||||||
|
'use strict';
|
||||||
|
var DataTable = $.fn.dataTable;
|
||||||
|
|
||||||
$.fn.dataTable.SearchFade = function(settings) {
|
|
||||||
var table = new $.fn.dataTable.Api(settings);
|
|
||||||
var searchFade = $('<div class="searchFade"/>');
|
|
||||||
|
|
||||||
table.settings()[0].searchFadeNode = searchFade;
|
|
||||||
|
|
||||||
_draw(table, searchFade);
|
/**
|
||||||
|
* @summary SearchFade
|
||||||
// Trigger a search
|
* @description Search and Fade unmatching rows in a DataTables
|
||||||
searchFade.on('keyup redraw', 'input', function() {
|
* @version 1.0.0
|
||||||
table.rows(':visible').every(function(rowIdx, tableLoop, rowLoop) {
|
* This source file is free software, available under the following license:
|
||||||
var present = true;
|
* MIT license - http://datatables.net/license/mit
|
||||||
if ($('.searchFadeInput' + table.settings()[0].sTableId).val().length) {
|
*
|
||||||
present = table
|
* This source file is distributed in the hope that it will be useful, but
|
||||||
.row(rowIdx)
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
.data()
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
||||||
.some(function(v) {
|
*
|
||||||
return v.match(new RegExp($('.searchFadeInput' + table.settings()[0].sTableId).val(), 'i')) != null;
|
* For details please refer to: http://www.datatables.net
|
||||||
});
|
*/
|
||||||
}
|
DataTable.Api.register('searchFade()', function () {
|
||||||
$(table.row(rowIdx).node()).toggleClass('notMatched', !present);
|
return this;
|
||||||
});
|
});
|
||||||
});
|
DataTable.Api.register('searchFade().node()', function () {
|
||||||
|
return this.settings()[0].searchFadeNode;
|
||||||
table.on('draw', function() {
|
});
|
||||||
$('input', searchFade).trigger('redraw');
|
function _draw(table, searchFade) {
|
||||||
});
|
searchFade.empty();
|
||||||
|
searchFade.append('Search: ');
|
||||||
// API method to get the searchFade container node
|
$('<input type="text" class="searchFadeInput' +
|
||||||
this.node = function() {
|
table.settings()[0].sTableId +
|
||||||
return searchFade;
|
'">').appendTo(searchFade);
|
||||||
};
|
}
|
||||||
};
|
DataTable.SearchFade = function (settings) {
|
||||||
|
var table = new DataTable.Api(settings);
|
||||||
$.fn.DataTable.SearchFade = $.fn.dataTable.SearchFade;
|
var searchFade = $('<div class="searchFade"/>');
|
||||||
|
table.settings()[0].searchFadeNode = searchFade;
|
||||||
$.fn.dataTable.ext.feature.push({
|
_draw(table, searchFade);
|
||||||
fnInit: function(settings) {
|
// Trigger a search
|
||||||
var search = new $.fn.dataTable.SearchFade(settings);
|
searchFade.on('keyup redraw', 'input', function () {
|
||||||
return search.node();
|
table.rows(':visible').every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
},
|
var present = true;
|
||||||
cFeature: 'F'
|
var val = $('.searchFadeInput' + table.settings()[0].sTableId).val();
|
||||||
});
|
if (val.length) {
|
||||||
|
present = table
|
||||||
|
.row(rowIdx)
|
||||||
|
.data()
|
||||||
|
.some(function (v) {
|
||||||
|
return v.match(new RegExp(val, 'i')) != null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(table.row(rowIdx).node()).toggleClass('notMatched', !present);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
table.on('draw', function () {
|
||||||
|
$('input', searchFade).trigger('redraw');
|
||||||
|
});
|
||||||
|
// API method to get the searchFade container node
|
||||||
|
this.node = function () {
|
||||||
|
return searchFade;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var search = new DataTable.SearchFade(settings);
|
||||||
|
return search.node();
|
||||||
|
},
|
||||||
|
cFeature: 'F',
|
||||||
|
});
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (settings.oInit.searchFade || DataTable.defaults.searchFade) {
|
||||||
|
DataTable.SearchFade(settings);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('init.dt', function(e, settings, json) {
|
|
||||||
if (e.namespace === 'dt') {
|
|
||||||
$.fn.dataTable.SearchFade(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return DataTable;
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
/*! SearchFade 0.0.1
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2018 SpryMedia Ltd - datatables.net/license
|
!function(t){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return t(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e=e||window,(n=n||("undefined"!=typeof window?require("jquery"):require("jquery")(e))).fn.dataTable||require("datatables.net")(e,n),t(n,0,e.document)}:t(jQuery,window,document)}(function(d,e,n,t){"use strict";var r=d.fn.dataTable;return r.Api.register("searchFade()",function(){return this}),r.Api.register("searchFade().node()",function(){return this.settings()[0].searchFadeNode}),r.SearchFade=function(e){var n,i=new r.Api(e),t=d('<div class="searchFade"/>');i.settings()[0].searchFadeNode=t,e=i,(n=t).empty(),n.append("Search: "),d('<input type="text" class="searchFadeInput'+e.settings()[0].sTableId+'">').appendTo(n),t.on("keyup redraw","input",function(){i.rows(":visible").every(function(e,n,t){var r=!0,a=d(".searchFadeInput"+i.settings()[0].sTableId).val();a.length&&(r=i.row(e).data().some(function(e){return null!=e.match(new RegExp(a,"i"))})),d(i.row(e).node()).toggleClass("notMatched",!r)})}),i.on("draw",function(){d("input",t).trigger("redraw")}),this.node=function(){return t}},r.ext.feature.push({fnInit:function(e){return new r.SearchFade(e).node()},cFeature:"F"}),d(n).on("init.dt",function(e,n){"dt"===e.namespace&&(n.oInit.searchFade||r.defaults.searchFade)&&r.SearchFade(n)}),r});
|
||||||
*/
|
|
||||||
!function(a){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return a(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e=e||window,n&&n.fn.dataTable||(n=require("datatables.net")(e,n).$),a(n,0,e.document)}:a(jQuery,window,document)}(function(r,e,n,a){"use strict";r.fn.dataTable.Api.register("searchFade()",function(){return this}),r.fn.dataTable.Api.register("searchFade().node()",function(){return this.settings()[0].searchFadeNode}),r.fn.dataTable.SearchFade=function(e){var n,d=new r.fn.dataTable.Api(e),a=r('<div class="searchFade"/>');d.settings()[0].searchFadeNode=a,e=d,(n=a).empty(),n.append("Search: "),r('<input type="text" class="searchFadeInput'+e.settings()[0].sTableId+'">').appendTo(n),a.on("keyup redraw","input",function(){d.rows(":visible").every(function(e,n,a){var t=!0;r(".searchFadeInput"+d.settings()[0].sTableId).val().length&&(t=d.row(e).data().some(function(e){return null!=e.match(new RegExp(r(".searchFadeInput"+d.settings()[0].sTableId).val(),"i"))})),r(d.row(e).node()).toggleClass("notMatched",!t)})}),d.on("draw",function(){r("input",a).trigger("redraw")}),this.node=function(){return a}},r.fn.DataTable.SearchFade=r.fn.dataTable.SearchFade,r.fn.dataTable.ext.feature.push({fnInit:function(e){return new r.fn.dataTable.SearchFade(e).node()},cFeature:"F"}),r(n).on("init.dt",function(e,n,a){"dt"===e.namespace&&r.fn.dataTable.SearchFade(n)})});
|
|
@ -0,0 +1,2 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
import $ from"jquery";import DataTable from"datatables.net";function _draw(e,a){a.empty(),a.append("Search: "),$('<input type="text" class="searchFadeInput'+e.settings()[0].sTableId+'">').appendTo(a)}DataTable.Api.register("searchFade()",function(){return this}),DataTable.Api.register("searchFade().node()",function(){return this.settings()[0].searchFadeNode}),DataTable.SearchFade=function(e){var i=new DataTable.Api(e),a=$('<div class="searchFade"/>');i.settings()[0].searchFadeNode=a,_draw(i,a),a.on("keyup redraw","input",function(){i.rows(":visible").every(function(e,a,t){var n=!0,r=$(".searchFadeInput"+i.settings()[0].sTableId).val();r.length&&(n=i.row(e).data().some(function(e){return null!=e.match(new RegExp(r,"i"))})),$(i.row(e).node()).toggleClass("notMatched",!n)})}),i.on("draw",function(){$("input",a).trigger("redraw")}),this.node=function(){return a}},DataTable.ext.feature.push({fnInit:function(e){return new DataTable.SearchFade(e).node()},cFeature:"F"}),$(document).on("init.dt",function(e,a){"dt"===e.namespace&&(a.oInit.searchFade||DataTable.defaults.searchFade)&&DataTable.SearchFade(a)});export default DataTable;
|
@ -0,0 +1,80 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary SearchFade
|
||||||
|
* @description Search and Fade unmatching rows in a DataTables
|
||||||
|
* @version 1.0.0
|
||||||
|
* This source file is free software, available under the following license:
|
||||||
|
* MIT license - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This source file is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
||||||
|
*
|
||||||
|
* For details please refer to: http://www.datatables.net
|
||||||
|
*/
|
||||||
|
DataTable.Api.register('searchFade()', function () {
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
DataTable.Api.register('searchFade().node()', function () {
|
||||||
|
return this.settings()[0].searchFadeNode;
|
||||||
|
});
|
||||||
|
function _draw(table, searchFade) {
|
||||||
|
searchFade.empty();
|
||||||
|
searchFade.append('Search: ');
|
||||||
|
$('<input type="text" class="searchFadeInput' +
|
||||||
|
table.settings()[0].sTableId +
|
||||||
|
'">').appendTo(searchFade);
|
||||||
|
}
|
||||||
|
DataTable.SearchFade = function (settings) {
|
||||||
|
var table = new DataTable.Api(settings);
|
||||||
|
var searchFade = $('<div class="searchFade"/>');
|
||||||
|
table.settings()[0].searchFadeNode = searchFade;
|
||||||
|
_draw(table, searchFade);
|
||||||
|
// Trigger a search
|
||||||
|
searchFade.on('keyup redraw', 'input', function () {
|
||||||
|
table.rows(':visible').every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
|
var present = true;
|
||||||
|
var val = $('.searchFadeInput' + table.settings()[0].sTableId).val();
|
||||||
|
if (val.length) {
|
||||||
|
present = table
|
||||||
|
.row(rowIdx)
|
||||||
|
.data()
|
||||||
|
.some(function (v) {
|
||||||
|
return v.match(new RegExp(val, 'i')) != null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(table.row(rowIdx).node()).toggleClass('notMatched', !present);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
table.on('draw', function () {
|
||||||
|
$('input', searchFade).trigger('redraw');
|
||||||
|
});
|
||||||
|
// API method to get the searchFade container node
|
||||||
|
this.node = function () {
|
||||||
|
return searchFade;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var search = new DataTable.SearchFade(settings);
|
||||||
|
return search.node();
|
||||||
|
},
|
||||||
|
cFeature: 'F',
|
||||||
|
});
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (settings.oInit.searchFade || DataTable.defaults.searchFade) {
|
||||||
|
DataTable.SearchFade(settings);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default DataTable;
|
@ -0,0 +1,118 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary SearchFade
|
||||||
|
* @description Search and Fade unmatching rows in a DataTables
|
||||||
|
* @version 1.0.0
|
||||||
|
* This source file is free software, available under the following license:
|
||||||
|
* MIT license - http://datatables.net/license/mit
|
||||||
|
*
|
||||||
|
* This source file is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
||||||
|
*
|
||||||
|
* For details please refer to: http://www.datatables.net
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery';
|
||||||
|
import DataTable from 'datatables.net';
|
||||||
|
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface DataTablesStatic {
|
||||||
|
/** Search and Fade unmatching rows in a DataTables */
|
||||||
|
SearchFade(settings: any): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
searchFade?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Api<T> {
|
||||||
|
searchFade: ApiSearchFade<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiSearchFade<T> {
|
||||||
|
(): ApiSearchFadeMethods<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiSearchFadeMethods<T> extends Api<T> {
|
||||||
|
node(): JQuery | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.Api.register('searchFade()', function () {
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
|
||||||
|
DataTable.Api.register('searchFade().node()', function () {
|
||||||
|
return this.settings()[0].searchFadeNode;
|
||||||
|
});
|
||||||
|
|
||||||
|
function _draw(table, searchFade) {
|
||||||
|
searchFade.empty();
|
||||||
|
searchFade.append('Search: ');
|
||||||
|
|
||||||
|
$(
|
||||||
|
'<input type="text" class="searchFadeInput' +
|
||||||
|
table.settings()[0].sTableId +
|
||||||
|
'">'
|
||||||
|
).appendTo(searchFade);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTable.SearchFade = function (settings) {
|
||||||
|
var table = new DataTable.Api(settings);
|
||||||
|
var searchFade = $('<div class="searchFade"/>');
|
||||||
|
|
||||||
|
table.settings()[0].searchFadeNode = searchFade;
|
||||||
|
|
||||||
|
_draw(table, searchFade);
|
||||||
|
|
||||||
|
// Trigger a search
|
||||||
|
searchFade.on('keyup redraw', 'input', function () {
|
||||||
|
table.rows(':visible').every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
|
var present = true;
|
||||||
|
var val = $(
|
||||||
|
'.searchFadeInput' + table.settings()[0].sTableId
|
||||||
|
).val()! as string;
|
||||||
|
|
||||||
|
if (val.length) {
|
||||||
|
present = table
|
||||||
|
.row(rowIdx)
|
||||||
|
.data()
|
||||||
|
.some(function (v) {
|
||||||
|
return v.match(new RegExp(val, 'i')) != null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(table.row(rowIdx).node()).toggleClass('notMatched', !present);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
table.on('draw', function () {
|
||||||
|
$('input', searchFade).trigger('redraw');
|
||||||
|
});
|
||||||
|
|
||||||
|
// API method to get the searchFade container node
|
||||||
|
this.node = function () {
|
||||||
|
return searchFade;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
DataTable.ext.feature.push({
|
||||||
|
fnInit: function (settings) {
|
||||||
|
var search = new DataTable.SearchFade(settings);
|
||||||
|
return search.node();
|
||||||
|
},
|
||||||
|
cFeature: 'F',
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('init.dt', function (e, settings) {
|
||||||
|
if (e.namespace !== 'dt') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.oInit.searchFade || DataTable.defaults.searchFade) {
|
||||||
|
DataTable.SearchFade(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
});
|
@ -0,0 +1,7 @@
|
|||||||
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
|
declare module 'datatables.net' {
|
||||||
|
interface Config {
|
||||||
|
searchHighlight?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export {};
|
@ -1,4 +1,2 @@
|
|||||||
/*! SearchHighlight for DataTables v1.0.1
|
/*! © SpryMedia Ltd - datatables.net/license */
|
||||||
* 2014 SpryMedia Ltd - datatables.net/license
|
!function(n){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return n(t,window,document)}):"object"==typeof exports?module.exports=function(t,e){return t=t||window,(e=e||("undefined"!=typeof window?require("jquery"):require("jquery")(t))).fn.dataTable||require("datatables.net")(t,e),n(e,0,t.document)}:n(jQuery,window,document)}(function(d,t,e,n){"use strict";var r=d.fn.dataTable;function a(t,e){t.unhighlight(),e.rows({filter:"applied"}).data().length&&(e.columns().every(function(){var t=this;t.nodes().flatten().to$().unhighlight({className:"column_highlight"}),t.nodes().flatten().to$().highlight(t.search().trim().split(/\s+/),{className:"column_highlight"})}),t.highlight(e.search().trim().split(/\s+/)))}return d(e).on("init.dt.dth",function(t,e,n){var i,o;"dt"===t.namespace&&(i=new r.Api(e),o=d(i.table().body()),d(i.table().node()).hasClass("searchHighlight")||e.oInit.searchHighlight||r.defaults.searchHighlight)&&(i.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth",function(){a(o,i)}).on("destroy",function(){i.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth")}),i.search())&&a(o,i)}),r});
|
||||||
*/
|
|
||||||
!function(t,l){function a(t,i){t.unhighlight(),i.rows({filter:"applied"}).data().length&&(i.columns().every(function(){var t=this;t.nodes().flatten().to$().unhighlight({className:"column_highlight"}),t.nodes().flatten().to$().highlight(t.search().trim().split(/\s+/),{className:"column_highlight"})}),t.highlight(i.search().trim().split(/\s+/)))}l(t).on("init.dt.dth",function(t,i,h){var n,e;"dt"===t.namespace&&(n=new l.fn.dataTable.Api(i),e=l(n.table().body()),l(n.table().node()).hasClass("searchHighlight")||i.oInit.searchHighlight||l.fn.dataTable.defaults.searchHighlight)&&(n.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth",function(){a(e,n)}).on("destroy",function(){n.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth")}),n.search())&&a(e,n)})}((window,document),jQuery);
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue