1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Filter dropdown fields by previous filter

Discussion in 'Completed' started by dantheafrican, Nov 26, 2008.

  1. dantheafrican

    dantheafrican New Member

    Level: Standard
    Hi - Not sure if this is already possible, but it would sure be useful

    Basically I have a table with some search filters at the top. What I am looking to do is filter what is displayed in a dropdown based on what option was previously selected.

    For example if the first dropdown lists countries and the second one lists states, then if someone selects USA in the first dropdown, it will only list US states in the second one (or fields that have corresponding rows in the database) - as opposed to how it currently works where each dropdown just lists all available options all the time.

    Ideally this should be dynamic so it would just look for all states where there are rows in the database to avoid having to list all states

  2. dantheafrican

    dantheafrican New Member

    Level: Standard
    Right, after some more investigation I see that this is possible. I have installed the cascading dropdown and have been trying to get it working. I keep getting SQL errors at the top of the table page no matter what combination of values I set for the cascading dropdown.

    Basically I have one really big table in the database that contains values for a lot of projects. I have the table set to filter by country first (by pulling up all the unique country values from the database), I would then like the second filter to look in the same table for all states that have corresponding country values to the one initially selected and then list the states in the dropdown.

    I've set the label field in the cascading drop down to "states" ID to "id" and Key to "country" (and every other conceivable combination) the watch element is set to the ID of the country element (848)

    It looks like most of the other threads pertaining to this issue have multiple database tables that are being joined.

    I have tried creating a new Fabrik table to link to, but that hasn't worked either. Guess I haven't structured the database in the most efficient way - but it certainly looks like it should be possible based on what others have accomplished in the forums

  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I'm not sure if it will work trying to use the same table, but one thing you are doing wrong is the "watched element" needs to be the element Name, not the ID.

    -- hugh
  4. dantheafrican

    dantheafrican New Member

    Level: Standard
    Thanks for the advice, I've changed the watched element to the element name (perhaps change the mouse-over help for this field - as it says "the elements id to watch")

    Just to clarify whether this is actually possible - what should I select under ID? would this be the actual tables ID column, or the country/state columns?...or something else

    I also assume I don't have to insert anything into the "where query" as the sql is being built based on the previous info.

    If its at all possible to build a sql query manually it shouldn't be too hard for me to do it - just not sure how to actually link it to the dropdowns

  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    The "where" is optional, and you don't need it.

    You'd usually select the peimray key of the table as the ID, and some descriptive field as the label.

    There's several detailed descriptions of how the cascade is configured in the forums - a search for 'cascading dropdown cities states' would probably yield some results.

    -- hugh
  6. cypherinfo

    cypherinfo Member

    Level: Community
    What about the final result? Did you succeed? If yes I would like to know how did you build (step-by-step) your cascading men?.

    Thank you.

  7. QfwfQ

    QfwfQ New Member

    Level: Community

    I'm curious to know about it too.

  8. sybn

    sybn New Member

    Level: Community
    I am curious,too. Isn't there a tutorial about this issue?
  9. rima

    rima New Member

    Level: Community
    I would like to know how to make dynamic dropdown menus, I tried the Cascading Stylesheet but cant seem to get it working.

    I want user to pick a car Brand and than the Type, should be that hard I gues but I dont know anything about coding or that stuff
  10. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Have you looked through the tutorials and the demo site for examples?

    -- hugh
  11. rima

    rima New Member

    Level: Community
    yea I did, but isnt working for me

    Its very confusing, can you make dropdown search on 2 elements when in the same database table?
  12. rob

    rob Administrator Staff Member

    Level: Community
    yes you can.
    Lets take this in small steps using your car brand example-

    You should have a table called 'car_brands'
    it should have two fields:


    fabrik_internal_id is the table's primary key and should be auto incrementing

    Then in the form where you want to show a dropdown of car brands, set up a database join element which points to the 'car_brands' table. Its settings should be set to:

    connection: site database
    table: car_brands
    key: fabrik_internal_id
    label: label

    ensure its published, and save it

    then check your form, it should now have a drop down that contains a list of all the records in the 'car_brands' table

    Once you've got that working report back here and I'll talk you through the second step

    1 person likes this.
  13. rima

    rima New Member

    Level: Community
    It shows a dropdown but it doesnt work as a search for my database.

    I have a database with carradiators, it has things as brand, type, motortype etc. but this doesnt give me a dropdown search for that table.

    I dont see how this will be usefull ?
  14. rob

    rob Administrator Staff Member

    Level: Community
    ok you should have perhaps said that you wanted to filter the results, as whilst the original post was about that - the rest of the disssion diverged away from that ! :)

    So what you want, if I have understood, is to have a filter at the top of your table that filters the list of records that the user sees?

    If so set the element's filter option to 'dropdown'. This option can be found under the element's table settings tab

    If its not that then please take a step back and fully explain what you want as its hard to second guess people sometimes 8)
  15. rima

    rima New Member

    Level: Community
    Im sorry I wasnt clear before, I will try to explain.

    I want a drop down search. So users can pick the brand, for example BMW and after that I would like a dynamic results in the 2nd dropdown, so people can pick the type, for example 320.
    After that the results will only show all BMW 320's

    I wasnt able to make the 2nd search dynamic, it shows all types for all brands.

    I hope you understand 8)
  16. rob

    rob Administrator Staff Member

    Level: Community
    ok so I presume you have got the first database join element working now as a table filter.

    So the next step is to create a cascading drop down (CDD) element - this element 'observes' the database join element (your 'car_brands' element). When that element changes the CDD sends a AJAX request to the server to get a filtered list of results, in your case that will me the car type's for that particular manufacturer.

    * Create a table of car_types, this should have the following fields:

    fabrik_internal_id - the primary key
    car_brand_id - a database join element pointing at the car_brand table
    label - a filed to store the car type

    Then in the form/table where you want to show a dropdown of car brands & car types
    * Create a new element
    * name it 'car_types'
    * set the plug-in to cascading drop down (I'm presuming you have downloaded and installed this plugin from the download section)

    give it the following values:

    * connection: site database
    * table: car_types
    * id: fabrik_internal_id
    * label: label

    (note how those options are pretty similar to the database join we added previously)

    *Watch element: car_brands (this is the database join we added in my previous explaination)
    *Foreign key: car_brand_id

    Ensure the element is set to show in table and that its filter type is set to drop down
    Save the element
  17. rima

    rima New Member

    Level: Community
    Cant get it to work unfortunatly

    what is this btw?

    Even if this will work it still not working on my parts database ?
  18. rima

    rima New Member

    Level: Community
    little kick :)
  19. peamak

    peamak Moderator

    Level: Community
    It's gonna be hard to be more clear than Rob here... Where are you now: did you try to set up the Cascading-dropdown? Do you have the car_types table set up? the 'car_brand_id' should be a database-join element pointing to the table car_brand and using the id element of this last table as primary key.

    This is because you have to tell the cascading dropdown the list of values to display depending on the watch element (the first dropdown).
  20. rima

    rima New Member

    Level: Community
    never mind it takes to long

Share This Page