Add Like counters to multiple dataset items on same page?

Hello. I see we can add third-party apps to count Likes, but they seem to track Likes for the whole page. Is it possible to connect Likes to multiple dataset items within a page?

One way I could imagine doing this would be if databases had a field option for Counting, where user input, such as a click on a Like button, would add to that item’s dynamic count in its database. Then, if we could sort by count, we could, for example, show the most popular items on a page first.

Am I missing a way to accomplish this?

Thank you.

Hi Jeff,
Currently we have no ready-made such button, and you may need to write the code for it yourself.

Schachar

Jeff,

That’s a good idea re implementation. You can use the wix-data update function to make that happen.

 import wixData from 'wix-data'; 
 
 export function likeClicked($w,event){

 //Do like animation here. You know, the one with the heart being filled in.

  let newPost= { 
 "_id": "00001", // Note the only required value is the ID
 "post_title": "Google Duplex will not take over!", 
 "author": "John Doe", 
 "likes": getLikeCount()+1 }; 
 //In reality you would implement getLikeCount() so it doesn't have to query DB
 //each time it wants to get likes.  
 
 //The update function is called with the following parameters:
 //update(name_of_collection: String, new_item_to_update_with: Object, [options:WixDataOptions]).
 //It returns a Promise with the newly added item.
 
 wixData.update("myCollection", newPost)
 .then( (results) => { let item = results;
      //Do whatever you need to do after the like has been sent to the DB.
  })
 .catch( (err) => { 
 
      //Catch any errors silently without affecting user experience.
      let errorMsg = err; 
  } ); 
  
  }

There might be an issue there. Giving update permission on a collection to anonymous might be unsafe.