Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81685

submitting "clear search field button" plugin

$
0
0
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.


/*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 = $('<img src="/images/delete.png" style="vertical-align:text-bottom;cursor:pointer;" alt="Delete" title="Delete"/>');
		
		//no image file needed, css embedding must be supported by browser
		var clearSearch = $('<img title="Delete" alt="" src="data:image/png;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAD2SURBVHjaxFM7DoMwDH2pOESHHgDPcB223gKpAxK34EAMMIe1FCQOgFQxuflARVBSVepQS5Ht2PHn2RHMjF/ohB8p2gSZpprtyxEHX8dGTeMG0A5UlsD5rCSGvF55F4SpqpSm1GmCzPO3LXJy1LXllwvodoMsCpNVy2hbYBjCLRiaZ8u7Dng+QXlu9b4H7ncvBmKbwoYBWR4kaXv3YmAMyoEpjv2PdWUHcP1j1ECqFpyj777YA6Yss9KyuEeDaW0cCsCUJMDjYUE8kr5TNuOzC+JiMI5uz2rmJvNWvidwcJXXx8IAuwb6uMqrY2iVgzbx99/4EmAAarFu0IJle5oAAAAASUVORK5CYII=" style="vertical-align:text-bottom;cursor:pointer;" />');
		$(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'
	} );
}

if you want you can post on it the http://datatables.net/plug-ins/ page

Viewing all articles
Browse latest Browse all 81685

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>