How to show Command Bar on PCF Component added to Sub-grid

By | March 12, 2021

Introduction

PowerApps Component Framework is a natural successor of Web Resource. It gives us the choice to create field and dataset components and provide an enhanced user experience for the users to view and work with data in forms, views, and dashboards. While we were working on a request for a dataset PCF component that can be configured on the Home grid as well as on the Sub-grid, we saw that it does not incorporate add a new item, quick find, and View Selector which you would normally see escorting the OOB sub-grids. As shown in the below image, the command bar is not visible for our dataset component.

show Command Bar on PCF Component added to Sub-grid

So, how to enable those commands in your Sub-grid?

In this blog, we will show you how to enable the command buttons and view selector in your PCF component for Sub-grid.

While building the PCF component you will get a data-set tag which contains all the property-set tags in Manifest.xml file.

<data-set name=”sampleDataSet” display-name-key=”Dataset_Display_Key”>

In this tag, you will need to add cds-data-set-options attribute, which will enable the Commandbar, ViewSelector, QuickFind and other navigation items as shown below:

<data-set name=”sampleDataSet” display-name-key=”Dataset_Display_Key” cds-data-set-options=”displayCommandBar:true;displayViewSelector:true;displayQuickFind:true”>

The cds-data-set-options directs model-driven form to display the command bar, view selector, and the quick find when the Boolean value is true.

You can enable/disable these three properties mentioned below as per your requirements by changing the Boolean value.

Property Value Description
displayCommandBar Boolean Enables/Disables the command bar on the Subgrid.
displayViewSelector Boolean Enables/Disables the view selector in the Subgrid.
displayQuickFind Boolean Enables/Disables the quick find in the Subgrid.

Also, it is mandatory to enable View Selector as well as Display Search Box while adding the Sub-grid to the form in customization to make the View Selector and Quick Find work.

1-show Command Bar on PCF Component added to Sub-grid

Note: In case if the view selector is off or Display Search Box is left untick in the customization, whether you enable them or not from the cds-data-set-options, View Selector and Quick Find (Search box) will not be visible on the Sub-grid.

If you do not mention a property in the cds-data-set-options attribute, then it will by default take it as false and will not show on the Sub-grid.

Also, these changes in the properties only affects the Sub-grid and not the Home grid.
Now, let us build our component with npm run build command.

Note: If you are using an old version of PCF, you may get the following error while building your component –
Manifest validation error: instance.manifest.control[0].data-set[0].$ additionalProperty “cds-data-set-options” exists in instance when not allowed

To overcome and resolve this error you need to navigate to Manifestschema.json file (which is located in the node_modules\pcf-scripts folder).

In this file, search for dataSetAttribs and you will get the below object. Set the additionalProperties as true, which will do our work.

“dataSetAttribs”: {
“type”: “object”,
“properties”: {
“name”: { “type”: “string” },
“display-name-key”: { “type”: “string” },
“description-key”: { “type”: “string” }
},
“required”: [“name”, “display-name-key”],
“additionalProperties”: true
},

This change is not required in the new version as Microsoft has given full support to this attribute and for the user with new version their object will appear as shown below:

“dataSetAttribs”: {
“type”: “object”,
“properties”: {
“name”: {
“type”: “string”
},
“display-name-key”: {
“type”: “string”
},
“description-key”: {
“type”: “string”
},
“cds-data-set-options”: {
“type”: “string”
}
},
“required”: [
“name”,
“display-name-key”
],
“additionalProperties”: false
}
After building your component and adding it on your Sub-grid, you will be able to see the View Selector and all the command buttons.

1-show Command Bar on PCF Component added to Sub-grid

Conclusion

As illustrated above, you can now easily enable or disable the command bar and navigation items in the Sub-grid PCF component.