How to implement individual column search?

How to implement individual column search?

wuwuwuwu Posts: 52Questions: 17Answers: 0

I have now a working datatable using vs.net generic handler but i want to implement individual column search. Any ideas?
thanks

Answers

  • rf1234rf1234 Posts: 3,021Questions: 88Answers: 421
    edited April 2020

    There are two individual column searching examples right here. It was only a matter of entering "individual column searching" into the search field in the top right corner of your screen ...

    https://datatables.net/examples/api/

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    hi rf1234. thanks for your reply. i tried to implement the individual search column on the footer but it seems that when i enter something on any of the textbox, it passes empty values on my .net generic handler. but when entering on the global search box, it passes the correct values to my generic handler so it display correctly. Any ideas again?

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    what i actually want to achieve is an individual search columns on my current datatable that uses server side processing using .net generic handlers.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Here's an example of the footer search. That would just work with serverSide, as the column filter string would be sent as part of the request.

    Colin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi collin, i tried already this but it still does not work. The column filter string is correct but when access in my .net Generic Handler, it is null. But when i tried to input on the global search box, it passes the correct value in my handler. I don't know what i am missing.
    Thanks

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    If you look at the network tab on the developer's tools for this example, and do a search, you'll see the search string is being sent as expected. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi Collin, thanks again for your reply. This client side processing is actually working for me. What is not working for me is the server side processing that I created. I uses .NET Generic Handler which calls stored procedure and returned JSON and display in jQuery datatable. Global search is working as expected but the individual search is not working. When I debug and enter something on individual search, it actually fires up, pass the correct value and go to my Generic Handler codes but the problem is I did not get the correct value on my generic handler. Do i need to update my .net generic handler codes? Thanks

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    It sounds like it yes. How are you constructing the SQL statement based on the data that DataTables is submitting? The query will need to take into account the search term that the client-side sends.

    Allan

  • wuwuwuwu Posts: 52Questions: 17Answers: 0
    edited April 2020

    Hi Allan, the sql statements is being called by generic handler. and generic handler has one parameter of HttpContext variable context. Then context.Request["sSearch"] is the one that global search is using. When i enter something on global search, the generic handler will fire and populate correctly the sSearch. But I don't know how to pass the individual search from jquery to generic handler. When I enter on the individual search, the generic handler fires too but I don't know how to get the search value. I tried to check the sSearch and it is null since i enter on the individual search column. Any ideas?
    By the way, this video "https://www.youtube.com/watch?v=u4QKLehvUhs" is the one i followed and it is working already except for the individual searching. Thanks

  • kthorngrenkthorngren Posts: 21,448Questions: 26Answers: 4,974

    The Server Side Processing docs explain the protocol used and parameters sent. There are parameters, including search, for each column that you will need to check in your script.

    Are you using Datatables 1.9.x or 1.10.x. If 1.9 you should consider upgrading to 1.10 since 1.9 is not being developed anymore.

    Kevin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi Kevin, this is the code i used to call the generic handler.

    var table = $('#uomDataTable').DataTable({
    aaSorting: [[0, 'desc']],
    columns: [
    { "data": "UOMCode", "name": "UOM Code" },
    { "data": "UOMDescription", "name": "Description" }
    ],
    bServerSide: true,
    sAjaxSource: '/GenericHandler/UOMHandler.ashx',
    processing: true
    });

    And my upper part of the generic handler is:
    public void ProcessRequest(HttpContext context)
    {
    int displayLength = int.Parse(context.Request["iDisplayLength"]);
    int displayStart = int.Parse(context.Request["iDisplayStart"]);
    int sortCol = int.Parse(context.Request["iSortCol_0"]);
    string sortDir = context.Request["sSortDir_0"];
    string search = context.Request["sSearch"]

            SqlConnection Conn = new SqlConnection
            .....
    

    This is working including the global search. I uses context.Request["sSearch"].
    My problem is on the individual searching. When I enter something on individual search, it goes to my generic handler but i don't know how can i retrieve the individual search text in my generic handler. thanks

  • kthorngrenkthorngren Posts: 21,448Questions: 26Answers: 4,974

    Since you are using the legacy form of Datatables you will want to look at this documentation:
    https://legacy.datatables.net/usage/server-side

    Look at the section called "Parameters sent to the server". That shows the parameters that are included for the columns, such as sSearch_(int). These are the parameters to retrieve in your server script.

    Kevin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi Kevin, thank you. I just upgraded from 1.10.. version and how do I convert this
    sAjaxSource: '/GenericHandler/UOMHandler.ashx', to the new version? thanks

  • kthorngrenkthorngren Posts: 21,448Questions: 26Answers: 4,974

    The Legacy Conversion Guide shows the mapping of the old versus new command styles. 1.10 supports the old naming technique however it is recommended to change from sAjaxSource to ajax. Note this will change the parameter names sent to the server. See this link.

    Kevin

  • wuwuwuwu Posts: 52Questions: 17Answers: 0
    edited April 2020

    Hi kevin, i managed to upgrade to 1.10 and it now display but came across another problem which tooltip and popover are not working anymore. Do you have any ideas on this?
    Also, I am currently trying to apply the individual search if it will work now using this upgrade. I will let you know.

    Thanks

  • wuwuwuwu Posts: 52Questions: 17Answers: 0

    Hi Kevin, it is working now including individual column search. thanks for your support.
    thanks too to others.

This discussion has been closed.