2019-09-27 18:03:31 +02:00
|
|
|
<script>
|
2020-02-03 10:50:30 +01:00
|
|
|
export let columns = []
|
|
|
|
export let data = ""
|
|
|
|
export let tableClass = ""
|
|
|
|
export let theadClass = ""
|
|
|
|
export let tbodyClass = ""
|
|
|
|
export let trClass = ""
|
|
|
|
export let thClass = ""
|
|
|
|
export let onRowClick
|
2019-09-27 18:03:31 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
export let _bb
|
2019-10-18 18:32:03 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const rowClickHandler = row => () => {
|
2020-09-10 22:11:05 +02:00
|
|
|
// call currently only accepts one argument, so passing row does nothing
|
|
|
|
// however, we do not expose this event anyway. I am leaving this
|
|
|
|
// in for the future, as can and probably should hande this
|
|
|
|
_bb.call("onRowClick", row)
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-10-18 18:32:03 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const cellValue = (colIndex, row) => {
|
|
|
|
const val = _bb.getStateOrValue(_bb.props.columns[colIndex].value, row)
|
|
|
|
return val
|
|
|
|
}
|
2019-09-27 18:03:31 +02:00
|
|
|
</script>
|
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
<table class={tableClass}>
|
|
|
|
<thead class={theadClass}>
|
|
|
|
<tr class={trClass}>
|
|
|
|
{#each columns as col}
|
|
|
|
<th class={thClass}>{col.title}</th>
|
|
|
|
{/each}
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class={tbodyClass}>
|
|
|
|
{#if data}
|
|
|
|
{#each data as row}
|
|
|
|
<tr class={trClass} on:click={rowClickHandler(row)}>
|
|
|
|
{#each columns as col, index}
|
2019-10-18 18:32:03 +02:00
|
|
|
<th class={thClass}>{cellValue(index, row)}</th>
|
2020-02-03 10:50:30 +01:00
|
|
|
{/each}
|
2019-09-27 18:03:31 +02:00
|
|
|
</tr>
|
2020-02-03 10:50:30 +01:00
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2019-09-27 18:03:31 +02:00
|
|
|
|
|
|
|
<style>
|
2020-02-03 10:50:30 +01:00
|
|
|
.table-default {
|
2019-09-27 18:03:31 +02:00
|
|
|
width: 100%;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
color: #212529;
|
|
|
|
border-collapse: collapse;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-09-27 18:03:31 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.table-default .thead-default .th-default {
|
2019-09-27 18:03:31 +02:00
|
|
|
vertical-align: bottom;
|
|
|
|
border-bottom: 2px solid #dee2e6;
|
|
|
|
font-weight: bold;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-09-27 18:03:31 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.table-default .th-default {
|
|
|
|
padding: 0.75rem;
|
2019-09-27 18:03:31 +02:00
|
|
|
vertical-align: top;
|
|
|
|
border-top: 1px solid #dee2e6;
|
|
|
|
font-weight: normal;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-09-27 18:03:31 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.th-default {
|
2019-09-27 18:03:31 +02:00
|
|
|
text-align: inherit;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-09-27 18:03:31 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.table-default .tbody-default .tr-default:hover {
|
2019-09-27 18:03:31 +02:00
|
|
|
color: #212529;
|
2020-02-03 10:50:30 +01:00
|
|
|
background-color: rgba(0, 0, 0, 0.075);
|
2019-09-27 18:03:31 +02:00
|
|
|
cursor: pointer;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
|
|
|
</style>
|