Smart UI Components & Libraries – Grid, Scheduler, Gantt, Kanban for Angular, React, Next.js, Vue, Blazor, JavaScript › Forums › Data Grid › Custom column header and column group header buttons
- This topic has 4 replies, 3 voices, and was last updated 1 day, 21 hours ago by
Patrick Walsh.
-
AuthorPosts
-
November 24, 2025 at 10:34 pm #113216
Patrick Walsh
ParticipantI’m using the smart-ui-grid web component and I need to add a button to each column’s and column group’s header so that I can have my app do things related to that column.
What is the best way to accomplish this?
I’ve tried a couple things based on the docs:
- Setting a labelTemplate gets me close, but I haven’t found a way to bind a click event handler to it.
- Enabling the columnMenu, but I need to customize the menu options.
November 25, 2025 at 2:19 pm #113217Markov
KeymasterHi Patrick,
You can use something like this: ` “columns”: [
{
“label”: “Task ID”, allowEdit: false, “dataType”: “number”, “template”: “autoNumber”, width: 150,
labelTemplate: function () {
return “<smart-button>Add</smart-button><span style=\”margin-left: 20px;\”>ID</span>”;
}
},`It renders a button inside the column header. Then you can bind to the columnClick event and handle the button click.
Best regards,
MarkovSmart UI Team
https://www.htmlelements.com/November 25, 2025 at 10:56 pm #113219Patrick Walsh
ParticipantHi, Markov:
Thank you for suggesting that approach. I’m able to catch clicks on the column, but it doesn’t appear possible to distinguish a click on the button from unrelated clicks on the column. This is important because we want to also have
allowColumnHeaderSelectionenabled so the column is selected on click.I would need the composed path or target, but these are not useful from where columnClicked is dispatched. What is the way forward from here?
Cheers,
Patrick
-
This reply was modified 2 days, 19 hours ago by
Patrick Walsh.
November 26, 2025 at 5:53 pm #113231admin
KeymasterHi Patrick,
We just released a new version. You have an originalEvent parameter in the column click.
Alternatively, the column definition includes a new headerTemplate property which allows you to setup the column’s header after the label template is rendered.Here’s the code:
` “label”: “Task ID”, allowEdit: false, “dataType”: “number”, “template”: “autoNumber”, width: 150,
labelTemplate: function () {
return “Add ID“;
},
headerTemplate: function (header) {
const button = header.querySelector(‘smart-button’);
button.addEventListener(‘pointerdown’, function (event) {
grid.addNewRow();
event.stopPropagation();
});
}`Hope this helps.
Best regards,
MarkovSmart UI Team
https://www.htmlelements.com/November 26, 2025 at 9:42 pm #113232Patrick Walsh
ParticipantAwesome—thank you for the update! I will try those new options.
-
AuthorPosts
- You must be logged in to reply to this topic.