Using a repeater as a filter for another repeater?

I recently started to make a website with my friend, and we wanted a repeater, that is connected to a database that is a list of categories, and another repeater that is connected to a database that is a list of data. If I wanted to make it so that when a user clicks one of the items displayed in the first repeater, it filters the other repeater based on the item that the user clicked, how would I do that? Thank you in advance.

For example:

$w.onReady( function () {
  $w("#dataset2").onReady(() => {
      $w("#repeaterElement").onClick(event => {
       const itemData = $w("#repeater1").data.find(e  => e._id === event.context.itemId);
	filterRepeater2(itemData);
      });
  })
})

function filterRepeater2(itemData){
  $w("#dataset2").setFilter(wixData.filter().eq("type", itemData.type));
}