0

Filters - product filtration

Hello! I have a database structure in Ninox where I create filters for products. The structure looks like this:

  1. Filters Table — stores filters like "Gender", "Color", "Season", etc.
  2. Filter_Name Subtable in the Filters Table — contains the filter name (for example, "Gender") and a relation to categories.
  3. Categories Subtable in Filter_Name — stores categories for each filter, for example, "Male", "Female", "Unisex".

I need a dynamic field on the product page to first display a list of all filters, and then, when I select a filter, automatically display the associated categories from the subtable.

I tried using the following formula:

let selectedFilter := this.Filter;
let categories := select Filter_Name where Filter_Name.Filter = selectedFilter;
categories.Category_Name

However, I am getting an error "Field not found" or "Not found". I can't figure out how to correctly set up the relationship between the Filter_Name subtable and the main Filters table to correctly display the categories.

I have attached the database to this email, so you can take a look at the structure and relationships. It might be easier to understand and help with the issue if you check it directly.

I would appreciate any help or suggestions!

 

8 replies

null
    • Fred
    • 9 days ago
    • Reported - view

    Here are my suggestions:

    In the Products table:

    1: change the code for Filter dynamic choice to:

    record(Filters,1).Filter_Name
    

    It looks like Filters is a dashboard or the beginning of a modular table. So if you only have 1 record then you can use the record() command.

    2: change the Categories dynamic multi choice field to:

    let selFilter := record(Filter_Name,number(Filter));
    selFilter.Categories
    

    Since each record in Filter_Name is linked to Categories you can use that relationship to create you dynamic fields with the use of the record() command again.

    With dynamic fields, the record() command becomes your best friend.

    Nice and simple code with no selects.

      • iliper LTD
      • iliper_LTD
      • 9 days ago
      • Reported - view

       

      Thank you for your valuable suggestions, they are always the most productive and helpful. I need to set up product filtering in the table so that after assigning filters to the products, I can filter them by these filters directly in the table.

      Here’s the proposed formula for filtering:

      let myChoiceFilter := this.Filter;
      let myChoiceCategory := this.Categories;
      let me := this;
      
      select Products
          where
              (myChoiceFilter = null or me.Filter_Name.Filter_Name = myChoiceFilter) and
              (myChoiceCategory = null or me.Categories.Category_Name = myChoiceCategory)
      
      

      Could you help me implement this or suggest improvements? Thank you in advance!

      • Fred
      • 9 days ago
      • Reported - view

      Take a look at the attached DB.

      A few changes:

      1) added a field called SearchTerms in Products. It creates an array of the selection(s) from Filter and Categories.

      2) I do something similar in Mine_Page, it is called Formula.

      Then in the view element I used some code from this handy post from

      let tooLook := Formula;
      (select Products)[var y := SearchTerms;
          var c := tooLook[var m := this;
                  count(y[= m]) > 0];
          count(c) = count(tooLook)]
      

      You can see now that since all of the filter and categories are in SearchTerms it makes it easier for me to compare. Also another reason to try to keep things arrays.

    • Fred
    • 9 days ago
    • Reported - view

    You should be aware that dynamic choice fields selections are "remembered" by Ninox even if you change the selection. If you select Gender under Filter and then select Male. Then you switch to Seasons and select Winter and Spring. Male will still be selected but not shown. You can see this by creating a new formula field and put the dynamic choice field name in it and it will show you the selections made.

    Since Filter is a single choice field, you only care about the categories that match the filter. That means you should put in the Trigger after update of Filter:

    Categories := null

    So everytime you switch Filter, you clear out Categories and don't have carry over.

      • iliper LTD
      • iliper_LTD
      • 9 days ago
      • Reported - view

       

      Thank you so much for your help – your advice is always incredibly useful and productive. I’m reaching out regarding an issue with setting up dynamic filtering and field selection.

      My goal is to create a filtering system where I can select multiple criteria and retain all the selected values to view products that match all parameters. For example:

      • Season: Summer
      • Gender: Women
      • Sizes: 38, 40, 42
      • Color: White

      Currently, I’ve set the first filter selection field as a single-choice field. If I change it to multi-selection, I lose the ability to display multiple filter options simultaneously. For instance, if I select both “Gender” and “Color,” I don’t see the corresponding selection fields for each filter.

      Is it possible to dynamically display separate selection fields for each filter when multiple filters are chosen? This way, I could independently select criteria for “Gender,” “Color,” and other filters, while all values remain active for filtering.

      • Fred
      • 9 days ago
      • Reported - view

      The searching part is easy. Like I said earlier, I created the fields SearchTerms and Formula in their respective tables to make an array of all selected choices. If you change Filter in either table to a dMC then you need to change the code in SearchTerms and Formula to take that into account.

      To do that you just need to follow the code for Characteristic. Something like:

      let xfilter := split(text(Filter), ", ");
      let xcat := split(text(Categories), ", ");
      array(xfilter, xcat)
      

      The problem with your current UI design of 1 characteristic field for all filter records is that if you switch to a multichoice then it become unmanagable the more filters that are selected. Like on clothing websites you see them break down the choices by category. So you will probably have to do something similar.

      Then you will have to recode the SearchTerms/Formula fields to handle the additional characteristic fields.

    • szormpas
    • 9 days ago
    • Reported - view

    Hi,

    I don't know if this is relevant to the post, but you can download a database with "filter examples" in the German forum:

    https://forum.ninox.de/t/m1y6pl5/optimieren-von-mehrfach-filter-in-ansichten-eines-dashboards

      • iliper LTD
      • iliper_LTD
      • 8 days ago
      • Reported - view

       Thank you for joining the discussion, we will definitely watch it

Content aside

  • Status Answered
  • 8 days agoLast active
  • 8Replies
  • 48Views
  • 3 Following