Exact word search

Exact word search

muhammadnanmuhammadnan Posts: 3Questions: 1Answers: 0
edited October 2014 in Free community support

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

  • muhammadnanmuhammadnan Posts: 3Questions: 1Answers: 0

    code is not showing correctly, you view the code on top in http://appache.no/hydor

  • muhammadnanmuhammadnan Posts: 3Questions: 1Answers: 0
    <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>
    
  • allanallan Posts: 63,382Questions: 1Answers: 10,449 Site admin
    edited October 2014

    I would suggest using regex with the search() or column().search() methods if you want full string matching. Something like:

    table.column( 1 ).search( '^My exact match$', true, false );
    

    You can't use ^$ with search() since, for performance reasons, DataTables concatenates the search strings into a single string. But you could use the smart filtering with double quotes:

    table.search( '"My exact match"' );
    

    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

This discussion has been closed.