Question

Issues with adding to rowToolbarItems for a list/grid in Freedom UI

On a Freedom UI section list page I am adding some items to the rowToolbarItems for the list. 

Issue 1:

Adding any items to the rowToolbarItems completely replaces the list. Meaning you lose the OOTB Open, Copy, Delete menu items. It would be great to be able to append (optionally, since some cases would be nice to remove items)

Issue 2: 

I cannot get rowToolbarItems to execute a custom request. If I add an item to the row using an OOTB request, such as a crt.CreateRecordRequest or crt.UpdateRecordRequest it all works. However, if I use my own custom request name and then add that request handler to the handlers section of the page code, my custom handler is never executed. 

Example: Adding this to the rowToolbarItems:

viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
    {
        "operation": "merge",
        "name": "DataTable",
        "values": {
            ...,
            "rowToolbarItems": [{
                "type": 'crt.MenuItem',
                "caption": 'Do something',
                "icon": 'open-button-icon',
                "clicked": {
                    "request": 'cfx.SomeCustomHandler',
                    "params": {
                        "itemsAttributeName": "Items",
                        "recordId": "$Items.PDS_Id",
                    },
                    "useRelativeContext": true
                }
            }]
        }
        ...
    },
    ...
]/**SCHEMA_VIEW_CONFIG_DIFF*/

Then this handler to the page: 

handlers: /**SCHEMA_HANDLERS*/[
    {
        request: "cfx.SomeCustomHandler",
        handler: async (request, next) => {
            // this is never executed
            return next?.handle(request);
        }
    }
]/**SCHEMA_HANDLERS*/

The handler is never executed/fired when the item is clicked. Have I missed something?

Ryan

Like 0

Like

2 comments

Hmm. Apparently, if I remove the useRelativeContext: true my custom handler does get executed. I am not sure why. I still get my param for the recordId passed in the request. 

According do this I need to set useRelativeContext to true for rowRoolbarItems. Maybe I've misunderstood the docs?

Hello Ryan,

 

1) It's not mentioned in the article, but it's also required to add out-of-the-box actions in the DataTable merge so they could be also displayed:

 {
                "operation": "merge",
                "name": "DataTable",
                "values": {
                    "layoutConfig": {
                        "basis": "100%",
                        "width": 300
                    },
                    "columns": [
                        {
                            "id": "f252f581-0ccf-44ac-b7c9-c00df2ad9919",
                            "code": "PDS_Name",
                            "caption": "#ResourceString(PDS_Name)#",
                            "dataValueType": 1
                        },
                    ],
                    "primaryColumnName": "PDS_Id",
                    "sorting": "$ItemsSorting | crt.ToDataTableSortingConfig: 'Items'",
					"rowToolbarItems": [
					    // default open action
						{
							type: 'crt.MenuItem',
							caption: 'DataGrid.RowToolbar.Open',
							icon: 'edit-row-action',
							disabled: "$Items.PrimaryModelMode | crt.IsEqual : 'create'",
							clicked: {
								request: 'crt.UpdateRecordRequest',
								params: {
									"itemsAttributeName": "Items",
									"recordId": "$Items.PDS_Id",
								},
							},
						},
						// default copy action
						{
							type: 'crt.MenuItem',
							caption: 'DataGrid.RowToolbar.Copy',
							icon: 'copy-row-action',
							disabled: "$Items.PrimaryModelMode | crt.IsEqual : 'create'",
							clicked: {
								request: 'crt.CopyRecordRequest',
								params: {
									"itemsAttributeName": "Items",
									"recordId": "$Items.PDS_Id",
								},
							},
						},
						// default delete action
						{
							type: 'crt.MenuItem',
							caption: 'DataGrid.RowToolbar.Delete',
							icon: 'delete-row-action',
							clicked: {
								request: 'crt.DeleteRecordRequest',
								params: {
									"itemsAttributeName": "Items",
									"recordId": "$Items.PDS_Id",
								}
							},
						},
						// new run process action					
						{
							"type": "crt.MenuItem",
							"caption": "Run your process",
							"icon": "process-button-icon",
							"clicked": {
								"request": "crt.RunBusinessProcessRequest",
								"params": {
									"processName": "UsrTestProcess", // UsrTestProcess - your process name
									"processRunType": "ForTheSelectedPage",
									"recordIdProcessParameterName": "ProcessRecordId" // ProcessRecordId - process parameter for record Id
								},
							}
						}
					]
                }
            }

Tested - indeed it works and should be done.

 

2) As for the useRelativeContext property: we don't recommend using it, this API is not public at the moment. Please trigger your handler without using useRelativeContext.

Show all comments