Individual column searching (select inputs) - server side - How to have the full list in the select

Individual column searching (select inputs) - server side - How to have the full list in the select

sr57sr57 Posts: 11Questions: 3Answers: 0

I tested this exampe https://datatables.net/examples/api/multi_filter_select.html

The gloabal 'input search' works correctly, means it filters also data that are not shwon.

But the individaul column search does not show all the list. The items in the select list for one column are only those shown on the page, that's normal by the use of the function 'this.api().columns().every( function () {' but it's a problem because there is no way (except with the global seacrh) to search for every data, and the selected list does not render all the data available for the column.

Does sb know an other example which solves this problem? What should be the best way to do it (have pre-calculated select lists build by the server? ...

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    The example you linked to appears to be showing every item in its select lists, not just those shown on the current page. Or am I misunderstanding the question?

  • sr57sr57 Posts: 11Questions: 3Answers: 0
    edited August 2021

    Hi @tangerine ,
    Thanks for your answer, you are right, the list is complete in the example but at the end it's writen 'since the data is available in the table on load' that means, if I well understand, that it's not a server side example.
    Are you sure that this example works in server side?
    I'll remove all my other code in my script to retest in the same conditionof the example.

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    In your sever script look for the draw parameter value being 1. That is the initial request. When the parameter is 1 then use some DB queries collect the column data and return in an additional object. Use the json parameter of initComplete to access the additional object in the returned JSON.

    Kevin

  • sr57sr57 Posts: 11Questions: 3Answers: 0
    edited August 2021

    Hi @kthorngren
    Thanks for your reply.

    I use Yajra DataTable with Infyom Laravel-Generator

    I change to draw(1) in public/vendor/datatables/buttons.server-side.js
    That does not solve the pb.

    But I don't understand the 2nd part of your answer.
    -1- From the doc of initComplete I understand that the 2 parametres 'settings & json' are no optional, so mandatory? But they are not present in the examples code and in y code !?
    -2- If I add this parameters, what/how to do with the json , is there any example somewhere?
    -3- Anyway, when I print json, it only shows the data on the page (10 rows)

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    I change to draw(1) in public/vendor/datatables/buttons.server-side.js
    That does not solve the pb.

    Sorry I'm not familiar with the framework you are using. Maybe someone else on the forum is and can help. Maybe you can contact the developer of the framework to get support.

    From the doc of initComplete I understand that the 2 parametres 'settings & json' are no optional, so mandatory? But they are not present in the examples code and in y code !?

    Javascript allows not passing in parameters that aren't being used.

    If I add this parameters, what/how to do with the json , is there any example somewhere?

    I don't have an example but I guess you will need to use JSON.parse() to parse the JSON string into a Javascript object. Then access the object you added with the slect list information.

    Anyway, when I print json, it only shows the data on the page (10 rows)

    Thats expected with server side processing. You should see a few other properties like draw, etc. Once you add your object for the select lists you should see it here to.

    Kevin

  • sr57sr57 Posts: 11Questions: 3Answers: 0
    edited August 2021
    Once you add your object for the select lists you should see it here to.
    

    Don't undersatnd ... What is the code related in the exemple https://datatables.net/examples/api/multi_filter_select.html ?

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    In your server script you will need to run queries to fetch all the unique options for each column you want the select inputs. Do this when the draw parameter is 1. Return the options as an additional property, for example:

    draw: 1,
    data: [ .... ],
    options: [ ... ]   // Add this property - can be named anything you like
    

    in initComplete use the json parameter to access the property you added in the server script. Sorry, I don't have a way to provide an example as I don't have a server side processing script to add the options property.

    Kevin

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    Here is a thread asking a similar question. I believe there are others on the forum. Maybe they will help.

    Kevin

  • sr57sr57 Posts: 11Questions: 3Answers: 0

    Many thanks @kthorngren it's clear and logic now.

Sign In or Register to comment.