search two words or more with OR

search two words or more with OR

kbrom kbrom Posts: 2Questions: 1Answers: 0

Hello. I have a need to search for two words using the DataTables.search() API. It looks like it is working on the following demo site http://datatables.net/examples/api/regex.html. but I couldn't get it to work. I am only able to search one word. Please help
Bellow is the function i am trying to use to do the search.

function filterColumn ( ) {
    $('#gsat').DataTable().search(
        'SS8|ACME',
        true,
        false  
    ).draw();

}

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29
    edited March 2016

    I've done this feature already and mocked it up again in JSFiddle and it does work fine. Is there anything else in your initialization like you are only sorting on particular columns, switched to case sensitive or your are using serverSide?

  • kbrom kbrom Posts: 2Questions: 1Answers: 0

    Thank you Glenderson for your reply. I have server side processing. If possible could you share with me the JSFIddle if you still have it available or think it would be helpful?

    table = $('#gsat').DataTable({
    
                    
    
                    "lengthMenu":  [[-1, display_amount, 200, 100], ["All", display_amount, 200, 100]] ,
    
                    "processing": true,
                    "serverSide": true,
                    "ajax": {
                        "url": "server_processing5.php",
                        "data": {
                            audit_date: selected_date,
                            reg: region,
                            selected_nename: selected_nename,
                            selected_multinename: selected_multinename
                        }
                    },
                    "order": [[ 1, "desc" ]],
                    "autoWidth":false,
                    "sPaginationType":"full_numbers",
                    "bJQueryUI":true,
                    "aoColumns": [
                    { "sWidth": "10%" },
                    {  "sWidth": "10%"},
                    {  "sWidth": "10%"},
                    {"sWidth": "12%"},
                    {"sWidth": "8%"},
                    {"sWidth": "7%"},
                    {"sWidth": "5%"},
                    {"sWidth": "5%"},
                    {"sWidth": "5%"},
                    {"sWidth": "360px"},
                    {"sWidth": "10%"},
                    {"sWidth": "10%"},
                    {"sWidth": "10%"}
                    ],
                    "footerCallback": function ( row, data, start, end, display ) {
                        var api = this.api(), data;
    
                // Remove the formatting to get integer data for summation
                var intVal = function ( i ) {
                    return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                    i : 0;
                };
    
                
    
              // Total Discripensis  over this page
                Col6_pageTotal = api
                    .column( 6, { page: 'current'} )
                    .data()
                    .reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                    }, 0 );
                
               // Total Matches  over this page
                Col7_pageTotal = api
                    .column( 7, { page: 'current'} )
                    .data()
                    .reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                    }, 0 );
                     
                // Total Attributes  over this page
                Col8_pageTotal = api
                    .column( 8, { page: 'current'} )
                    .data()
                    .reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                    }, 0 );
    
                    var percentage = parseInt((( Col7_pageTotal / Col8_pageTotal) * 100 ),10);
                     console.log("percentage:"+percentage);
                     console.log("totalpage:"+ Col7_pageTotal);
                 // Update footer
                $( api.column( 6 ).footer() ).html(
                    Col6_pageTotal 
                );
    
                 $( api.column( 7 ).footer() ).html(
                    Col7_pageTotal
                );
    
                 $( api.column( 8 ).footer() ).html(
                    Col8_pageTotal  
                );
                 $( api.column( 9 ).footer() ).html(
                    ' (' + percentage+'%)' 
                );
              
    
            }
    
    
    
    
    
        } );
    
This discussion has been closed.