Determine Which Button Clicked When Multiple custom commands used on one row.
Hi,
I have 4 custom command buttons on each row of the grid.
What is the best way to pass out to OnCommandClicked which one of the buttons was clicked?
Possible Idea: Could you add a Command Button Name or Command Button Id to the CommandButtonOptions()?
When using the below line of code, I could do it, but I only want to show icons on the button, not words.
public void OnCommandClicked(CommandClickEventArgs<MyModel> args)
{
SelectedCommandButton = args.CommandColumn.ButtonOption.Content;
}
------
<GridColumn HeaderText="Group Actions" TextAlign="TextAlign.Center" Width="300">
<GridCommandColumns>
<GridCommandColumn ButtonOption="@(new CommandButtonOptions() { CssClass="e-icons e-preview", Content="Preview"})" Title="View Details"></GridCommandColumn>
<GridCommandColumn ButtonOption="@(new CommandButtonOptions() { CssClass="e-icons e-edit" , Content="Edit"})" Title="Edit Row"></GridCommandColumn>
<GridCommandColumn ButtonOption="@(new CommandButtonOptions() { CssClass="e-icons e-copy" , Content="Clone"})" Title="Clone"></GridCommandColumn>
<GridCommandColumn ButtonOption="@(new CommandButtonOptions() { CssClass="e-icons e-mt-createlink" , Content="MakeLink"})" Title="Make Link"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
RN
Rahul Narayanasamy
Syncfusion Team
June 11, 2021 03:33 PM UTC
Hi Victor,
Greetings from Syncfusion.
Query: Determine Which Button Clicked When Multiple custom commands used on one row.
We have validated your query and you want to know which command button is clicked. We suggest you to check which button is clicked by using command button content(args.CommandColumn.ButtonOption.Content) or Title property of the CommandColumn(args.CommandColumn.Title).
If you have only shown icon in command button, then you can use Title property of the CommandColumn(args.CommandColumn.Title) to identify which button is clicked. Find the below code snippets for your reference.
|
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315">
<GridEvents CommandClicked="OnCommandClicked" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
. . .
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn HeaderText="Manage Records" Width="150">
<GridCommandColumns>
<GridCommandColumn Title="CustomButton1" ID="CustomButton1" ButtonOption="@(new CommandButtonOptions() { Content = "CustomButton1", CssClass = "e-flat" })"></GridCommandColumn>
<GridCommandColumn Title="CustomButton2" ID="CustomButton2" ButtonOption="@(new CommandButtonOptions() { Content = "CustomButton2", CssClass = "e-flat" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
. . .
public void OnCommandClicked(CommandClickEventArgs<Order> args)
{
if(args.CommandColumn.ButtonOption.Content == "CustomButton1")
{
// Perform required operations here
}
if (args.CommandColumn.Title == "CustomButton2")
{
// Perform required operations here
}
}
} |
Query: Possible Idea: Could you add a Command Button Name or Command Button Id to the CommandButtonOptions()?
Also, we have already considered this requirement as an usability improvement feature and logged the improvement report for the same. Thank you for taking the time to request this improvement “Need to send whole command column object in CommandClicked event arguments” and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the improvement feature in any of our upcoming release. Until then we appreciate your patience.
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.
Please let us know if you have any concerns.
Regards,
Rahul
Marked as answer
VI
Victor
June 11, 2021 06:00 PM UTC
Thanks for your answer and for logging my enhancement request.
I understand the only option for me is to use:
Title property of the CommandColumn(args.CommandColumn.Title
...
I depend on that value to describe the icon only button in more detail to the user.
Example = Grid of Apps
When they hover over the first button it has an icon on it.... the tool tip which is the title shows "Setup this App".
I actually want to put the name of the app in that row in the future in the title of the tooltip which equal "title".. ( Setup {AppName} )
So if I make that title dynamic in some way, it won't work for capturing the command button that was clicked.
Hopefully you see that the Command button has much promise and power if we could only set a button name or ID.
Please expidite this enhancement :) ...
RN
Rahul Narayanasamy
Syncfusion Team
June 14, 2021 12:34 PM UTC
Hi Victor,
Thanks for your update.
We have validated your query and we understood that you will change the command column Title property dynamically. Based on your scenario, we could not capture which command button is clicked by using Title property.
As we said in our previous update, we have already considered this requirement(Need to send ID property to command clicked event) as an usability improvement feature and logged the improvement report for the same. Thank you for taking the time to request this improvement “Need to send whole command column object in CommandClicked event arguments” and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the improvement feature in any of our upcoming release. Until then we appreciate your patience.
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.
Please let us know if you have any concerns.
Regards,
Rahul
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
VI Victor
- Jun 10, 2021 05:10 AM UTC
- Jun 14, 2021 12:34 PM UTC