Add table placeholder

This commit is contained in:
Andrew Kingston 2021-04-09 14:48:26 +01:00
parent 4e214f4e87
commit 54583873ed
1 changed files with 66 additions and 34 deletions

View File

@ -15,7 +15,7 @@
export let allowEditColumns = true export let allowEditColumns = true
export let selectedRows = [] export let selectedRows = []
export let customColumnRenderer = SelectEditRenderer export let customColumnRenderer = SelectEditRenderer
export let customColumnTitle export let customColumnTitle = null
export let customRenderers = [] export let customRenderers = []
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -87,7 +87,8 @@
const getFields = (schema, showAutoColumns) => { const getFields = (schema, showAutoColumns) => {
let columns = [] let columns = []
let autoColumns = [] let autoColumns = []
Object.entries(schema).forEach(([field, fieldSchema]) => { Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
schema[field].name = field
if (!fieldSchema?.autocolumn) { if (!fieldSchema?.autocolumn) {
columns.push(field) columns.push(field)
} else if (showAutoColumns) { } else if (showAutoColumns) {
@ -200,6 +201,7 @@
</tr> </tr>
</thead> </thead>
<tbody class="spectrum-Table-body"> <tbody class="spectrum-Table-body">
{#if sortedRows?.length}
{#each sortedRows as row, idx} {#each sortedRows as row, idx}
<tr <tr
on:click={() => toggleSelectRow(row)} on:click={() => toggleSelectRow(row)}
@ -207,7 +209,8 @@
class:hidden={idx < firstVisibleRow || idx > lastVisibleRow}> class:hidden={idx < firstVisibleRow || idx > lastVisibleRow}>
{#if idx >= firstVisibleRow && idx <= lastVisibleRow} {#if idx >= firstVisibleRow && idx <= lastVisibleRow}
{#if customColumnRenderer} {#if customColumnRenderer}
<td class="spectrum-Table-cell spectrum-Table-cell--divider"> <td
class="spectrum-Table-cell spectrum-Table-cell--divider">
<div class="spectrum-Table-cell-content"> <div class="spectrum-Table-cell-content">
<svelte:component <svelte:component
this={customColumnRenderer} this={customColumnRenderer}
@ -233,6 +236,16 @@
{/if} {/if}
</tr> </tr>
{/each} {/each}
{:else}
<div class="placeholder">
<svg
class="spectrum-Icon spectrum-Icon--sizeXXL"
focusable="false">
<use xlink:href="#spectrum-icon-18-Table" />
</svg>
<div>No rows found.</div>
</div>
{/if}
</tbody> </tbody>
</table> </table>
</div> </div>
@ -322,6 +335,25 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.placeholder {
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: var(
--spectrum-table-cell-text-color,
var(--spectrum-alias-text-color)
);
}
.placeholder div {
margin-top: 10px;
font-size: var(
--spectrum-table-cell-text-size,
var(--spectrum-alias-font-size-default)
);
}
tbody { tbody {
z-index: 1; z-index: 1;
} }