submitting "clear search field button" plugin
submitting "clear search field button" plugin
Hello,
I have developed a plugin that some people on the forum were searching for and would like to share it.
It adds a "clear text" button for the search field that when pressed deletes the filter.
Here is the sourcode, just include it after jquery.dataTables.min.js and you're done, no code to add or modify.
[code]
/*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL Galeola S.r.l.( www.galeola.it )(Maxim Postoronca) OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.*/
if ( typeof $.fn.dataTable == "function" && typeof $.fn.dataTableExt.fnVersionCheck == "function" && $.fn.dataTableExt.fnVersionCheck('1.9.2')/*older versions should work too*/ )
{
$.fn.dataTableExt.oApi.clearSearch = function ( oSettings )
{
var table = this;
//any browser, must include your own file
//var clearSearch = $('');
//no image file needed, css embedding must be supported by browser
var clearSearch = $('');
$(clearSearch).click( function ()
{
table.fnFilter('');
});
$(oSettings.nTableWrapper).find('div.dataTables_filter').append(clearSearch);
$(oSettings.nTableWrapper).find('div.dataTables_filter label').css('margin-right', '-16px');//16px the image width
$(oSettings.nTableWrapper).find('div.dataTables_filter input').css('padding-right', '16px');
}
//auto-execute, no code needs to be added
$.fn.dataTable.models.oSettings['aoInitComplete'].push( {
"fn": $.fn.dataTableExt.oApi.clearSearch,
"sName": 'whatever'
} );
}
[/code]
if you want you can post on it the http://datatables.net/plug-ins/ page
I have developed a plugin that some people on the forum were searching for and would like to share it.
It adds a "clear text" button for the search field that when pressed deletes the filter.
Here is the sourcode, just include it after jquery.dataTables.min.js and you're done, no code to add or modify.
[code]
/*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL Galeola S.r.l.( www.galeola.it )(Maxim Postoronca) OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.*/
if ( typeof $.fn.dataTable == "function" && typeof $.fn.dataTableExt.fnVersionCheck == "function" && $.fn.dataTableExt.fnVersionCheck('1.9.2')/*older versions should work too*/ )
{
$.fn.dataTableExt.oApi.clearSearch = function ( oSettings )
{
var table = this;
//any browser, must include your own file
//var clearSearch = $('');
//no image file needed, css embedding must be supported by browser
var clearSearch = $('');
$(clearSearch).click( function ()
{
table.fnFilter('');
});
$(oSettings.nTableWrapper).find('div.dataTables_filter').append(clearSearch);
$(oSettings.nTableWrapper).find('div.dataTables_filter label').css('margin-right', '-16px');//16px the image width
$(oSettings.nTableWrapper).find('div.dataTables_filter input').css('padding-right', '16px');
}
//auto-execute, no code needs to be added
$.fn.dataTable.models.oSettings['aoInitComplete'].push( {
"fn": $.fn.dataTableExt.oApi.clearSearch,
"sName": 'whatever'
} );
}
[/code]
if you want you can post on it the http://datatables.net/plug-ins/ page
This discussion has been closed.
Replies
I'm trying to expand it clear all the column filters as well. But so far can't get it to work. Any help would be appreciated. I think it's just a matter of adding another table.fnFilter except additionally pointing at the column filters
That uses something like this
for ( var i=0, iLen=oSettings.aoPreSearchCols.length ; i