Table - Bitblue

The Table component is a powerful, customizable data table built with Tailwind CSS that provides features like sorting, row selection, action menus, and more. This documentation will guide you through using the component in your Svelte applications.

Basic Usage

Here's a basic example of how to use the Table component:

Actions
ID
Name
Email
Role
Status
1Alicealice@example.comAdminActive
2Bobbob@example.comUserInactive
3Charliecharlie@example.comUserActive
<script lang="ts">
	import { Table } from '@cailabs/components.data';

	// Sample data
	let users = $state([
		{ id: 1, name: 'Alice', email: 'alice@example.com', role: 'Admin', status: 'Active' },
		{ id: 2, name: 'Bob', email: 'bob@example.com', role: 'User', status: 'Inactive' },
		{ id: 3, name: 'Charlie', email: 'charlie@example.com', role: 'User', status: 'Active' }
	]);

	// Table configuration
	const columns = [
		{ header: 'ID', accessor: 'id' },
		{ header: 'Name', accessor: 'name' },
		{ header: 'Email', accessor: 'email' },
		{ header: 'Role', accessor: 'role' },
		{ header: 'Status', accessor: 'status' }
	];

	const actions = [
		{ name: 'Edit', icon: 'ri:edit-2-fill' },
		{ name: 'Deactivate', icon: 'mdi:account-cancel' }
	];

	// Event handlers
	function handleAction(event: any) {
		const { name, row } = event;
		console.log(`${name} action for:`, row);

		if (name === 'Deactivate') {
			users = users.map((u) => (u.id === row.id ? { ...u, status: 'Inactive' } : u));
		}
	}

	function handleRowClick(event: any) {
		console.log('Row clicked:', event);
	}
</script>

<Table
	data={users}
	tableColumns={columns}
	showActions
	actionLists={actions}
	rowClickable
	headerColor="blue"
	onActionClicked={handleAction}
	onRowClicked={handleRowClick}
/>

Props

Full public API from TableProps / related types.

Data & Columns

PropTypeDefaultDescription
dataany[][]Row data
tableColumnsTableColumn[]—Column definitions (required)
hiddenColumnsstring[]—Column ids hidden initially
allColumnsany—Full column catalog for visibility menus

Appearance

PropTypeDefaultDescription
headerColor'green' | 'orange' | 'white' | 'purple' | 'sky' | 'blue' | 'red' | 'pink'—Header background
headerTextColor'black' | 'white' | 'gray'—Header text color
heightnumber—Table container height
bgWhiteboolean—White body background
hideWhiteSpaceboolean—Prevent cell text wrap
showMiniWidthboolean—Compact column widths
showTableBottomPaddingboolean—Extra padding under the table
tableBottomContentSnippet—Content rendered below the table

Features

PropTypeDefaultDescription
showActionsboolean—Actions column
showCheckBoxboolean—Row selection checkboxes
showViewDetailsboolean—“View Details” in action menu
showEditboolean—“Edit” in action menu
showDeleteboolean—“Delete” in action menu
showIndexboolean—Index column
rowClickableboolean—Rows fire onRowClicked

Sorting

PropTypeDefaultDescription
sortedColumnsTableSortInfo[]—Bindable active sort
initialSortKeysTableSortInfo[]—Initial sort configuration

Selection

PropTypeDefaultDescription
selectedRowsany[]—Bindable selected rows
selectAllCheckedboolean—Bindable select-all state

Actions

PropTypeDefaultDescription
actionListsTableActionList[]—Custom action menu entries

Events

PropTypeDescription
handleCheckbox(val: any[]) => voidSelection changed
onView(val: any) => voidView Details clicked
onEdit(val: any) => voidEdit clicked
onDelete(val: any) => voidDelete clicked
onActionClicked({ name, row }) => voidCustom action clicked
onRowClicked(val: any) => voidRow clicked

Types

TableColumn

export interface TableColumn {
  header: string;
  id?: string;
  plugins?: any;
  accessor?: string | string[] | ((row: any) => unknown);
  cell?: (ctx: { value: unknown; row: any }) => unknown;
  renderComponent?: Component<any>;
  renderProps?: (ctx: {
    value: unknown;
    row: any;
    column: TableColumn;
  }) => Record<string, unknown>;
}

