Favourites

This is what I would like to do. I am trying weeks already but I do not find the way.

I have a list of read-only products. Each product has een favourite icon (star or heart). When I click this icon the product is added to another list called โ€œfavouriteโ€ and the icon turns red. When I reclick the icon the product is deleted from the favourite list and the icon turns black again.

It seems easy but I do not find anything to do this.

I would appreciate any help!

2 18 374
18 REPLIES 18

Hello @MikeeGee, welcome to our community !

Lets take this step by step, your table is โ€œread onlyโ€, but in order to have dynamic actions you need some way to store which row is a โ€œfavoriteโ€ and which one isnโ€™t, and if we canโ€™t add another column to that table in order to store that information, it might get bumpy.

Letโ€™s say we make another table so that each time someone clicks a row on the primary table a new row is added for recording the newly favorited row, in order to display the โ€œfavorite iconโ€ in your primary table, youโ€™re gonna need a format rule that checks between tables in order to figure out which rows in your primary tables are โ€œfavoritesโ€.

And thatโ€™s no bueno, cross table format rules can make your app quite slow.

What do you say then, can we add a new column to your primary table?

Also, are โ€œfavoritesโ€ global (shared across all users) or should be different for each? Considering you have a Current_User system of course, and if you donโ€™t, you should, itโ€™s great.

EDIT: Now that i think about it we could add a virtual column to the read-only table for checking if each row is a โ€œfavoriteโ€ or not, that could work.

I would like to make the favourites global for all users

Youโ€™re on the right track!


Youโ€™ve got all the necessary pieces, you just need to assemble them.

  1. Create an action that creates the โ€œfavorite recordโ€ in the background

    • Make sure this favorite record contains:
      • A reference to the Primary record:
        [Favorite_Primary_Ref]
      • A Enum-reference to the User table (linking that record to the user):
        [Favorite_User_Ref]
  2. Create a Current_User system

  3. Create an additional slice, to hold all the favorite records from the Current User

    • Name: Current_User_Favorites
    • Formula: INDEX(Current_User[UserID], 1) = [Favorite_User_Ref]
      or
      IN([Favorite_User_Ref], Current_User[UserID])

At this point youโ€™ve got a slice holding only the favorite records from your user

  • You can use that as a โ€œglobal variableโ€ - which can then be used for your formatting rules.
  1. Create a formatting rule:
    • Name: Favorited by user
    • Table: Primary table (the oneโ€™s being favorited)
    • Formula: IN([Primary_Record_ID], Current_User_Favorites[Favorite_Primary_Ref])

It can seem counter-intuitive to create all this โ€œstuffโ€ - all this overhead - just for some formatting rules; but in reality youโ€™re creating ways to efficiently achieve your desired results.


Once you have this global variable like this, you can use it all over the place.

  • For instance: the button to favorite a record

This action should have a condition formula, that checks to see if the record at hand is inside that Current_User_Favorites (slice).

  • This formula, is the same one used by the formatting rule: the IN() formula (only reversed):
    NOT(IN([Primary_Record_ID], Current_User_Favorites[Favorite_Primary_Ref]))

If you put this formula inside the condition for the favorite record creation actionโ€ฆ it will only show when the ID of the record IS NOT inside the Current_User_Favorites (slice).

Ok, let me try this. Iโ€™ll let you know when I have any questions.

Sorry but I need to do it step by step, starting with step 1.

Can you tell me if my columns are correctly filled and what do have to fill exactly in the action.

This is what youโ€™re trying to do

  • Instead of creating a record on the โ€œProductsโ€ table, you instead need to create a new table

I appreciate a lot that you try to help me. Please be patient with me cause I am just een beginner

Can you give me an example? because I m really lost. I do not know what I have to fill in this new table.

maybe you can give me a sample of something like that

Rafael, are you looking for ? Or do I have to look at somewere else ?

Hello, weโ€™re going the virtual column route then? or weโ€™re gonna add another column to your main table? the result is similar but the methods are quite different.

If the favorites are global, then adding another column will suffice, if you wish to follow the great @MultiTech_Visions advice, which will turn your app into a much more robust one, youโ€™re going to need to add couple more tables to your app.

Are you familiar with references and slices? those are very important for making optimal apps.

Hello! Of course I want to follow the great @MultiTech_Visions advice! Can you reach my main googlesheet (test) ? Can you use it to make an example? The problem is that I do not know how to make the specific right link between the tables. I could make some references with slices following some tutorials on youtube but I didnโ€™t found what I searching for. Keep in mind that Iโ€™m just a beginner I need to understand how it works and I tryed already many many many times.

I gotchu

I made some changes to the spreadsheet to better illustrate how it works, but as i was about to start explaining it I realized it would be easier if i build it myself and then make it a public sample so you can see for yourself how it works, so give me a bit of time and iโ€™ll be back with it.

Hello Rafael,

Thanks for you answer! Add a virtual column looks likes to be the right way. I use to try many times but I do not know how to do it. Below the link to my google sheet. This is just a test sheet. The first tab is a imported data and do not have to be changed. I use a quey formula to copy the data to the tab โ€œproductsโ€.

https://docs.google.com/spreadsheets/d/1tMuRCXyZiJqJHbWopJysaLw7-EKtlTMuRDS3Wokz0Ow/edit?usp=sharing

Iโ€™m back

https://www.appsheet.com/portfolio/1902178

Itโ€™s the only app on my portfolio, so it shouldnโ€™t be hard to find haha, I tried to keep it as minimalistic as possible.

The sample app has:

Tables:

  • An โ€œUserโ€ table with the basic stuff (id,name,email,role)
  • Your โ€œScrโ€ table almost untouched, just added an โ€œScr_IDโ€ column and an auxiliary column for placing the action buttons
  • A โ€œFavouritesโ€ table for saving the references we talked about

Slices:

  • A โ€œcurrentUserโ€ slice of your users table
  • A โ€œcurrentUserFavouritesโ€ slice of all the favourite records of the current user

Actions:

  • A โ€œMark as favouriteโ€ action
  • A โ€œDelete favouriteโ€ action
  • A โ€œEraseโ€ action

Format rules:

  • A โ€œFavouriteโ€ rule that places a cute little pink heart next to โ€œscr_nameโ€ if it is a favourited item for the current user

Expressions:

Let me know if you have any questions about it, donโ€™t forget you can make a copy of it so you can play with it. Have fun !

Amazing! It looks different than what I thought but I like it even more! Great job! Iโ€™am very glad. I didnโ€™t look in detail, Iโ€™ll get time to understand how you builded up and let you know if a have questions. Thank a lot Rafael!

Iโ€™m back with 2 questions:

1/ How do you set the ID numbers ? Is it possible to generate these numbers automatically ?
2/ How to watch the favourites in a primary view ?

Hello again

They are generated automatically already, using uniqueID():

Thereโ€™s a slice of your primary table that contains only the favourites, you only need to create a new view that uses that slice.

Top Labels in this Space