Difference between search and filter option.

Difference between search and filter option.

RamprakashRamprakash Posts: 14Questions: 7Answers: 1

Can anyone say exactly what are difference between search and filter options.
In which case we need to prefer filter instead of search?\
I need mulitple filtering in mulitple columns,
Example:
Search a string in 0th column, search another string in 3rd column and search another string in all columns and combine all the result together and draw. What should I need to use??

This question has accepted answers - jump to:

Answers

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    A bit unrelated to the q' , but if you will apply my yadcf filter to your table you will be able to use the exFilterColumn function to achieve your goal

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    edited March 2015 Answer ✓

    Can anyone say exactly what are difference between search and filter options

    In most cases the terms filter and search in DataTables are interchangable. I have make the terminology constant in the 1.10 API and options that to find data in the table is called a search.

    The API also has a method called filter(). This is not the same as search(). fitler() operates on the data contained in the API result set - not the table.

    Search a string in 0th column, search another string in 3rd column and search another string in all columns and combine all the result together and draw.

    table
      .search( 'all column search' )
      .column( 0 ).search( 'string1' )
      .column( 3 ).search( 'string2' )
      .draw();
    

    Allan

  • RamprakashRamprakash Posts: 14Questions: 7Answers: 1

    @daniel_r exFilterColumn has three types, and second is somewhat related but my need is one search criteria is to search in all the columns remaining two each in only one column.

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    Answer ✓

    @Ramprakash , there is only one way to call the function, you need to provide two args, first one is the table and the second argument is array of pairs: column number and String/Object with from and to, filter_value (the actual string value that we want to filter by), the "three types" are three examples of calling the function

  • RamprakashRamprakash Posts: 14Questions: 7Answers: 1

    Wow.. Sounds great.. Its really nice working with datatables.. Thank you allan..

  • RamprakashRamprakash Posts: 14Questions: 7Answers: 1

    Yes @daniel_r just now i look over the function. I've used solution by Allan and it gave the exact result what I want. Thank you for the reply :-)

  • RamprakashRamprakash Posts: 14Questions: 7Answers: 1
    edited March 2015

    @Allan But one problem exists there..
    In the search criteria on column 0 I need to search multiple strings, and I need to find exact match..
    Ex:
    I may have values like Person #1, Person 2,... Person #11,...Person #21...

    Based on my code I've given like

    $('#example')

               .DataTable().column(0)
               .search("^"+"Person #1|Person #2"+"$",true,false,false)
               .column(index).search(tempString,true,false,false)
               .draw();
    

    I need only rows that have entries either Person #1 or Person #2 not Person #11, Person #21 like that...

    It takes last one correctly and filters Person #2 correctly but not for #1.. How can I achieve it??

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Answer ✓

    The regex is incomplete for such a match - just adding parenthesis should do it:

    .search("^("+"Person #1|Person #2"+")$",true,false,false)
    

    My regex is seriously rusty(!) so you might want to check that (I've just done a cursory check which appears to confirm that).

    Allan

  • RamprakashRamprakash Posts: 14Questions: 7Answers: 1

    @Allan You are really amazing.. Working nice.. Thanks a lot :-)

This discussion has been closed.