-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom HTMLElement inside header loses event handler #1605
Comments
Start a new pull request in StackBlitz Codeflow. |
This is a regression caused by PR #1476 which was fixing another bug #1475 in PR #1476, I used At this point, I'm not sure if the use of @zewa666 @ardakod I'm opened to suggestion here side note, my tendency of using animated gif can be quite useful, especially when revisiting old issues like this one |
well the root-cause is understandable.
so the issue I'd say is how the label for the picker is constructed as merely the text needs to be displayed there but not the actual element moved. I've created a PR with a potential solution. |
yeah I found that if I modify the global value extractor as below, it fixes the issue without the need for the clone. I'm not sure reading the function pickerHeaderColumnValueExtractor(column: Column, gridOptions?: GridOption) {
let colName = column?.name ?? '';
if (colName instanceof HTMLElement) {
colName = colName.textContent || '';
}
const headerGroup = column?.columnGroup || '';
const columnGroupSeparator = gridOptions?.columnGroupSeparator ?? ' - ';
if (headerGroup) {
return headerGroup + columnGroupSeparator + colName;
}
return colName;
} EDIT ohhh I just realized you did the exact same changes lol, thanks for the PR, I left some comments |
yeah it was just a quick one to show where the potential solution could go. Seeing you did the same makes me feel like its the proper thing to do. I've closed my PR since you're at it anyways. if you don't like textContent you could instead use the deepClone here since you'll most likely not care about the attached handlers in the context of the columnPicker. I'd personally stick with the textContent as it feels cleaner though |
yeah the concern I have is the following (I've also put the same comment in your now closed PR) I had another possible problem with the that is using the following code const div = document.createElement('div');
const button = document.createElement('button');
button.className = 'button button-small';
button.textContent = 'click';
button.addEventListener('click', () => alert('hi'));
div.appendChild(document.createTextNode('Column 1 '));
div.appendChild(button);
this.columnDefinitions = [
{
id: 'sel', name: div, field: 'num', width: 80, type: FieldType.number,
excludeFromExport: true,
resizable: true,
filterable: true,
selectable: false,
focusable: false
}, |
well if you'd want to maintain that functionality here too, which I quite frankly think is a sideeffect users typically dont think off, we'd need a deepClone of the element for the picker. I think the better approach alltogether would be to introduce something like a |
so do you mean something like this instead headerColumnValueExtractor: (columnDef: Column) => getHtmlStringOutput(columnDef.pickerLabel || columnDef.name || '', 'innerHTML') EDIT actually it seems that I have to do this change on the global value extractor instead |
yep exactly, that would keep textContent as default, which most likely will be fine 9 out of 10 times. but for these other cases you can create the label to override the behavior |
Yeah that seems like a nice feature, now with this new prop (renamed it to this.columnDefinitions = [
{
id: 'sel', name: div, field: 'num', width: 80, type: FieldType.number,
+ columnPickerLabel: 'Custom Label',
excludeFromExport: true,
resizable: true,
filterable: true,
selectable: false,
focusable: false
}, |
feat: add `columnPickerLabel` for custom label, also fix #1605
Describe the bug
This bug was first reported in Angular-Slickgrid but is really code related to Slickgrid-Universal, so I'm closing the Angular-Slickgrid issue and opening this new one with same info
Reproduction
Which Framework are you using?
Angular
Environment Info
Validations
The text was updated successfully, but these errors were encountered: