Row action - render based on result of subquery

  • 1
  • Idea
  • Updated 3 years ago
  • Under Consideration
I have a page with tabs for products and bookmarked products(custom object).

It would be great if the row action (bookmark) could be conditionally rendered based on the result of a subquery ie. if the product has been bookmarked by the current user

I currently use a product model that uses the result of a subquery to only retrieve Products that have not been bookmarked
Photo of William Keam

William Keam

  • 302 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
You are correct that conditional rendering of row actions cannot be done on a subquery,  but you can create a template on your row,  and use the conditional rendering provided by our mustache syntax to show an icon (or really anything)  if there are child records for that particular row. 

That syntax would look like this. 

{{#ChildRelationshipName}}Text or Html Code or Model Merge syntax {{/ChildRelationshipName}}
Photo of William Keam

William Keam

  • 302 Points 250 badge 2x thumb
Hi Rob,

Sorry I don't follow you. Are you able to provide an example?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Yup here is an example. 

I have an account tab page where I want to show an Icon if there are contacts on the account. 

1.  I add the contacts child relationship to my accounts model (Unless you want to show contact details,  you don't need to add any fields)



2. On the Accounts table add a template field. With this sort of syntax in the template: 
{{#Contacts}}<div class="sk-icon inline nx-rowaction sk-icon-partners"></div>{{/Contacts}}



What this does is look at the row - and if there are contacts,  the icon will be shown,  if no contacts are there,  nothing will be shown. 
You can wrap the Div in a <a href.... tag to make it link to a detail page. 


3.  This produces a page that looks like this:  




There you go... 
Photo of William Keam

William Keam

  • 302 Points 250 badge 2x thumb
Thanks Rob!

I didn't see the Child Relationship Tab on the models all good now.

Cheers,
William
Photo of William Keam

William Keam

  • 302 Points 250 badge 2x thumb
Hi Rob,

I have another question. Is it possible to run actions from template components using javascript? If so are you able to point me in the direction of some documentation or examples? I have searched but was not able to find anything relating to running actions from template components.

Cheers,
William
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Ugh.  Your subsequent question was rattling around my head when I wrote the prior answer.  When you go to a template, you do lose the hooks into the action framework.  You are now in the realm of  a custom field renderer that uses the javascript API to show the icon conditionally,  and then controls the actions that occur when that link is selected.   Here is a community post sketching out this strategy:   https://community.skuidify.com/skuid/topics/custom-popup