Skip to content

Table

A powerful data table component with selection, sorting, and custom column rendering.

Basic Usage

vue
<script setup>
import { ref } from 'vue'

const columns = [
  { key: 'name', title: 'Name' },
  { key: 'age', title: 'Age', align: 'center' },
  { key: 'email', title: 'Email' }
]

const data = [
  { id: 1, name: 'John Doe', age: 28, email: 'john@example.com' },
  { id: 2, name: 'Jane Smith', age: 32, email: 'jane@example.com' },
  { id: 3, name: 'Bob Johnson', age: 45, email: 'bob@example.com' }
]
</script>

<template>
  <MTable :columns="columns" :data="data" />
</template>

With Index Column

vue
<template>
  <MTable :columns="columns" :data="data" show-index />
</template>

Stripe Style

vue
<template>
  <MTable :columns="columns" :data="data" stripe />
</template>

Row Selection

vue
<script setup>
const selectedKeys = ref([])

const handleSelect = (keys, rows) => {
  selectedKeys.value = keys
  console.log('Selected rows:', rows)
}
</script>

<template>
  <MTable 
    :columns="columns" 
    :data="data" 
    selectable
    :selected-keys="selectedKeys"
    @select="handleSelect"
  />
</template>

Custom Column Content

Use named slots to customize column content:

vue
<template>
  <MTable :columns="columns" :data="data">
    <template #name="{ row, value }">
      <span class="font-bold text-blue-600">{{ value }}</span>
    </template>
    <template #actions="{ row }">
      <MButton size="small" @click="handleEdit(row)">Edit</MButton>
      <MButton size="small" type="danger" @click="handleDelete(row)">Delete</MButton>
    </template>
  </MTable>
</template>

Loading State

vue
<template>
  <MTable :columns="columns" :data="data" :loading="isLoading" />
</template>

Props

NameTypeDefaultDescription
columnsColumn[][]Column configuration array
dataany[][]Table data
rowKeystring'id'Unique key for each row
loadingbooleanfalseShow loading overlay
stripebooleanfalseStriped row style
showIndexbooleanfalseShow index column
selectablebooleanfalseEnable row selection
selectedKeys(string | number)[][]Currently selected row keys

Column Configuration

NameTypeDescription
keystringColumn data key
titlestringColumn header title
widthstringColumn width (e.g., '100px', '20%')
minWidthstringMinimum column width
align'left' | 'center' | 'right'Text alignment

Events

NameParametersDescription
row-click(row, index)Triggered when a row is clicked
select(keys, rows)Triggered when selection changes
select-all(selected: boolean)Triggered when select all checkbox changes

Slots

NameScopeDescription
[columnKey]{ row, index, value }Custom content for specific column
empty-Content for empty state

Released under the MIT License.