How to get maincategory and subcategories?

Hello!

Now I tried everything without any luck. I search for scripts and nothing helps.

Situation right now is I need Hierarchy:
On the first page, all “products” are now displayed with their own box. But I want a main category and under that the “products” should be displayed.

Chatgpt got me this code but It didnt do anything that I can see.

function sortData() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var dataRange = sheet.getDataRange();
  var data = dataRange.getValues();

  // Ta bort första raden (rubrikerna) innan sortering
  var headers = data.shift();

  // Sortera data
  data.sort(function (a, b) {
    for (var i = 0; i < 4; i++) {
      if (a[i] < b[i]) return -1;
      if (a[i] > b[i]) return 1;
    }
    return 0;
  });

  // Lägg tillbaka rubrikerna
  data.unshift(headers);

  // Skriv de sorterade datavärdena tillbaka till arket
  dataRange.setValues(data);
}

Please help

If you already know what your main categories are going to be, I would just create a new table that only lists the categories. Then create a relation that links the category to the category in the products table. In the app, set the source or your collection to the category table. When you select a category from the collection, it will show a detail screen. At that point, you can add a collection that is sourced from the relation you created earlier.

2 Likes

Do you have the opportunity to show me the steps in print screens as I am a complete beginner with Glibe? Or if you can refer to any guide on this?

If you create a new mobile app in Glide, this is the exact type of setup that the default app gives you. You should see Categories and Things, and if you look at the data you can see how they connect to each other.

4 Likes

This helpt me a lot! Thank you!

Now I have last problem. When I search I feel like I search just in seperate table. How Can I search all things from category page?

That’s a little more complicated. The search will only search for visible data on the detail screen of each item in the collection. Going back to the Categories and Things example, the search would only work for data visible on the Category detail screen. However, it will not search any data inside any of the Things items in the collection on the category detail screen.

To make it work, you would first have to create a template column in the Things table that joins all of the columns that you want to search into one value. Then in your category table, you will need a Joined List column that retrieves that template column from the relation in the Categories table. Finally you will need to add that Joined List column as text on the Category detail screen. When you search the categories collection, it will be looking at that joined list text that is on the category detail screen.

Now obviously you wouldn’t want to see a random string of text on the category screen. I don’t remember the correct method of the to of my head, but there are two things to try. One is to set the visibility of the text so it is not visible. If that doesn’t allow the search to work, then you will have to use a rich text component and you will have to create a template column that writes the joined list with some html to make the text invisible. Hopefully you don’t have to go that far. I would try the visibility truck first.

2 Likes