table = {
return (index, columns, groups, cb) => {
const element = html`
<div style="overflow: auto; overflow-x: scroll; width: 800px; max-height: 300px;">
<table>
<thead>
<tr style="background: white;">
<th style="min-width: 200px; height: 44px; position: sticky; left: 0; top: 0; background: white; z-index: 2;">${index[0].name}</th>
${index.length > 1 ? html`<th style="position: sticky; top: 0; left: 200px; background: white; z-index: 2;">${index[1].name}</th>` : ''}
${columns.map(({name}) => html`<th style="padding: 12px; position: sticky; top: 0; height: 44px; background: white;">${name}</th>`)}
</tr>
</thead>
<tbody>
${groups.flatMap((members, groupNum) => members.map((datum, rowNum) => html`
<tr>
${rowNum === 0 ? html`<td style="min-width: 200px; position: sticky; left: 0; background: white;">${datum[index[0].key]}</td>` : html`<td style="min-width: 200px; background: white; left: 0; position: sticky;" />`}
${index.length > 1 ? html`<td style="position: sticky; left: 200px; background: white;">${datum[index[1].key]}</td>` : ''}
${columns.map(({key, format}) =>
html`<td
data-cell="${[...index.map(({key}) => datum[key]), key].join('<SEP>')}"
style="padding: 0 12px;"
>${(format && datum[key]) ? format(datum[key]) : (datum[key] || '')}</td>`
)}
</tr>
`))}
</tbody>
</table>
</div>
`
element.addEventListener('click', evt => {
if (evt.target.dataset.cell) {
cb(_.zipObject([...index.map(({key}) => key), 'column'], evt.target.dataset.cell.split('<SEP>')))
}
})
return element
}
}