Better identify CommandModel within commandClick

I wanted to add custom commands to the grid using the [commands] property. Everything is working as expected. But identifying the clicked command is a bit a struggle since the CommandModel class does not have and id property. Compared with ItemModel class of the toolbar the CommandModel lacks the id property. Thus I have to check on title or buttonOptions.content or buttonOptions.title to find out which command was clicked. Because that properties might be localized this is not always easy.

My workaround is to add the following object as item of [commands] properts

// @ts-ignore
{ id: 'download', buttonOption: { cssClass: 'e-flat', iconCss: 'e-icons e-download' }, title: 'Download'}

within onCommandClicked I have the following code:

onCommandClicked(args: CommandClickEventArgs) {
const rowData = (args.rowData as IInvoice)
// @ts-ignore
if(args.commandColumn?.id === 'download'){
//todo
}
}

It might be cool to have an id property on CommandModel or CommandButtonOption too.

Regards,
Michael


3 Replies 1 reply marked as answer

JC Joseph Christ Nithin Issack Syncfusion Team January 24, 2022 01:57 PM UTC

HI Michael, 

  Greetings from Syncfusion support. 

  Unlike the toolbar items the command column items will be rendered in each row. If we set id for the command button the id will not be unique. Hence we have restricted the users from setting id for the command buttons in the command column. Therefore for identifying the clicked command button users required to check on the title or buttonOptions.content or buttonOptions.title to find out which command was clicked. 

  Please get back to us for further details. 

Regards, 
Joseph I. 


Marked as answer

MM Michael Mairegger January 25, 2022 02:21 PM UTC

Hi Joseph,

ok according that reason it sounds reasonable. Therefore, I will check for content or title.


Regards,
Michael M.



JC Joseph Christ Nithin Issack Syncfusion Team January 26, 2022 11:47 AM UTC

Hi Michael, 

  Thanks for your update. 

  We are glad that the issue has been resolved 

 Please get back to us for further details. 

Regards, 
Joseph I. 


Loader.
Up arrow icon