Datatable Dropdown reload
Datatable Dropdown reload
Hello,
I have a DataTable Server-Side with a dropdown filters comming from Mysql database
My filters have dependencies, i have 4 filters, Brand, Model, Year, Doors.
Filters model year and doors are empty, only show options after select the brand.
The problem:
I select brand "AUDI", then in dropdown modelos i select "A4 Avant" and works fine. But if i want to change the brand, i select BMW, my datatable returns "Empty Results" and i have two options:
I need to select some model of BMW, and after select model work fine.
I need to select another brand, and work fine, example, i'm on Brand AUDI, model A4 AVANT, i select brand Mercedes, no results, i select brand BMW, full results from BMW.
I try some codes in this forum and on other foruns and can't put to work, i want, when i select "Brand" always reload datatable...
Live example:
https://new.dga.pt/produtos/datatables.php
The code: (My code have PHP, so you cant preview result, but can watch the HTML, the script for datatable is on javascript field.
https://live.datatables.net/carofiba/1/watch
Thank You!
This question has an accepted answers - jump to answer
Answers
You are encountering a similar issue as we have in SearchPanes for the cascade.
What you need to do is have your event listener for the
Marca
field reset the values for the other three inputs - then make the Ajax request. For example:Do the same for the other dropdowns, just removing itself, so finally you end up with the
Ano
search just calling draw as it currently is.Allan
Just use a "change" event handler and do an ajax reload of the data table.
https://datatables.net/reference/api/ajax.reload()
Yes allan, that makes sense, i tried this code, but inside the script to call the the other options based on last choice. When you sent me that code, i just copy and put inside a new script on the end of page and worked with no problems.
Solved.
Newbie error... i'm a begginer in JS.
Thank you Allan.