Skip to content

Commit

Permalink
Features: Updates to operate with DataTables 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanJard committed Feb 22, 2024
1 parent 0ad8916 commit 6c9c2ab
Show file tree
Hide file tree
Showing 64 changed files with 1,880 additions and 471 deletions.
14 changes: 9 additions & 5 deletions features/alphabetSearch/dataTables.alphabetSearch.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*! © SpryMedia Ltd - datatables.net/license */
interface AlphabetSearchOptions {
column?: number;
caseSensitive?: boolean;
numbers?: boolean;
}
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;
};
alphabet?: AlphabetSearchOptions;
}
interface Api<T> {
alphabetSearch: ApiAlphabet<T>;
Expand All @@ -21,5 +22,8 @@ declare module 'datatables.net' {
node(): JQuery | null;
recalc(): Api<T>;
}
interface Feature {
alphabetSearch?: AlphabetSearchOptions;
}
}
export {};
15 changes: 13 additions & 2 deletions features/alphabetSearch/dataTables.alphabetSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ var DataTable = $.fn.dataTable;
*
* License MIT - http://datatables.net/license/mit
*
* For more detailed information please see:
* http://datatables.net/blog/2014-09-22
* Please see [this blog post](http://datatables.net/blog/2014-09-22).
*
* @example
* $('#myTable').DataTable( {
* layout: {
* topStart: 'alphabetSearch;
* }
* } );
*/
;
// Search function
DataTable.Api.register('alphabetSearch()', function (searchTerm) {
this.iterator('table', function (context) {
Expand Down Expand Up @@ -217,6 +224,10 @@ DataTable.ext.feature.push({
},
cFeature: 'A',
});
DataTable.feature.register('alphabetSearch', function (settings, opts) {
var search = new DataTable.AlphabetSearch(settings);
return search.node();
});


return DataTable;
Expand Down
2 changes: 1 addition & 1 deletion features/alphabetSearch/dataTables.alphabetSearch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion features/alphabetSearch/dataTables.alphabetSearch.min.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*! © SpryMedia Ltd - datatables.net/license */
import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;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)}),this.node=function(){return e}},DataTable.ext.feature.push({fnInit:function(a){return new DataTable.AlphabetSearch(a).node()},cFeature:"A"});export default DataTable;
import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;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)}),this.node=function(){return e}},DataTable.ext.feature.push({fnInit:function(a){return new DataTable.AlphabetSearch(a).node()},cFeature:"A"}),DataTable.feature.register("alphabetSearch",function(a,t){return new DataTable.AlphabetSearch(a).node()});export default DataTable;
15 changes: 13 additions & 2 deletions features/alphabetSearch/dataTables.alphabetSearch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ let $ = jQuery;
*
* License MIT - http://datatables.net/license/mit
*
* For more detailed information please see:
* http://datatables.net/blog/2014-09-22
* Please see [this blog post](http://datatables.net/blog/2014-09-22).
*
* @example
* $('#myTable').DataTable( {
* layout: {
* topStart: 'alphabetSearch;
* }
* } );
*/
;
// Search function
DataTable.Api.register('alphabetSearch()', function (searchTerm) {
this.iterator('table', function (context) {
Expand Down Expand Up @@ -177,6 +184,10 @@ DataTable.ext.feature.push({
},
cFeature: 'A',
});
DataTable.feature.register('alphabetSearch', function (settings, opts) {
var search = new DataTable.AlphabetSearch(settings);
return search.node();
});


export default DataTable;
21 changes: 14 additions & 7 deletions features/alphabetSearch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, user-scalable=no">
<title>DataTables example - Fuzzy Searching</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.0.0/css/dataTables.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="dataTables.alphabetSearch.css">

<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/2.0.0/js/dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="dataTables.alphabetSearch.js"></script>
<script type="text/javascript" language="javascript" class="init">


$(document).ready(function() {
var table = $('#example').DataTable({
dom: 'Alfrtip'
layout: {
top: 'alphabetSearch'
}
});
} );

Expand Down Expand Up @@ -512,11 +514,16 @@ <h1>DataTables example <span>Alphabet Search</span></h1>
</tfoot>
</table>
</div>
<p>The Javascript shown below is used to initialise the table shown in this example:</p><code class="multiline language-js">$(document).ready(function() {
<p>The Javascript shown below is used to initialise the table shown in this example:</p>
<code class="multiline language-js">
$(document).ready(function() {
var table = $('#example').DataTable({
fuzzySearch: true
layout: {
top: 'alphabetSearch'
}
});
} );</code>
} );
</code>
</div>
</section>
</body>
Expand Down
32 changes: 25 additions & 7 deletions features/alphabetSearch/src/dataTables.alphabetSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,32 @@
*
* License MIT - http://datatables.net/license/mit
*
* For more detailed information please see:
* http://datatables.net/blog/2014-09-22
* Please see [this blog post](http://datatables.net/blog/2014-09-22).
*
* @example
* $('#myTable').DataTable( {
* layout: {
* topStart: 'alphabetSearch;
* }
* } );
*/

import DataTable from 'datatables.net';

interface AlphabetSearchOptions {
column?: number;
caseSensitive?: boolean;
numbers?: boolean;
};

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;
};
alphabet?: AlphabetSearchOptions;
}

interface Api<T> {
Expand All @@ -45,6 +53,10 @@ declare module 'datatables.net' {

recalc(): Api<T>;
}

interface Feature {
alphabetSearch?: AlphabetSearchOptions;
}
}

// Search function
Expand Down Expand Up @@ -240,3 +252,9 @@ DataTable.ext.feature.push({
},
cFeature: 'A',
});

DataTable.feature.register('alphabetSearch', function (settings, opts) {
var search = new DataTable.AlphabetSearch(settings);

return search.node();
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $(document).on('init.dt', function (e, dtSettings) {
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();
var $paging = $(api.table().container()).find('div.dt-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') {
Expand Down
Loading

0 comments on commit 6c9c2ab

Please sign in to comment.