Exact word search
Exact word search
Im using Tablepress wordpress plugin (I've already written code for "Press enter to search and hidden table and search speficic columns" ). Now I want EXACT WORD SEARCH i.e user will see results only when he types exact word/number.
Note: I've found some solutions here but don't understand where to place exactly
1. http://stackoverflow.com/questions/19114586/how-to-get-exact-match-using-fnfilter
2. http://www.datatables.net/forums/discussion/4096/filtering-an-exact-match/p1
HERE IS THE LINK: http://appache.no/hydor
and here is the code
<script type="text/javascript">
$(document).ready( function () {
var table =
$('#tablepress-1').dataTable( {
"aoColumnDefs": [
{
"bSearchable": false, "aTargets": [ 0,2,4,5,6,7,8]}
],"bLengthChange":false,"iDisplayLength":1 } );
window.alert = function() {};
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
return oSettings.oPreviousSearch.sSearch === '' ? false : true;
}
);
var DT_tablepress_1 = $('#tablepress-1').dataTable({"aaSorting":[],"bSortClasses":false,"asStripeClasses":[],"bSort":false,"bLengthChange":false,"iDisplayLength":1,"bInfo":false});
$('#tablepress-1_filter input').unbind().bind('keyup', function(e) {
if( 13 == e.keyCode )
DT_tablepress_1.fnFilter( this.value );
});
$( '.dataTables_filter' ).find( 'input' ).on( 'keyup', function(e) {
if( 13 == e.keyCode ) {
$( '.dataTables_wrapper' ).find( '.tablepress' ).toggle( '' != $(this).val() );
}
} );
$( '.dataTables_wrapper' ).find( '.tablepress' ).hide();
});
</script>
Answers
code is not showing correctly, you view the code on top in http://appache.no/hydor
I would suggest using regex with the
search()
orcolumn().search()
methods if you want full string matching. Something like:You can't use
^$
withsearch()
since, for performance reasons, DataTables concatenates the search strings into a single string. But you could use the smart filtering with double quotes:Slightly different since it doesn't go start to end of a column's string, but it does match that phrase and only that phrase.
Allan