TableActionList

export interface TableActionList {
  name: string;
  icon?: string;
  otherClasses?: string;
  visible?: (row: any) => boolean;
  onClick?: (row: any) => void;
}

TableSortInfo

export interface TableSortInfo {
  id: string;
  order: 'asc' | 'desc';
}

Examples

Basic Table

<script>
  import { Table } from '@cailabs/components.data';
  
  const data = [
    { id: 1, name: 'Item 1', price: 10.99 },
    { id: 2, name: 'Item 2', price: 20.50 }
  ];
  
  const columns = [
    { header: 'ID', accessor: 'id' },
    { header: 'Name', accessor: 'name' },
    { header: 'Price', accessor: 'price' }
  ];
</script>

<Table data={data} tableColumns={columns} />

Function Accessor Column

<script lang="ts">
	import { Table } from '@cailabs/components.data';

	const rows = [
		{ id: 1, specialityName: 'Cardiology' },
		{ id: 2, specialityName: null }
	];

	const columns = [
		{
			header: 'Specialty Name',
			accessor: (row: any) => row?.specialityName ?? '-',
			plugins: { sort: { disable: true } }
		}
	];
</script>

<Table data={rows} tableColumns={columns} />

Render Component Per Column (JSX-like)

<script lang="ts">
	import { Table } from '@cailabs/components.data';
	import SpecialtyCell from './SpecialtyCell.svelte';

	const rows = [
		{ id: 1, specialityName: 'Cardiology' },
		{ id: 2, specialityName: null }
	];

	const columns = [
		{
			id: 'specialty',
			header: 'Specialty Name',
			accessor: (row: any) => row?.specialityName ?? '-',
			renderComponent: SpecialtyCell,
			renderProps: ({ row }) => ({ muted: !row?.specialityName }),
			plugins: { sort: { disable: true } }
		}
	];
</script>

<Table data={rows} tableColumns={columns} />
<!-- SpecialtyCell.svelte -->
<script lang="ts">
	let { value, row, muted = false } = $props();
</script>

<div class="flex items-center gap-1">
	<span class:opacity-60={muted}>{value}</span>
	{#if !row?.specialityName}
		<span class="text-xs text-gray-400">(not set)</span>
	{/if}
</div>

Table with Custom Actions

<script>
  import { Table } from '@cailabs/components.data';
  
  let products = $state([...]);
  
  const columns = [...];
  
  const actions = [
    { name: 'Edit', icon: 'ri:edit-2-fill' },
    { name: 'Archive', icon: 'mdi:archive' }
  ];
  
  function handleAction({ name, row }) {
    if (name === 'Edit') {
      // Handle edit
    } else if (name === 'Archive') {
      // Handle archive
    }
  }
</script>

<Table 
  data={products} 
  tableColumns={columns} 
  showActions 
  actionLists={actions}
  onActionClicked={handleAction}
/>

Advanced Features

Row Selection

Enable row selection with checkboxes:

<script>
  let selectedRows = $state([]);
  let selectAllChecked = $state(false);
  
  function handleSelection(rows) {
    // Do something with selected rows
    console.log(rows);
  }
</script>

<Table
  data={data}
  tableColumns={columns}
  showCheckBox
  selectedRows={selectedRows}
  selectAllChecked={selectAllChecked}
  handleCheckbox={handleSelection}
/>

Conditional Actions

Show actions conditionally based on row data:

<script>
  const actions = [
    { 
      name: 'Activate', 
      icon: 'mdi:account-check',
      visible: (row) => row.status === 'Inactive' 
    },
    { 
      name: 'Deactivate', 
      icon: 'mdi:account-cancel',
      visible: (row) => row.status === 'Active' 
    }
  ];
</script>

<Table 
  data={users} 
  tableColumns={columns} 
  showActions 
  actionLists={actions}
/>

© 2026 Bitblue is a registered trademark. All Rights Reserved.