datatables.net-feature-alphabetsearch 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md ADDED
@@ -0,0 +1,26 @@
1
+
2
+ # DataTables input paging feature
3
+
4
+ Show an set of alphabet buttons alongside a table providing search input options.
5
+
6
+
7
+ ## Usage
8
+
9
+ To install with npm (substitute with your favorite package manager if you prefer):
10
+
11
+ ```
12
+ npm install datatables.net datatables.net-feature-alphabetsearch
13
+ ```
14
+
15
+ Then in your Javascript file (assuming you are using ES Modules):
16
+
17
+ ```js
18
+ import DataTable from 'datatables.net';
19
+ import 'datatables.net-feature-alphabetsearch';
20
+
21
+ new DataTable('#example', {
22
+ layout: {
23
+ top: 'alphabetSearch'
24
+ }
25
+ });
26
+ ```
@@ -0,0 +1,34 @@
1
+ div.alphabet {
2
+ position: relative;
3
+ display: table;
4
+ width: 100%;
5
+ margin-bottom: 1em;
6
+ }
7
+ div.alphabet span {
8
+ display: table-cell;
9
+ color: #3174c7;
10
+ cursor: pointer;
11
+ text-align: center;
12
+ }
13
+ div.alphabet span:hover {
14
+ text-decoration: underline;
15
+ }
16
+ div.alphabet span.active {
17
+ color: black;
18
+ }
19
+ div.alphabet span.empty {
20
+ color: red;
21
+ }
22
+
23
+ div.alphabetInfo {
24
+ display: block;
25
+ position: absolute;
26
+ background-color: #111;
27
+ border-radius: 3px;
28
+ color: white;
29
+ top: 2em;
30
+ height: 1.8em;
31
+ padding-top: 0.4em;
32
+ text-align: center;
33
+ z-index: 1;
34
+ }
@@ -0,0 +1,65 @@
1
+ /*! © SpryMedia Ltd - datatables.net/license */
2
+ /**
3
+ * @summary AlphabetSearch
4
+ * @description Show an set of alphabet buttons alongside a table providing
5
+ * search input options
6
+ * @author SpryMedia Ltd
7
+ * @copyright Copyright SpryMedia Ltd.
8
+ * @requires DataTables 3+
9
+ *
10
+ * License MIT - http://datatables.net/license/mit
11
+ *
12
+ * Please see [this blog post](http://datatables.net/blog/2014-09-22).
13
+ *
14
+ * @example
15
+ * new DataTable('#myTable', {
16
+ * layout: {
17
+ * top: 'alphabetSearch'
18
+ * }
19
+ * });
20
+ */
21
+ import { Api, Context, Dom } from 'datatables.net';
22
+ interface AlphabetSearchOptions {
23
+ column?: number;
24
+ caseSensitive?: boolean;
25
+ numbers?: boolean;
26
+ }
27
+ declare module 'datatables.net' {
28
+ interface DataTablesStatic {
29
+ /** Show an set of alphabet buttons alongside a table providing search input options */
30
+ AlphabetSearch: typeof AlphabetSearch;
31
+ }
32
+ interface Config {
33
+ alphabet?: AlphabetSearchOptions;
34
+ }
35
+ interface Api<T> {
36
+ alphabetSearch: ApiAlphabet<T>;
37
+ }
38
+ interface ApiAlphabet<T> {
39
+ (searchTerm: string): ApiAlphabetMethods<T>;
40
+ }
41
+ interface ApiAlphabetMethods<T> extends Api<T> {
42
+ node(): Dom | null;
43
+ recalc(): Api<T>;
44
+ }
45
+ interface Feature {
46
+ alphabetSearch?: AlphabetSearchOptions;
47
+ }
48
+ interface Context {
49
+ alphabetSearch: string;
50
+ _alphabetSearch: AlphabetSearch;
51
+ _alphabet: any;
52
+ _alphabetOptions: AlphabetSearchOptions;
53
+ }
54
+ interface Options {
55
+ alphabet: AlphabetSearchOptions;
56
+ }
57
+ }
58
+ declare class AlphabetSearch {
59
+ private _container;
60
+ constructor(context: Context);
61
+ node(): Dom<HTMLElement>;
62
+ private bin;
63
+ draw(table: Api, alphabet: Dom, options: AlphabetSearchOptions): void;
64
+ }
65
+ export {};
@@ -0,0 +1,235 @@
1
+ /*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
2
+
3
+ (function(factory){
4
+ if (typeof define === 'function' && define.amd) {
5
+ // AMD
6
+ define(['datatables.net'], function (dt) {
7
+ return factory(window, document, dt);
8
+ });
9
+ }
10
+ else if (typeof exports === 'object') {
11
+ // CommonJS
12
+ var cjsRequires = function (root) {
13
+ if (! root.DataTable) {
14
+ require('datatables.net')(root);
15
+ }
16
+ };
17
+
18
+ if (typeof window === 'undefined') {
19
+ module.exports = function (root) {
20
+ if (! root) {
21
+ // CommonJS environments without a window global must pass a
22
+ // root. This will give an error otherwise
23
+ root = window;
24
+ }
25
+
26
+ cjsRequires(root);
27
+ return factory(root, root.document, root.DataTable);
28
+ };
29
+ }
30
+ else {
31
+ cjsRequires(window);
32
+ module.exports = factory(window, window.document, window.DataTable);
33
+ }
34
+ }
35
+ else {
36
+ // Browser
37
+ factory(window, document, window.DataTable);
38
+ }
39
+ }(function(window, document, DataTable) {
40
+ 'use strict';
41
+
42
+ var Dom = DataTable.Dom;
43
+
44
+ /**
45
+ * @summary AlphabetSearch
46
+ * @description Show an set of alphabet buttons alongside a table providing
47
+ * search input options
48
+ * @author SpryMedia Ltd
49
+ * @copyright Copyright SpryMedia Ltd.
50
+ * @requires DataTables 3+
51
+ *
52
+ * License MIT - http://datatables.net/license/mit
53
+ *
54
+ * Please see [this blog post](http://datatables.net/blog/2014-09-22).
55
+ *
56
+ * @example
57
+ * new DataTable('#myTable', {
58
+ * layout: {
59
+ * top: 'alphabetSearch'
60
+ * }
61
+ * });
62
+ */
63
+ // Search function
64
+ DataTable.Api.register('alphabetSearch()', function (searchTerm) {
65
+ this.iterator('table', function (context) {
66
+ context.alphabetSearch = searchTerm;
67
+ });
68
+ return this;
69
+ });
70
+ // Recalculate the alphabet display for updated data
71
+ DataTable.Api.register('alphabetSearch.recalc()', function () {
72
+ this.iterator('table', function (context) {
73
+ context._alphabetSearch.draw(new DataTable.Api(context), context._alphabet, context._alphabetOptions);
74
+ });
75
+ return this;
76
+ });
77
+ DataTable.Api.register('alphabetSearch.node()', function () {
78
+ return this.context.length ? this.context[0]._alphabet : null;
79
+ });
80
+ // Search plug-in
81
+ DataTable.ext.search.push(function (context, searchData) {
82
+ // Ensure that there is a search applied to this table before running it
83
+ if (!context.alphabetSearch || !searchData) {
84
+ return true;
85
+ }
86
+ var columnId = 0;
87
+ var caseSensitive = false;
88
+ if (context.init.alphabet !== undefined) {
89
+ columnId =
90
+ context.init.alphabet.column !== undefined
91
+ ? context.init.alphabet.column
92
+ : 0;
93
+ caseSensitive =
94
+ context.init.alphabet.caseSensitive !== undefined
95
+ ? context.init.alphabet.caseSensitive
96
+ : false;
97
+ }
98
+ if (caseSensitive) {
99
+ if (searchData[columnId].charAt(0) === context.alphabetSearch) {
100
+ return true;
101
+ }
102
+ }
103
+ else {
104
+ if (searchData[columnId].charAt(0).toUpperCase() ===
105
+ context.alphabetSearch) {
106
+ return true;
107
+ }
108
+ }
109
+ return false;
110
+ });
111
+ class AlphabetSearch {
112
+ constructor(context) {
113
+ var table = new DataTable.Api(context);
114
+ var alphabet = Dom.c('div').classAdd('alphabet');
115
+ var options = Object.assign({
116
+ column: 0,
117
+ caseSensitive: false,
118
+ numbers: false
119
+ }, table.init().alphabet);
120
+ this._container = alphabet;
121
+ this.draw(table, alphabet, options);
122
+ context._alphabetSearch = this;
123
+ context._alphabet = alphabet;
124
+ context._alphabetOptions = options;
125
+ // Trigger a search
126
+ alphabet.on('click', 'span', function () {
127
+ alphabet.find('.active').classRemove('active');
128
+ Dom.s(this).classAdd('active');
129
+ table.alphabetSearch(Dom.s(this).data('letter')).draw();
130
+ });
131
+ // Mouse events to show helper information
132
+ alphabet
133
+ .on('mouseenter', 'span', function () {
134
+ alphabet
135
+ .find('div.alphabetInfo')
136
+ .css({
137
+ opacity: '1',
138
+ left: Dom.s(this).position().left + 'px',
139
+ width: Dom.s(this).width() + 'px'
140
+ })
141
+ .html(Dom.s(this).data('matchCount'));
142
+ })
143
+ .on('mouseleave', 'span', function () {
144
+ alphabet.find('div.alphabetInfo').css('opacity', '0');
145
+ });
146
+ }
147
+ node() {
148
+ return this._container;
149
+ }
150
+ // Private support methods
151
+ bin(data, options) {
152
+ var letter, bins = {};
153
+ for (var i = 0, ien = data.length; i < ien; i++) {
154
+ if (options.caseSensitive) {
155
+ letter = data[i].toString().replace(/<.*?>/g, '').charAt(0);
156
+ }
157
+ else {
158
+ letter = data[i]
159
+ .toString()
160
+ .replace(/<.*?>/g, '')
161
+ .charAt(0)
162
+ .toUpperCase();
163
+ }
164
+ if (bins[letter]) {
165
+ bins[letter]++;
166
+ }
167
+ else {
168
+ bins[letter] = 1;
169
+ }
170
+ }
171
+ return bins;
172
+ }
173
+ draw(table, alphabet, options) {
174
+ alphabet.empty();
175
+ alphabet.append('Search: ');
176
+ var columnData = table.column(options.column || '*').data();
177
+ var bins = this.bin(columnData, options);
178
+ Dom.c('span')
179
+ .classAdd('clear active')
180
+ .data('letter', '')
181
+ .data('matchCount', columnData.length)
182
+ .html('None')
183
+ .appendTo(alphabet);
184
+ if (options.numbers) {
185
+ for (var i = 0; i < 10; i++) {
186
+ var letter = String.fromCharCode(48 + i);
187
+ Dom.c('span')
188
+ .data('letter', letter)
189
+ .data('matchCount', bins[letter] || 0)
190
+ .classAdd(!bins[letter] ? 'empty' : '')
191
+ .html(letter)
192
+ .appendTo(alphabet);
193
+ }
194
+ }
195
+ for (var i = 0; i < 26; i++) {
196
+ var letter = String.fromCharCode(65 + i);
197
+ Dom.c('span')
198
+ .data('letter', letter)
199
+ .data('matchCount', bins[letter] || 0)
200
+ .classAdd(!bins[letter] ? 'empty' : '')
201
+ .html(letter)
202
+ .appendTo(alphabet);
203
+ }
204
+ if (options.caseSensitive) {
205
+ for (var i = 0; i < 26; i++) {
206
+ var letter = String.fromCharCode(97 + i);
207
+ Dom.c('span')
208
+ .data('letter', letter)
209
+ .data('matchCount', bins[letter] || 0)
210
+ .classAdd(!bins[letter] ? 'empty' : '')
211
+ .html(letter)
212
+ .appendTo(alphabet);
213
+ }
214
+ }
215
+ Dom.c('div').classAdd('alphabetInfo').appendTo(alphabet);
216
+ }
217
+ }
218
+ DataTable.AlphabetSearch = AlphabetSearch;
219
+ // Legacy dom option
220
+ DataTable.ext.feature.push({
221
+ fnInit: function (settings) {
222
+ var search = new DataTable.AlphabetSearch(settings);
223
+ return search.node();
224
+ },
225
+ cFeature: 'A'
226
+ });
227
+ // Feature registration
228
+ DataTable.feature.register('alphabetSearch', function (settings, opts) {
229
+ var search = new DataTable.AlphabetSearch(settings);
230
+ return search.node();
231
+ });
232
+
233
+
234
+ return DataTable;
235
+ }));
@@ -0,0 +1 @@
1
+ div.alphabet{position:relative;display:table;width:100%;margin-bottom:1em}div.alphabet span{display:table-cell;color:#3174c7;cursor:pointer;text-align:center}div.alphabet span:hover{text-decoration:underline}div.alphabet span.active{color:black}div.alphabet span.empty{color:red}div.alphabetInfo{display:block;position:absolute;background-color:#111;border-radius:3px;color:white;top:2em;height:1.8em;padding-top:.4em;text-align:center;z-index:1}
@@ -0,0 +1,2 @@
1
+ /*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
2
+ (e=>{var a;"function"==typeof define&&define.amd?define(["datatables.net"],function(t){return e(window,document,t)}):"object"==typeof exports?(a=function(t){t.DataTable||require("datatables.net")(t)},"undefined"==typeof window?module.exports=function(t){return t=t||window,a(t),e(0,t.document,t.DataTable)}:(a(window),module.exports=e(window,window.document,window.DataTable))):e(window,document,window.DataTable)})(function(t,e,i){var o=i.Dom;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){t._alphabetSearch.draw(new i.Api(t),t._alphabet,t._alphabetOptions)}),this}),i.Api.register("alphabetSearch.node()",function(){return this.context.length?this.context[0]._alphabet:null}),i.ext.search.push(function(t,e){if(!t.alphabetSearch||!e)return!0;var a=0,n=!1;if(void 0!==t.init.alphabet&&(a=void 0!==t.init.alphabet.column?t.init.alphabet.column:0,n=void 0!==t.init.alphabet.caseSensitive&&t.init.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});return i.AlphabetSearch=class{constructor(t){var e=new i.Api(t),a=o.c("div").classAdd("alphabet"),n=Object.assign({column:0,caseSensitive:!1,numbers:!1},e.init().alphabet);this._container=a,this.draw(e,a,n),t._alphabetSearch=this,t._alphabet=a,t._alphabetOptions=n,a.on("click","span",function(){a.find(".active").classRemove("active"),o.s(this).classAdd("active"),e.alphabetSearch(o.s(this).data("letter")).draw()}),a.on("mouseenter","span",function(){a.find("div.alphabetInfo").css({opacity:"1",left:o.s(this).position().left+"px",width:o.s(this).width()+"px"}).html(o.s(this).data("matchCount"))}).on("mouseleave","span",function(){a.find("div.alphabetInfo").css("opacity","0")})}node(){return this._container}bin(t,e){for(var a,n={},i=0,r=t.length;i<r;i++)n[a=e.caseSensitive?t[i].toString().replace(/<.*?>/g,"").charAt(0):t[i].toString().replace(/<.*?>/g,"").charAt(0).toUpperCase()]?n[a]++:n[a]=1;return n}draw(t,e,a){e.empty(),e.append("Search: ");var t=t.column(a.column||"*").data(),n=this.bin(t,a);if(o.c("span").classAdd("clear active").data("letter","").data("matchCount",t.length).html("None").appendTo(e),a.numbers)for(var i=0;i<10;i++){var r=String.fromCharCode(48+i);o.c("span").data("letter",r).data("matchCount",n[r]||0).classAdd(n[r]?"":"empty").html(r).appendTo(e)}for(i=0;i<26;i++){r=String.fromCharCode(65+i);o.c("span").data("letter",r).data("matchCount",n[r]||0).classAdd(n[r]?"":"empty").html(r).appendTo(e)}if(a.caseSensitive)for(i=0;i<26;i++){r=String.fromCharCode(97+i);o.c("span").data("letter",r).data("matchCount",n[r]||0).classAdd(n[r]?"":"empty").html(r).appendTo(e)}o.c("div").classAdd("alphabetInfo").appendTo(e)}},i.ext.feature.push({fnInit:function(t){return new i.AlphabetSearch(t).node()},cFeature:"A"}),i.feature.register("alphabetSearch",function(t,e){return new i.AlphabetSearch(t).node()}),i});
@@ -0,0 +1,2 @@
1
+ /*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
2
+ import DataTable,{Dom}from"datatables.net";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){a._alphabetSearch.draw(new DataTable.Api(a),a._alphabet,a._alphabetOptions)}),this}),DataTable.Api.register("alphabetSearch.node()",function(){return this.context.length?this.context[0]._alphabet:null}),DataTable.ext.search.push(function(a,t){if(!a.alphabetSearch||!t)return!0;var e=0,n=!1;if(void 0!==a.init.alphabet&&(e=void 0!==a.init.alphabet.column?a.init.alphabet.column:0,n=void 0!==a.init.alphabet.caseSensitive&&a.init.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});class AlphabetSearch{constructor(a){var t=new DataTable.Api(a),e=Dom.c("div").classAdd("alphabet"),n=Object.assign({column:0,caseSensitive:!1,numbers:!1},t.init().alphabet);this._container=e,this.draw(t,e,n),a._alphabetSearch=this,a._alphabet=e,a._alphabetOptions=n,e.on("click","span",function(){e.find(".active").classRemove("active"),Dom.s(this).classAdd("active"),t.alphabetSearch(Dom.s(this).data("letter")).draw()}),e.on("mouseenter","span",function(){e.find("div.alphabetInfo").css({opacity:"1",left:Dom.s(this).position().left+"px",width:Dom.s(this).width()+"px"}).html(Dom.s(this).data("matchCount"))}).on("mouseleave","span",function(){e.find("div.alphabetInfo").css("opacity","0")})}node(){return this._container}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}draw(a,t,e){t.empty(),t.append("Search: ");var a=a.column(e.column||"*").data(),n=this.bin(a,e);if(Dom.c("span").classAdd("clear active").data("letter","").data("matchCount",a.length).html("None").appendTo(t),e.numbers)for(var r=0;r<10;r++){var i=String.fromCharCode(48+r);Dom.c("span").data("letter",i).data("matchCount",n[i]||0).classAdd(n[i]?"":"empty").html(i).appendTo(t)}for(r=0;r<26;r++){i=String.fromCharCode(65+r);Dom.c("span").data("letter",i).data("matchCount",n[i]||0).classAdd(n[i]?"":"empty").html(i).appendTo(t)}if(e.caseSensitive)for(r=0;r<26;r++){i=String.fromCharCode(97+r);Dom.c("span").data("letter",i).data("matchCount",n[i]||0).classAdd(n[i]?"":"empty").html(i).appendTo(t)}Dom.c("div").classAdd("alphabetInfo").appendTo(t)}}DataTable.AlphabetSearch=AlphabetSearch,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;
@@ -0,0 +1,196 @@
1
+ /*! © SpryMedia Ltd - datatables.net/license - 3.0.0-beta.2 */
2
+
3
+ import DataTable, { Dom } from 'datatables.net';
4
+
5
+ /**
6
+ * @summary AlphabetSearch
7
+ * @description Show an set of alphabet buttons alongside a table providing
8
+ * search input options
9
+ * @author SpryMedia Ltd
10
+ * @copyright Copyright SpryMedia Ltd.
11
+ * @requires DataTables 3+
12
+ *
13
+ * License MIT - http://datatables.net/license/mit
14
+ *
15
+ * Please see [this blog post](http://datatables.net/blog/2014-09-22).
16
+ *
17
+ * @example
18
+ * new DataTable('#myTable', {
19
+ * layout: {
20
+ * top: 'alphabetSearch'
21
+ * }
22
+ * });
23
+ */
24
+ // Search function
25
+ DataTable.Api.register('alphabetSearch()', function (searchTerm) {
26
+ this.iterator('table', function (context) {
27
+ context.alphabetSearch = searchTerm;
28
+ });
29
+ return this;
30
+ });
31
+ // Recalculate the alphabet display for updated data
32
+ DataTable.Api.register('alphabetSearch.recalc()', function () {
33
+ this.iterator('table', function (context) {
34
+ context._alphabetSearch.draw(new DataTable.Api(context), context._alphabet, context._alphabetOptions);
35
+ });
36
+ return this;
37
+ });
38
+ DataTable.Api.register('alphabetSearch.node()', function () {
39
+ return this.context.length ? this.context[0]._alphabet : null;
40
+ });
41
+ // Search plug-in
42
+ DataTable.ext.search.push(function (context, searchData) {
43
+ // Ensure that there is a search applied to this table before running it
44
+ if (!context.alphabetSearch || !searchData) {
45
+ return true;
46
+ }
47
+ var columnId = 0;
48
+ var caseSensitive = false;
49
+ if (context.init.alphabet !== undefined) {
50
+ columnId =
51
+ context.init.alphabet.column !== undefined
52
+ ? context.init.alphabet.column
53
+ : 0;
54
+ caseSensitive =
55
+ context.init.alphabet.caseSensitive !== undefined
56
+ ? context.init.alphabet.caseSensitive
57
+ : false;
58
+ }
59
+ if (caseSensitive) {
60
+ if (searchData[columnId].charAt(0) === context.alphabetSearch) {
61
+ return true;
62
+ }
63
+ }
64
+ else {
65
+ if (searchData[columnId].charAt(0).toUpperCase() ===
66
+ context.alphabetSearch) {
67
+ return true;
68
+ }
69
+ }
70
+ return false;
71
+ });
72
+ class AlphabetSearch {
73
+ constructor(context) {
74
+ var table = new DataTable.Api(context);
75
+ var alphabet = Dom.c('div').classAdd('alphabet');
76
+ var options = Object.assign({
77
+ column: 0,
78
+ caseSensitive: false,
79
+ numbers: false
80
+ }, table.init().alphabet);
81
+ this._container = alphabet;
82
+ this.draw(table, alphabet, options);
83
+ context._alphabetSearch = this;
84
+ context._alphabet = alphabet;
85
+ context._alphabetOptions = options;
86
+ // Trigger a search
87
+ alphabet.on('click', 'span', function () {
88
+ alphabet.find('.active').classRemove('active');
89
+ Dom.s(this).classAdd('active');
90
+ table.alphabetSearch(Dom.s(this).data('letter')).draw();
91
+ });
92
+ // Mouse events to show helper information
93
+ alphabet
94
+ .on('mouseenter', 'span', function () {
95
+ alphabet
96
+ .find('div.alphabetInfo')
97
+ .css({
98
+ opacity: '1',
99
+ left: Dom.s(this).position().left + 'px',
100
+ width: Dom.s(this).width() + 'px'
101
+ })
102
+ .html(Dom.s(this).data('matchCount'));
103
+ })
104
+ .on('mouseleave', 'span', function () {
105
+ alphabet.find('div.alphabetInfo').css('opacity', '0');
106
+ });
107
+ }
108
+ node() {
109
+ return this._container;
110
+ }
111
+ // Private support methods
112
+ bin(data, options) {
113
+ var letter, bins = {};
114
+ for (var i = 0, ien = data.length; i < ien; i++) {
115
+ if (options.caseSensitive) {
116
+ letter = data[i].toString().replace(/<.*?>/g, '').charAt(0);
117
+ }
118
+ else {
119
+ letter = data[i]
120
+ .toString()
121
+ .replace(/<.*?>/g, '')
122
+ .charAt(0)
123
+ .toUpperCase();
124
+ }
125
+ if (bins[letter]) {
126
+ bins[letter]++;
127
+ }
128
+ else {
129
+ bins[letter] = 1;
130
+ }
131
+ }
132
+ return bins;
133
+ }
134
+ draw(table, alphabet, options) {
135
+ alphabet.empty();
136
+ alphabet.append('Search: ');
137
+ var columnData = table.column(options.column || '*').data();
138
+ var bins = this.bin(columnData, options);
139
+ Dom.c('span')
140
+ .classAdd('clear active')
141
+ .data('letter', '')
142
+ .data('matchCount', columnData.length)
143
+ .html('None')
144
+ .appendTo(alphabet);
145
+ if (options.numbers) {
146
+ for (var i = 0; i < 10; i++) {
147
+ var letter = String.fromCharCode(48 + i);
148
+ Dom.c('span')
149
+ .data('letter', letter)
150
+ .data('matchCount', bins[letter] || 0)
151
+ .classAdd(!bins[letter] ? 'empty' : '')
152
+ .html(letter)
153
+ .appendTo(alphabet);
154
+ }
155
+ }
156
+ for (var i = 0; i < 26; i++) {
157
+ var letter = String.fromCharCode(65 + i);
158
+ Dom.c('span')
159
+ .data('letter', letter)
160
+ .data('matchCount', bins[letter] || 0)
161
+ .classAdd(!bins[letter] ? 'empty' : '')
162
+ .html(letter)
163
+ .appendTo(alphabet);
164
+ }
165
+ if (options.caseSensitive) {
166
+ for (var i = 0; i < 26; i++) {
167
+ var letter = String.fromCharCode(97 + i);
168
+ Dom.c('span')
169
+ .data('letter', letter)
170
+ .data('matchCount', bins[letter] || 0)
171
+ .classAdd(!bins[letter] ? 'empty' : '')
172
+ .html(letter)
173
+ .appendTo(alphabet);
174
+ }
175
+ }
176
+ Dom.c('div').classAdd('alphabetInfo').appendTo(alphabet);
177
+ }
178
+ }
179
+ DataTable.AlphabetSearch = AlphabetSearch;
180
+ // Legacy dom option
181
+ DataTable.ext.feature.push({
182
+ fnInit: function (settings) {
183
+ var search = new DataTable.AlphabetSearch(settings);
184
+ return search.node();
185
+ },
186
+ cFeature: 'A'
187
+ });
188
+ // Feature registration
189
+ DataTable.feature.register('alphabetSearch', function (settings, opts) {
190
+ var search = new DataTable.AlphabetSearch(settings);
191
+ return search.node();
192
+ });
193
+
194
+
195
+ export default DataTable;
196
+
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "datatables.net-feature-alphabetsearch",
3
+ "version": "1.0.0",
4
+ "description": "DataTables plugin: An alphabet search input control",
5
+ "main": "dist/dataTables.alphabetSearch.js",
6
+ "module": "dist/dataTables.alphabetSearch.mjs",
7
+ "style": "dist/dataTables.alphabetSearch.css",
8
+ "types": "dist/dataTables.alphabetSearch.d.ts",
9
+ "files": [
10
+ "dist/*.css",
11
+ "dist/*.js",
12
+ "dist/*.mjs",
13
+ "dist/*.d.ts"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/DataTables/Plugins.git"
18
+ },
19
+ "keywords": [
20
+ "DataTables",
21
+ "plugins"
22
+ ],
23
+ "author": "SpryMedia Ltd",
24
+ "license": "MIT",
25
+ "bugs": {
26
+ "url": "https://datatables.net/forums"
27
+ },
28
+ "homepage": "https://datatables.net",
29
+ "dependencies": {
30
+ "datatables.net": "^3.0.0-0"
31
+ }
32
+ }