searching is not happening

searching is not happening

JanurajJanuraj Posts: 85Questions: 18Answers: 0

http://live.datatables.net/wilavabi/11/edit
I am providing the test case.
in the test case, on selecting the option in select dropdown
search should happen and table should show the results appropriately

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    edited November 2020

    In your event handler you have var table =$('#profile-table').DataTable(); but your table ID is example. Here is the updated test case:
    http://live.datatables.net/wilavabi/12/edit

    Your server script will need to handle the regex searching which the /ssp/ids-objects.php script does not so the search in the test case results in an error.

    Allan has told others that regex searching with SQL type databases is not recommended due to performance. That part is up to you to write and verify it works properly.

    Kevin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    sorry my bad, I have put it as server side , for client side how to handle it?
    the same test case i want the search on client side.
    Please help in this

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    I removed serverside and fixed this error:

    DataTables warning: table id=example - Requested unknown parameter 'last_name' for row 0, column 2. For more information about this error, please see http://datatables.net/tn/4

    Fixed it by adding a return after the if statement in the columns.render. You always need to return something.

    The search works here:
    http://live.datatables.net/wilavabi/16/edit

    Kevin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0
    edited November 2020

    @kthorngren it is working here in the test case.
    But i have built similar thing in my project.
    it is not happening.

    table.column(5).data().toArray(). -----> ["0abbc286-901a-40be-8cd9-a86d459df2b7"]

    But on searching against this column it is not displaying the results.
    i tried using the below code

    table.column(5).search("^" + "0abbc286-901a-40be-8cd9-a86d459df2b7" + "(.)*", true, false).draw();

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    As it's working in Kevin's example, we'll need to see it. Can you link to your project, please.

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0
    edited November 2020

    table.column(5).data().toArray(). -----> ["0abbc286-901a-40be-8cd9-a86d459df2b7"]

    it is returning this, so when i use

    table.column(5).search("^" + "0abbc286-901a-40be-8cd9-a86d459df2b7" + "(.)*", true, false).draw();
    it should search and show it right. Here am i missing anything?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    it should search and show it right. Here am i missing anything?

    Use https://regex101.com/ to test your regex expressions. If they work but you aren't see the results then we will need to see a running example with the problem to help debug. Otherwise its impossible to guess what the problem might be.

    Kevin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    how to log and see the search results ?
    http://live.datatables.net/wilavabi/18/edit

    without regex is it not possible to search against a specific column?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    You can use regex for a specific column, see the updated example:
    http://live.datatables.net/nujibusa/1/edit

    Change the drop down and you will see all columns the start with S.

    To see the searched data you will use columns() or rows() with a selector-modifier of {search: 'applied'} with the chained data() API. This is also in the example.

    Kevin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0
    edited November 2020

    Thanks Kevin @kthorngren

    Now i have another use case. where i have two filters on names and office columns.
    wanted to perform search combining both the filters.
    I tried using chaining but i am not getting correct results
    in the test case on selecting name as "Airi" and office as "accountant" it is displaying 0 results instead of 1.
    Please see the test case below

    http://live.datatables.net/wilavabi/19/edit

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    You have a trailing space in your Accountant option:

    <option value="Accountant ">Accountant </option>
    

    Remove the space.

    Kevin

This discussion has been closed.