diff --git a/features/searchPane/customOptions.html b/features/searchPane/customOptions.html
new file mode 100644
index 0000000..22c58d5
--- /dev/null
+++ b/features/searchPane/customOptions.html
@@ -0,0 +1,537 @@
+
+
+
+
+
+ DataTables search pane example
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Position |
+ Office |
+ Age |
+ Start date |
+ Salary |
+
+
+
+
+
+ Name |
+ Position |
+ Office |
+ Age |
+ Start date |
+ Salary |
+
+
+
+
+
+ Tiger Nixon |
+ System Architect |
+ Edinburgh |
+ 61 |
+ 2011/04/25 |
+ $320,800 |
+
+
+ Garrett Winters |
+ Accountant |
+ Tokyo |
+ 63 |
+ 2011/07/25 |
+ $170,750 |
+
+
+ Ashton Cox |
+ Junior Technical Author |
+ San Francisco |
+ 66 |
+ 2009/01/12 |
+ $86,000 |
+
+
+ Cedric Kelly |
+ Senior Javascript Developer |
+ Edinburgh |
+ 22 |
+ 2012/03/29 |
+ $433,060 |
+
+
+ Airi Satou |
+ Accountant |
+ Tokyo |
+ 33 |
+ 2008/11/28 |
+ $162,700 |
+
+
+ Brielle Williamson |
+ Integration Specialist |
+ New York |
+ 61 |
+ 2012/12/02 |
+ $372,000 |
+
+
+ Herrod Chandler |
+ Sales Assistant |
+ San Francisco |
+ 59 |
+ 2012/08/06 |
+ $137,500 |
+
+
+ Rhona Davidson |
+ Integration Specialist |
+ Tokyo |
+ 55 |
+ 2010/10/14 |
+ $327,900 |
+
+
+ Colleen Hurst |
+ Javascript Developer |
+ San Francisco |
+ 39 |
+ 2009/09/15 |
+ $205,500 |
+
+
+ Sonya Frost |
+ Software Engineer |
+ Edinburgh |
+ 23 |
+ 2008/12/13 |
+ $103,600 |
+
+
+ Jena Gaines |
+ Office Manager |
+ London |
+ 30 |
+ 2008/12/19 |
+ $90,560 |
+
+
+ Quinn Flynn |
+ Support Lead |
+ Edinburgh |
+ 22 |
+ 2013/03/03 |
+ $342,000 |
+
+
+ Charde Marshall |
+ Regional Director |
+ San Francisco |
+ 36 |
+ 2008/10/16 |
+ $470,600 |
+
+
+ Haley Kennedy |
+ Senior Marketing Designer |
+ London |
+ 43 |
+ 2012/12/18 |
+ $313,500 |
+
+
+ Tatyana Fitzpatrick |
+ Regional Director |
+ London |
+ 19 |
+ 2010/03/17 |
+ $385,750 |
+
+
+ Michael Silva |
+ Marketing Designer |
+ London |
+ 66 |
+ 2012/11/27 |
+ $198,500 |
+
+
+ Paul Byrd |
+ Chief Financial Officer (CFO) |
+ New York |
+ 64 |
+ 2010/06/09 |
+ $725,000 |
+
+
+ Gloria Little |
+ Systems Administrator |
+ New York |
+ 59 |
+ 2009/04/10 |
+ $237,500 |
+
+
+ Bradley Greer |
+ Software Engineer |
+ London |
+ 41 |
+ 2012/10/13 |
+ $132,000 |
+
+
+ Dai Rios |
+ Personnel Lead |
+ Edinburgh |
+ 35 |
+ 2012/09/26 |
+ $217,500 |
+
+
+ Jenette Caldwell |
+ Development Lead |
+ New York |
+ 30 |
+ 2011/09/03 |
+ $345,000 |
+
+
+ Yuri Berry |
+ Chief Marketing Officer (CMO) |
+ New York |
+ 40 |
+ 2009/06/25 |
+ $675,000 |
+
+
+ Caesar Vance |
+ Pre-Sales Support |
+ New York |
+ 21 |
+ 2011/12/12 |
+ $106,450 |
+
+
+ Doris Wilder |
+ Sales Assistant |
+ Sidney |
+ 23 |
+ 2010/09/20 |
+ $85,600 |
+
+
+ Angelica Ramos |
+ Chief Executive Officer (CEO) |
+ London |
+ 47 |
+ 2009/10/09 |
+ $1,200,000 |
+
+
+ Gavin Joyce |
+ Developer |
+ Edinburgh |
+ 42 |
+ 2010/12/22 |
+ $92,575 |
+
+
+ Jennifer Chang |
+ Regional Director |
+ Singapore |
+ 28 |
+ 2010/11/14 |
+ $357,650 |
+
+
+ Brenden Wagner |
+ Software Engineer |
+ San Francisco |
+ 28 |
+ 2011/06/07 |
+ $206,850 |
+
+
+ Fiona Green |
+ Chief Operating Officer (COO) |
+ San Francisco |
+ 48 |
+ 2010/03/11 |
+ $850,000 |
+
+
+ Shou Itou |
+ Regional Marketing |
+ Tokyo |
+ 20 |
+ 2011/08/14 |
+ $163,000 |
+
+
+ Michelle House |
+ Integration Specialist |
+ Sidney |
+ 37 |
+ 2011/06/02 |
+ $95,400 |
+
+
+ Suki Burks |
+ Developer |
+ London |
+ 53 |
+ 2009/10/22 |
+ $114,500 |
+
+
+ Prescott Bartlett |
+ Technical Author |
+ London |
+ 27 |
+ 2011/05/07 |
+ $145,000 |
+
+
+ Gavin Cortez |
+ Team Leader |
+ San Francisco |
+ 22 |
+ 2008/10/26 |
+ $235,500 |
+
+
+ Martena Mccray |
+ Post-Sales support |
+ Edinburgh |
+ 46 |
+ 2011/03/09 |
+ $324,050 |
+
+
+ Unity Butler |
+ Marketing Designer |
+ San Francisco |
+ 47 |
+ 2009/12/09 |
+ $85,675 |
+
+
+ Howard Hatfield |
+ Office Manager |
+ San Francisco |
+ 51 |
+ 2008/12/16 |
+ $164,500 |
+
+
+ Hope Fuentes |
+ Secretary |
+ San Francisco |
+ 41 |
+ 2010/02/12 |
+ $109,850 |
+
+
+ Vivian Harrell |
+ Financial Controller |
+ San Francisco |
+ 62 |
+ 2009/02/14 |
+ $452,500 |
+
+
+ Timothy Mooney |
+ Office Manager |
+ London |
+ 37 |
+ 2008/12/11 |
+ $136,200 |
+
+
+ Jackson Bradshaw |
+ Director |
+ New York |
+ 65 |
+ 2008/09/26 |
+ $645,750 |
+
+
+ Olivia Liang |
+ Support Engineer |
+ Singapore |
+ 64 |
+ 2011/02/03 |
+ $234,500 |
+
+
+ Bruno Nash |
+ Software Engineer |
+ London |
+ 38 |
+ 2011/05/03 |
+ $163,500 |
+
+
+ Sakura Yamamoto |
+ Support Engineer |
+ Tokyo |
+ 37 |
+ 2009/08/19 |
+ $139,575 |
+
+
+ Thor Walton |
+ Developer |
+ New York |
+ 61 |
+ 2013/08/11 |
+ $98,540 |
+
+
+ Finn Camacho |
+ Support Engineer |
+ San Francisco |
+ 47 |
+ 2009/07/07 |
+ $87,500 |
+
+
+ Serge Baldwin |
+ Data Coordinator |
+ Singapore |
+ 64 |
+ 2012/04/09 |
+ $138,575 |
+
+
+ Zenaida Frank |
+ Software Engineer |
+ New York |
+ 63 |
+ 2010/01/04 |
+ $125,250 |
+
+
+ Zorita Serrano |
+ Software Engineer |
+ San Francisco |
+ 56 |
+ 2012/06/01 |
+ $115,000 |
+
+
+ Jennifer Acosta |
+ Junior Javascript Developer |
+ Edinburgh |
+ 43 |
+ 2013/02/01 |
+ $75,650 |
+
+
+ Cara Stevens |
+ Sales Assistant |
+ New York |
+ 46 |
+ 2011/12/06 |
+ $145,600 |
+
+
+ Hermione Butler |
+ Regional Director |
+ London |
+ 47 |
+ 2011/03/21 |
+ $356,250 |
+
+
+ Lael Greer |
+ Systems Administrator |
+ London |
+ 21 |
+ 2009/02/27 |
+ $103,500 |
+
+
+ Jonas Alexander |
+ Developer |
+ San Francisco |
+ 30 |
+ 2010/07/14 |
+ $86,500 |
+
+
+ Shad Decker |
+ Regional Director |
+ Edinburgh |
+ 51 |
+ 2008/11/13 |
+ $183,000 |
+
+
+ Michael Bruce |
+ Javascript Developer |
+ Singapore |
+ 29 |
+ 2011/06/27 |
+ $183,000 |
+
+
+ Donna Snider |
+ Customer Support |
+ New York |
+ 27 |
+ 2011/01/25 |
+ $112,000 |
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/features/searchPane/dataTables.searchPane.js b/features/searchPane/dataTables.searchPane.js
index 31fffd7..125c69d 100644
--- a/features/searchPane/dataTables.searchPane.js
+++ b/features/searchPane/dataTables.searchPane.js
@@ -95,8 +95,7 @@
_attach: function() {
var container = this.c.container;
- var host =
- typeof container === 'function' ? container(this.s.dt) : container;
+ var host = typeof container === 'function' ? container(this.s.dt) : container;
if (this.c.insert === 'prepend') {
$(this.dom.container).prependTo(host);
@@ -108,7 +107,9 @@
_binData: function(data) {
var out = {};
- data.each(function(d) {
+ for (var i = 0, ien = data.length; i < ien; i++) {
+ var d = data[i];
+
if (!d) {
return;
}
@@ -118,7 +119,7 @@
} else {
out[d]++;
}
- });
+ }
return out;
},
@@ -142,8 +143,10 @@
var paneClasses = classes.pane;
var table = this.s.dt;
var column = table.column(idx);
+ var colOpts = this._getOptions(idx);
var list = $('');
- var bins = this._binData(column.data().flatten());
+ var binData = colOpts.options ? new DataTable.Api(null, colOpts.options) : column.data();
+ var bins = this._binData(binData.flatten());
// Don't show the pane if there isn't enough variance in the data
if (this._variance(bins) < this.c.threshold) {
@@ -155,8 +158,7 @@
var search = column.search();
search = search ? search.substr(1, search.length - 2).split('|') : [];
- var data = column
- .data()
+ var data = binData
.unique()
.sort()
.toArray();
@@ -164,9 +166,7 @@
for (var i = 0, ien = data.length; i < ien; i++) {
if (data[i]) {
var li = $('')
- .html(
- '' + data[i] + ''
- )
+ .html('' + data[i] + '')
.data('filter', data[i])
.append(
$('')
@@ -175,9 +175,7 @@
);
if (search.length) {
- var escaped = data[i].replace
- ? $.fn.dataTable.util.escapeRegex(data[i])
- : data[i];
+ var escaped = data[i].replace ? $.fn.dataTable.util.escapeRegex(data[i]) : data[i];
if ($.inArray(escaped, search) !== -1) {
li.addClass(itemClasses.selected);
@@ -192,11 +190,7 @@
.data('column', idx)
.addClass(paneClasses.container)
.addClass(search.length ? paneClasses.active : '')
- .append(
- $('').addClass(
- this.classes.clear
- )
- )
+ .append($('').addClass(this.classes.clear))
.append(
$('')
.addClass(paneClasses.title)
@@ -222,12 +216,20 @@
}
},
+ _getOptions: function ( colIdx ) {
+ var table = this.s.dt;
+
+ return table.settings()[0].aoColumns[colIdx].searchPane || {};
+ },
+
_toggle: function(li) {
var classes = this.classes;
var itemSelected = classes.item.selected;
var table = this.s.dt;
var li = $(li);
var pane = li.closest('div.' + classes.pane.container);
+ var columnIdx = pane.data('column');
+ var options = this._getOptions(columnIdx);
li.toggleClass(itemSelected, !li.hasClass(itemSelected));
@@ -236,13 +238,32 @@
if (filters.length === 0) {
pane.removeClass(classes.pane.active);
table
- .column(pane.data('column'))
+ .column(columnIdx)
.search('')
.draw();
+ } else if (options.match === 'any') {
+ // Allow sub-word matching
+ pane.addClass(classes.pane.active);
+ table
+ .column(columnIdx)
+ .search(
+ '(' +
+ $.map(filters, function(filter) {
+ var d = $(filter)
+ .data('filter')
+ .toString();
+ return $.fn.dataTable.util.escapeRegex(d);
+ }).join('|') +
+ ')',
+ true,
+ false
+ )
+ .draw();
} else {
+ // Only search on the full phrase
pane.addClass(classes.pane.active);
table
- .column(pane.data('column'))
+ .column(columnIdx)
.search(
'^(' +
$.map(filters, function(filter) {
@@ -318,6 +339,21 @@
});
});
+ DataTable.Api.register('column().paneOptions()', function(options) {
+ return this.iterator('column', function(ctx, idx) {
+ var col = ctx.aoColumns[idx];
+
+ if (ctx.searchPane) {
+ if (!col.searchPane) {
+ col.searchPane = {};
+ }
+
+ col.searchPane.options = options;
+ ctx.searchPane.rebuild();
+ }
+ });
+ });
+
$(document).on('init.dt', function(e, settings, json) {
if (e.namespace !== 'dt') {
return;
diff --git a/features/searchPane/dataTables.searchPane.min.js b/features/searchPane/dataTables.searchPane.min.js
index f84a6fe..e63d60b 100644
--- a/features/searchPane/dataTables.searchPane.min.js
+++ b/features/searchPane/dataTables.searchPane.min.js
@@ -1,12 +1,26 @@
/*!
+ Copyright 2017 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
SearchPane 0.0.1
2017 SpryMedia Ltd - datatables.net/license
*/
-(function(b){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(d){return b(d,window,document)}):"object"===typeof exports?module.exports=function(d,h){d||(d=window);if(!h||!h.fn.dataTable)h=require("datatables.net")(d,h).$;return b(h,d,d.document)}:b(jQuery,window,document)})(function(b,d,h,k){function f(a,c){var g=this,e=new j.Api(a);this.classes=b.extend(!0,{},f.classes);this.dom={container:b("").addClass(this.classes.container)};this.c=b.extend(!0,{},f.defaults,
-c);this.s={dt:e};e.settings()[0].searchPane=this;e.columns(this.c.columns).eq(0).each(function(a){g._pane(a)});b(this.dom.container).on("click","li",function(){g._toggle(this)}).on("click","button."+this.classes.clear,function(){g._clear(b(this).closest("div."+g.classes.pane.container))});this._attach()}var j=b.fn.dataTable;b.extend(f.prototype,{rebuild:function(){var a=this;this.s.dt.columns(this.c.columns).eq(0).each(function(c){a._pane(c)})},_attach:function(){var a=this.c.container,a="function"===
-typeof a?a(this.s.dt):a;"prepend"===this.c.insert?b(this.dom.container).prependTo(a):b(this.dom.container).appendTo(a)},_binData:function(a){var c={};a.each(function(a){a&&(c[a]?c[a]++:c[a]=1)});return c},_clear:function(a){var c=this.classes,b=c.item.selected;a.find("li."+b).removeClass(b);a.removeClass(c.pane.active);this.s.dt.column(a.data("column")).search("").draw()},_pane:function(a){var c=this.classes,g=c.item,c=c.pane,e=this.s.dt.column(a),l=b(""),m=this._binData(e.data().flatten());
-if(!(this._variance(m)").html(''+d[i]+"").data("filter",d[i]).append(b("").addClass(g.count).html(m[d[i]]));if(f.length){var k=d[i].replace?b.fn.dataTable.util.escapeRegex(d[i]):d[i];-1!==b.inArray(k,f)&&j.addClass(g.selected)}l.append(j)}g=b("").data("column",a).addClass(c.container).addClass(f.length?
-c.active:"").append(b('').addClass(this.classes.clear)).append(b("").addClass(c.title).html(b(e.header()).text())).append(b("").addClass(c.scroller).append(l));c=this.dom.container;e=c.children().map(function(){if(b(this).data("column")==a)return this});e.length?e.replaceWith(g):b(c).append(g)}},_toggle:function(a){var c=this.classes,g=c.item.selected,e=this.s.dt,a=b(a),d=a.closest("div."+c.pane.container);a.toggleClass(g,!a.hasClass(g));a=d.find("li."+
-g);0===a.length?(d.removeClass(c.pane.active),e.column(d.data("column")).search("").draw()):(d.addClass(c.pane.active),e.column(d.data("column")).search("^("+b.map(a,function(a){a=b(a).data("filter").toString();return b.fn.dataTable.util.escapeRegex(a)}).join("|")+")$",!0,!1).draw())},_variance:function(a){for(var a=b.map(a,function(a){return a}),c=a.length,g=0,e=0,d=c;e").addClass(this.classes.container)};this.c=a.extend(!0,{},d.defaults,
+h);this.s={dt:b};b.settings()[0].searchPane=this;b.columns(this.c.columns).eq(0).each(function(a){e._pane(a)});a(this.dom.container).on("click","li",function(){e._toggle(this)}).on("click","button."+this.classes.clear,function(){e._clear(a(this).closest("div."+e.classes.pane.container))});this._attach()}var k=a.fn.dataTable;a.extend(d.prototype,{rebuild:function(){var a=this;this.s.dt.columns(this.c.columns).eq(0).each(function(b){a._pane(b)})},_attach:function(){var b=this.c.container,b="function"===
+typeof b?b(this.s.dt):b;"prepend"===this.c.insert?a(this.dom.container).prependTo(b):a(this.dom.container).appendTo(b)},_binData:function(a){for(var b={},e=0,c=a.length;e"),d=l.options?new k.Api(null,l.options):c.data(),l=this._binData(d.flatten());if(!(this._variance(l)").html(''+d[g]+"").data("filter",d[g]).append(a("").addClass(e.count).html(l[d[g]]));if(m.length){var q=d[g].replace?a.fn.dataTable.util.escapeRegex(d[g]):d[g];-1!==a.inArray(q,m)&&n.addClass(e.selected)}f.append(n)}e=
+a("").data("column",b).addClass(h.container).addClass(m.length?h.active:"").append(a('').addClass(this.classes.clear)).append(a("").addClass(h.title).html(a(c.header()).text())).append(a("").addClass(h.scroller).append(f));h=this.dom.container;c=h.children().map(function(){if(a(this).data("column")==b)return this});c.length?c.replaceWith(e):a(h).append(e)}},_getOptions:function(a){return this.s.dt.settings()[0].aoColumns[a].searchPane||{}},_toggle:function(b){var d=
+this.classes,e=d.item.selected,c=this.s.dt;b=a(b);var f=b.closest("div."+d.pane.container),g=f.data("column"),k=this._getOptions(g);b.toggleClass(e,!b.hasClass(e));b=f.find("li."+e);0===b.length?(f.removeClass(d.pane.active),c.column(g).search("").draw()):"any"===k.match?(f.addClass(d.pane.active),c.column(g).search("("+a.map(b,function(b){b=a(b).data("filter").toString();return a.fn.dataTable.util.escapeRegex(b)}).join("|")+")",!0,!1).draw()):(f.addClass(d.pane.active),c.column(g).search("^("+a.map(b,
+function(b){b=a(b).data("filter").toString();return a.fn.dataTable.util.escapeRegex(b)}).join("|")+")$",!0,!1).draw())},_variance:function(b){b=a.map(b,function(a,b){return a});for(var d=b.length,e=0,c=0,f=d;c