Skip to content
On this page

createColumn

Creates a column object for a <Table> or <MiniTable>.

Usage

vue
<script setup lang="ts">
import { Table, createColumn } from '@screaming/tables'

const columns = [
  createColumn('key'),
  createColumn('key', { ... }),
  ...
]
</script>

<template>
  <!-- other props omitted for brevity -->
  <Table :columns="columns" />
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Type Definitions

ts
import { h as _h, type VNode } from 'vue'
import { type Obj } from '@screaming/utils'

interface Column {
  key: string
  width: number
  sortOrder: 'asc' | 'desc'
  permanent?: boolean
  sortable: boolean
  rankable: boolean
  createTitle: (h: typeof _h) => VNode
  format: ({ value, h, row }: { value: any; h: typeof _h; row: Obj }) => VNode | string
}

interface CreateColumnOptions {
  title?: string | ((h?: typeof _h) => VNode)
  width?: number
  sortOrder?: 'asc' | 'desc'
  permanent?: boolean
  sortable?: boolean
  rankable?: boolean
  format?: ({ value, h, row }: { value?: any; h?: typeof _h; row?: Obj }) => VNode | string
}

/**
 * @param key - The column's key.
 * @param options - Function options.
 * @param options.title - The column's <th> content.
 * @param options.width - The column's width with respect to neighbouring columns.
 * @param options.sortOrder - The column's sorting order.
 * @param options.permanent - If a column should always be visible.
 * @param options.sortable - If the column can be sorted.
 * @param options.rankable - If the column can be ranked (requires options.sortable: true).
 * @param options.format - Formatting function for the column's cell values.
 */
export declare function createColumn(key: string, options?: CreateColumnOptions): Column
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36