Table

Table is used to display lists, select rows, and drag-sort rows on settings pages.

It is based on Antd Table and adds row selection and drag sorting for settings pages.

Basic Usage

NameStatus
1Email providerEnabled
2SMS providerDisabled
3WebhookEnabled
import React, { useState } from 'react';
import { Table } from '@nocobase/client-v2';
import type { ColumnsType } from 'antd/es/table';

interface Row {
  id: number;
  name: string;
  status: string;
}

const columns: ColumnsType<Row> = [
  { title: 'Name', dataIndex: 'name' },
  { title: 'Status', dataIndex: 'status' },
];

const dataSource: Row[] = [
  { id: 1, name: 'Email provider', status: 'Enabled' },
  { id: 2, name: 'SMS provider', status: 'Disabled' },
  { id: 3, name: 'Webhook', status: 'Enabled' },
];

export default function TableDemo() {
  const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);

  return (
    <Table<Row>
      rowKey="id"
      columns={columns}
      dataSource={dataSource}
      rowSelection={{ selectedRowKeys, onChange: setSelectedRowKeys }}
      pagination={false}
    />
  );
}

API

PropTypeDescription
rowKey`string(record, index) => React.Key`
showIndexbooleanShow row index before selection
isDraggablebooleanWhether drag sorting is enabled
onSortEnd`(from, to) => voidPromise`
showSortHandlebooleanWhether to show the default drag handle
sortHandleColumnWidthnumberWidth of the automatic drag-handle column

Attached exports

DescriptionDescription
DEFAULT_PAGE_SIZE50
PAGE_SIZE_OPTIONS[5, 10, 20, 50, 100, 200]