TinyBase logoTinyBase β

TableInHtmlTable

TableInHtmlTable(
  this: void,
  internals: Brand<"ComponentInternals">,
  props: (
    TableInHtmlTableProps &
    HtmlTableProps
  ),
): {
  $on?: (type: string, callback: (e: any) => void): () => void;
  $set?: (props: Partial<(
    TableInHtmlTableProps &
    HtmlTableProps
  )>): void;
}
TypeDescription
thisvoid
internalsBrand<"ComponentInternals">
props( TableInHtmlTableProps & HtmlTableProps )

The props passed to the component.

returns{ $on?: (type: string, callback: (e: any) => void): () => void; $set?: (props: Partial<( TableInHtmlTableProps & HtmlTableProps )>): void; }

See the <TableInHtmlTable /> (Svelte) demo for this component in action.

The component's props identify which Table to render based on Table Id, and Store (which is either the default context Store, a named context Store, or by explicit reference).

This component renders a Table by iterating over its Row objects. By default the Cells are in turn rendered with the CellView component, but you can override this behavior by providing a component for each Cell in the customCells prop. You can pass additional props to that custom component with the getComponentProps callback. See the CustomCell type for more details.

This component uses the useRowIds hook under the covers, which means that any changes to the structure of the Table will cause a re-render.

You can use the headerRow and idColumn props to control whether the Ids appear in a <th> element at the top of the table, and the start of each row.

Examples

This example creates a Provider context into which a default Store is provided. The TableInHtmlTable component within it then renders the Table in a <table> element with a CSS class.

App.svelte
<script>
  import {Provider} from 'tinybase/ui-svelte';
  import {TableInHtmlTable} from 'tinybase/ui-svelte-dom';

  export let store;
</script>

<Provider {store}>
  <TableInHtmlTable tableId="pets" className="table" />
</Provider>
import {flushSync, mount} from 'svelte';
import {createStore} from 'tinybase';
import App from './App.svelte';

const store = createStore().setTable('pets', {
  fido: {species: 'dog'},
  felix: {species: 'cat'},
});
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {store}}));
console.log(app.innerHTML);
// ->
`
<table class="table">
  <thead>
    <tr>
      <th>Id</th>
      <th>species</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th title="fido">fido</th>
      <td>dog</td>
    </tr>
    <tr>
      <th title="felix">felix</th>
      <td>cat</td>
    </tr>
  </tbody>
</table>
`;

This example creates a Provider context into which a default Store is provided. The TableInHtmlTable component within it then renders the Table with a custom component and a custom props callback for the species Cell. The header row at the top of the table and the Id column at the start of each row is removed.

FormattedCellView.svelte
<script>
  import {CellView} from 'tinybase/ui-svelte';

  export let tableId;
  export let rowId;
  export let cellId;
  export let bold = false;
</script>

{#if bold}<b>{rowId}</b>{:else}{rowId}{/if}:<CellView
  {tableId}
  {rowId}
  {cellId}
/>
App.svelte
<script>
  import {Provider} from 'tinybase/ui-svelte';
  import {TableInHtmlTable} from 'tinybase/ui-svelte-dom';
  import FormattedCellView from './FormattedCellView.svelte';

  export let store;

  const customCells = {
    species: {
      component: FormattedCellView,
      getComponentProps: (rowId) => ({bold: rowId == 'fido'}),
    },
  };
</script>

<Provider {store}>
  <TableInHtmlTable
    tableId="pets"
    {customCells}
    headerRow={false}
    idColumn={false}
  />
</Provider>
import {flushSync, mount} from 'svelte';
import {createStore} from 'tinybase';
import App from './App.svelte';

const store = createStore().setTable('pets', {
  fido: {species: 'dog'},
  felix: {species: 'cat'},
});
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {store}}));
console.log(app.innerHTML);
// ->
`
<table>
  <tbody>
    <tr>
      <td><b>fido</b>:dog</td>
    </tr>
    <tr>
      <td>felix:cat</td>
    </tr>
  </tbody>
</table>
`;

Since

v4.1.0

element

The custom element version of the component. Only present if compiled with the customElement compiler option Read more.

z_$$bindings

Does not exist at runtime, for typing capabilities only. DO NOT USE Read more.