Skip to content
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

fix: generate-new-id-for-onclick-error #116

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions flex-table-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class DataTable {

this.headers = this.cols.filter(col => !col.hidden).map(
(col, idx) => new Object({
id: "Col" + idx,
name: col.name,
icon: col.icon || null
}));
Expand Down Expand Up @@ -540,7 +541,7 @@ class FlexTableCard extends HTMLElement {

// temporary for generated header html stuff
let my_headers = this.tbl.headers.map((obj, idx) => new Object({
th_html_begin: `<th class="${cfg.columns[idx].align || 'left'}" id="${obj.name}">`,
th_html_begin: `<th class="${cfg.columns[idx].align || 'left'}" id="${obj.id}">`,
th_html_end: `${obj.name}</th>`,
icon_html: ((obj.icon) ? `<ha-icon id='icon' icon='${obj.icon}'></ha-icon>` : "")
}));
Expand All @@ -566,17 +567,17 @@ class FlexTableCard extends HTMLElement {

// add sorting click handler to header elements
this.tbl.headers.map((obj, idx) => {
root.getElementById(obj.name).onclick = (click) => {
root.getElementById(obj.id).onclick = (click) => {
// remove previous sort by
this.tbl.headers.map((obj, idx) => {
root.getElementById(obj.name).classList.remove("headerSortDown");
root.getElementById(obj.name).classList.remove("headerSortUp");
root.getElementById(obj.id).classList.remove("headerSortDown");
root.getElementById(obj.id).classList.remove("headerSortUp");
});
this.tbl.updateSortBy(idx);
if (this.tbl.sort_by.indexOf("+") != -1) {
root.getElementById(obj.name).classList.add("headerSortUp");
root.getElementById(obj.id).classList.add("headerSortUp");
} else {
root.getElementById(obj.name).classList.add("headerSortDown");
root.getElementById(obj.id).classList.add("headerSortDown");
}
this._updateContent(
root.getElementById("flextbl"),
Expand Down