Multiple Filter Select with Database Table

Multiple Filter Select with Database Table

wahyzcrakwahyzcrak Posts: 6Questions: 1Answers: 0

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

I am using the above link to try and add drop down selections to the footer of a table that I am pulling in from a database model.

I have it working to pull in all of the records, but as soon as I add this code, it is not working, so I think that I am not understanding which part of the code is pulling in the data for the table. In the example the table is just populated by html, but I am pulling in the data from a database and would like to use this method to filter some of the columns.

Is there an example of this implementation being used with a datatable that is populated from database records?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    I copied the initComplete code from the example into this test case that uses ajax data:
    http://live.datatables.net/samixovo/1/edit

    The select filters seem to work. What is the exact issue you are having?

    Maybe you can post a test case showing the issue.

    kevin

  • wahyzcrakwahyzcrak Posts: 6Questions: 1Answers: 0
    edited November 2017

    Apparently I was just doing it wrong, I formatted my java script the same way you have yours and now it is working, however, I think the drop down selectors are only pulling in the values from the first page, rather than from all pages..

    I think my problem was legitimately only that I didn't put a comma after my table array

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    I think the drop down selectors are only pulling in the values from the first page, rather than from all pages

    I can see that if you are using server side processing.

    Kevin

  • wahyzcrakwahyzcrak Posts: 6Questions: 1Answers: 0
    edited November 2017

    Hmm, yea that must be it, I disabled the server side processing and now it loads as expected.. it is noticibly slower, though

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You could try deferRender to help increase the speed of the initial display.

    Kevin

  • wahyzcrakwahyzcrak Posts: 6Questions: 1Answers: 0
    edited November 2017

    Hmm, I put in a deferRender: true directly after my ajax declaration and before my table array, but it doesn't seem to be helping all that much.

    I am mostly just worried that once I start having millions of records that this will not be functional without the server side processing... currently I only have 8000 entries and it is a bit slow to load.. that being said, I haven't set up any index on my database table yet

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    If you plan to have millions of records then maybe you will want to stick with server side processing. Have a look at the first FAQ here:
    https://datatables.net/faqs/index#General-initialisation

    I think it would be easier to start with server side than to convert from client to server side. Depending on the number of options in your select input it might be better to use text inputs like this example:
    https://datatables.net/examples/api/multi_filter.html

    You could probably figure out a way to populate a select inputs with all your options via an ajax call. Although you would need to be careful not to introduce delays, solved by server side processing, by collecting and processing too many records to populate select inputs.

    Kevin

  • wahyzcrakwahyzcrak Posts: 6Questions: 1Answers: 0

    Indeed, the main thing is I will have CVEs, and Hosts, both of which may have many records for either one.

    For example 1 host might have 1000 rows, and even more rows per cve, so the dropdowns will never be too big, it is just a matter of there being so many records.

    I will read into this a bit and start with your suggestions. Thank you for the help

  • wahyzcrakwahyzcrak Posts: 6Questions: 1Answers: 0

    I can probably also find some ways to make it so that less records have to load by default, like having it default to loading the most recent few months or something, and adding a few buttons to tell it whether or not I want to see remediated items, etc

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    Not sure if this would be relevant to what you want to do but this blog talks about parent / child tables:
    https://datatables.net/blog/2016-03-25

    Maybe you could have the parent display the hosts and the child display the associated CVE's for the selected host. You could potentially just have that child table display the list of CVE's and have another child table the displays the 1000+ rows of the selected CVE. So 3 tables on one page. Just some alternate ideas for you to look at.

    Kevin

This discussion has been closed.