Show/Hide Ribbon Buttons for Subgrids of the Same Table in Model Driven Apps


While working on one of my weekend Power Apps Model-Driven Apps projects, I ran into an interesting requirement. I had three subgrids of the same child entity placed inside the parent entity’s main form. Each subgrid needed to show a drop-down command with buttons — but the tricky part was:

  • Each subgrid should show different buttons based on its context.
  • All buttons should call the same JavaScript function but with different parameters.
  • The visibility must change dynamically depending on which subgrid the user is working in.

After trying multiple approaches, I found that the best way was to configure everything directly inside the Power Apps Command Bar Editor. Below is a simple breakdown of how I achieved it.

Scenario Overview

I had two tables:

  • Doctor – Parent entity
  • Appointments – Child entity

Inside the Doctor main form, I added three Appointments subgrids:

  • In-Progress Appointments
  • Upcoming Appointments
  • Completed Appointments

Each subgrid displays appointments based on the appointment status. The key functionality was simple - allow the user to move a record from one subgrid to another by updating the appointment status.

Main Form Setup

Below is a quick view of how the main form was arranged, with all three subgrids placed inside the Doctor record:


Setting Up Command Button Visibility

Since all three buttons perform similar actions, I grouped them inside a single drop-down called “Move To”.

The drop-down should appear only when a record is selected. I used the following Power FX formula:

!IsEmpty(Self.Selected.AllItems)

Next, each button under the drop-down should only appear based on the selected record’s current status. For example:

  • If the record is in "Upcoming", show only "Move to In-Progress" and "Move to Completed".
  • If the record is in "Completed", hide the option to move forward.

Here’s the Power FX formula I used for conditional button visibility:

If(
    Or(
        Text(First(Distinct(Self.Selected.AllItems,'Appointment Status')).Value)="Checked-In",
        Text(First(Distinct(Self.Selected.AllItems,'Appointment Status')).Value)="Completed"
    ),
    true,
    false
)

Setting Up Command Button Action

For the actual update, I added a JavaScript Web Resource and connected it to the button action.

The JavaScript function updates the appointment status and refreshes all the subgrids. It accepts three parameters:

  • SelectedControlSelectedItemIds – list of selected records
  • Status value – the new appointment status
  • primaryControl – the form context

Here’s the script:

Demonstration

Here’s a quick look at how the feature works in the form:



Have a great day!

Tamilarasu Arunachalam

Post a Comment

Previous Post Next Post