Feature - searchPane: API method to rebuild panes

pull/355/head
Allan Jardine 7 years ago
parent 130178932d
commit d63f22010b

@ -2,7 +2,6 @@
// - Styling for selected // - Styling for selected
// - Styling for container / header // - Styling for container / header
// - Styling for clear option // - Styling for clear option
// - Rebuild API method
(function(factory) { (function(factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
@ -47,8 +46,10 @@
dt: table dt: table
}; };
table.settings()[0].searchPane = this;
table table
.columns(opts.columns) .columns(this.c.columns)
.eq(0) .eq(0)
.each(function(idx) { .each(function(idx) {
that._pane(idx); that._pane(idx);
@ -66,6 +67,17 @@
} }
$.extend(SearchPanes.prototype, { $.extend(SearchPanes.prototype, {
rebuild: function () {
var that = this;
this.s.dt
.columns(this.c.columns)
.eq(0)
.each(function(idx) {
that._pane(idx);
});
},
_attach: function () { _attach: function () {
var container = this.c.container; var container = this.c.container;
var host = typeof container === 'function' ? var host = typeof container === 'function' ?
@ -152,7 +164,9 @@
); );
if ( search.length ) { if ( search.length ) {
var escaped = $.fn.dataTable.util.escapeRegex( data[i] ); var escaped = data[i].replace ?
$.fn.dataTable.util.escapeRegex( data[i] ) :
data[i];
if ($.inArray(escaped, search) !== -1) { if ($.inArray(escaped, search) !== -1) {
li.addClass(itemClasses.selected); li.addClass(itemClasses.selected);
@ -163,8 +177,7 @@
} }
} }
$(this.dom.container).append( var pane = $('<div/>')
$('<div/>')
.data('column', idx) .data('column', idx)
.addClass(paneClasses.container) .addClass(paneClasses.container)
.addClass(search.length ? paneClasses.active : '') .addClass(search.length ? paneClasses.active : '')
@ -182,8 +195,23 @@
$('<div/>') $('<div/>')
.addClass(paneClasses.scroller) .addClass(paneClasses.scroller)
.append(list) .append(list)
)
); );
var container = this.dom.container;
var replace = container.children().map( function () {
if ( $(this).data('column') == idx ) {
return this;
}
} );
console.log( replace );
if ( replace.length ) {
replace.replaceWith( pane );
}
else {
$(container).append( pane );
}
}, },
_toggle: function(li) { _toggle: function(li) {
@ -209,7 +237,8 @@
.column(pane.data('column')) .column(pane.data('column'))
.search( .search(
'^'+$.map(filters, function(filter) { '^'+$.map(filters, function(filter) {
return $.fn.dataTable.util.escapeRegex( $(filter).data('filter') ); var d = $(filter).data('filter').toString();
return $.fn.dataTable.util.escapeRegex( d );
}).join('|')+'$', }).join('|')+'$',
true, true,
false false
@ -259,11 +288,28 @@
container: function ( dt ) { container: function ( dt ) {
return dt.table().container(); return dt.table().container();
}, },
columns: null, columns: undefined,
insert: 'prepend', insert: 'prepend',
threshold: 0.5 threshold: 0.5
}; };
SearchPanes.version = "0.0.1";
$.fn.dataTable.SearchPanes = SearchPanes;
$.fn.DataTable.SearchPanes = SearchPanes;
DataTable.Api.register( 'searchPanes.rebuild()', function () {
return this.iterator( 'table', function (ctx) {
if ( ctx.searchPane ) {
ctx.searchPane.rebuild();
}
} );
} );
$(document).on('init.dt', function(e, settings, json) { $(document).on('init.dt', function(e, settings, json) {
if (e.namespace !== 'dt') { if (e.namespace !== 'dt') {
return; return;

Loading…
Cancel
Save