Skip to content

Table ​

Full featured table component.

Usage ​

vue
<script setup>
import { Table } from 'gurunkit';
</script>

<template>
  <Table
    :columns="[
      { id: 'name', name: 'Name' },
      { id: 'email', name: 'Email' },
    ]"
    :data="[
      { name: 'Josh', email: 'josh@email.com' },
      { name: 'Admin', email: 'admin@email.com' },
      { name: 'Lim', email: 'lim@email.com' },
    ]"
  />
</template>
NameEmail
Joshjosh@email.com
Adminadmin@email.com
Limlim@email.com

Column ​

Set table columns via the columns prop. It is should be an array of object with the following structure:

  • id the key of each data item that will displayed.
  • name the column name.

Data ​

Set table data via the data prop. It is should be an array of object with any structure.

Each object should have a property defined as the id in the columns prop.

Custom Column Value ​

You can render a custom value in specific column by adding a value property to the object in the columns array.

The value property should be a valid function that returns a a string and receive an item prop containing the rendered item.

js
{
  id: 'name',
  name: 'Name',
  value: ({ item }) => `Name: ${item.name}`
}

Example:

vue
<script setup>
import { Table } from 'gurunkit';
import { h } from 'vue';
</script>

<template>
  <Table
    :columns="[
      {
        id: 'name',
        name: 'Name',
        value: ({ item }) => `Name: ${item.name}`,
      },
      { id: 'email', name: 'Email' },
    ]"
    :data="[
      { name: 'Josh', email: 'josh@email.com' },
      { name: 'Admin', email: 'admin@email.com' },
      { name: 'Lim', email: 'lim@email.com' },
    ]"
  />
</template>
NameEmail
Name: Joshjosh@email.com
Name: Adminadmin@email.com
Name: Limlim@email.com

Custom Render Column ​

You can render a custom component in specific column by adding a render property to the object in the columns array.

The render property should be a valid component that will be rendered and receive an item prop containing the rendered item.

js
{
  id: 'name',
  name: 'Name',
  render: ({ item }) => h('p', { class: 'font-bold' }, item.name)
}

Example:

vue
<script setup>
import { Table } from 'gurunkit';
import { h } from 'vue';
</script>

<template>
  <Table
    :columns="[
      {
        id: 'name',
        name: 'Name',
        render: ({ item }) => h('p', { class: 'font-bold' }, item.name),
      },
      { id: 'email', name: 'Email' },
    ]"
    :data="[
      { name: 'Josh', email: 'josh@email.com' },
      { name: 'Admin', email: 'admin@email.com' },
      { name: 'Lim', email: 'lim@email.com' },
    ]"
  />
</template>
NameEmail

Josh

josh@email.com

Admin

admin@email.com

Lim

lim@email.com

Empty Message ​

When the data props is empty, an empty message is displayed. Use the empty-message prop to customize the message.

vue
<script setup>
import { Table } from 'gurunkit';
import { h } from 'vue';
</script>

<template>
  <Table
    :columns="[
      { id: 'name', name: 'Name' },
      { id: 'email', name: 'Email' },
    ]"
    :data="[]"
    empty-message="Tidak ada data"
  />
</template>
NameEmail
Tidak ada data

API ​

Props ​

NameTypeRequiredDefaultDescription
columns{ id: string, name: string, render?: Vue.Component, value?: ({ item: any }) => string }[]✅[]Table columns
dataany[]❌[]Table data
empty-messagestring❌Empty dataMessage show when data is empty

Released under the MIT License.