parent
e347f48c19
commit
42fde81be8
@ -0,0 +1,38 @@ |
||||
export const ensureSlotTemplate = ( |
||||
slot: Element, |
||||
templateName: string, |
||||
getTemplate: () => HTMLTemplateElement | null, |
||||
) => { |
||||
if (slot.getAttribute("data-current-template") !== templateName) { |
||||
while (slot.lastChild) { |
||||
slot.removeChild(slot.lastChild); |
||||
} |
||||
|
||||
const template = getTemplate(); |
||||
if (template) { |
||||
slot.appendChild(template.content.cloneNode(true)); |
||||
} |
||||
|
||||
slot.setAttribute("data-current-template", templateName); |
||||
} |
||||
}; |
||||
|
||||
export const ensureRowsNumber = (tbody: HTMLTableSectionElement, targetRowsNumber: number) => { |
||||
while (targetRowsNumber < tbody.rows.length) { |
||||
tbody.deleteRow(0); |
||||
} |
||||
|
||||
while (targetRowsNumber > tbody.rows.length) { |
||||
tbody.insertRow(); |
||||
} |
||||
}; |
||||
|
||||
export const ensureColumnsNumber = (row: HTMLTableRowElement, targetColumnsNumber: number) => { |
||||
while (targetColumnsNumber < row.cells.length) { |
||||
row.cells[0]?.remove(); |
||||
} |
||||
|
||||
while (targetColumnsNumber > row.cells.length) { |
||||
row.insertCell(); |
||||
} |
||||
}; |
Loading…
Reference in new issue