Demos#
#代码演示
#基础用法
Issue 管理
标题 | 状态 | 标签 | 创建时间 | 操作 | |
|---|---|---|---|---|---|
暂无数据 | |||||
查询表格
import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button, Dropdown, message, Space, Tag } from 'antd';
import { useRef } from 'react';
import request from 'umi-request';
export const waitTimePromise = async (time: number = 100) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
};
export const waitTime = async (time: number = 100) => {
await waitTimePromise(time);
};
type GithubIssueItem = {
url: string;
id: number;
number: number;
title: string;
labels: {
name: string;
color: string;
}[];
state: string;
comments: number;
created_at: string;
updated_at: string;
closed_at?: string;
};
const columns: ProColumns<GithubIssueItem>[] = [
{
dataIndex: 'index',
valueType: 'indexBorder',
width: 48,
},
{
title: '标题',
dataIndex: 'title',
copyable: true,
ellipsis: true,
tooltip: '标题过长会自动收缩',
formItemProps: {
rules: [
{
required: true,
message: '此项为必填项',
},
],
},
},
{
disable: true,
title: '状态',
dataIndex: 'state',
filters: true,
onFilter: true,
ellipsis: true,
valueType: 'select',
valueEnum: {
all: { text: '超长'.repeat(50) },
open: {
text: '未解决',
status: 'Error',
},
closed: {
text: '已解决',
status: 'Success',
disabled: true,
},
processing: {
text: '处理中',
status: 'Processing',
},
},
},
{
disable: true,
title: '标签',
dataIndex: 'labels',
search: false,
formItemRender: (_, { defaultRender }) => {
return defaultRender(_);
},
render: (_, record) => (
<Space>
{record.labels.map(({ name, color }) => (
<Tag color={color} key={name}>
{name}
</Tag>
))}
</Space>
),
},
{
title: '创建时间',
key: 'showTime',
dataIndex: 'created_at',
valueType: 'date',
sorter: true,
search: false,
},
{
title: '创建时间',
dataIndex: 'created_at',
valueType: 'dateRange',
hideInTable: true,
search: {
transform: (value) => {
return {
startTime: value[0],
endTime: value[1],
};
},
},
},
{
title: '操作',
valueType: 'option',
key: 'option',
render: (text, record, _, action) => [
<a
key="editable"
onClick={() => {
action?.startEditable?.(record.id);
}}
>
编辑
</a>,
<a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
查看
</a>,
<TableDropdown
key="actionGroup"
onSelect={() => action?.reload()}
menus={[
{ key: 'copy', name: '复制' },
{ key: 'delete', name: '删除' },
]}
/>,
],
},
];
const Demo = () => {
const actionRef = useRef<ActionType>();
return (
<ProTable<GithubIssueItem>
columns={columns}
actionRef={actionRef}
cardBordered
request={async (params) => {
await waitTime(2000);
return request<{
data: GithubIssueItem[];
}>('https://proapi.azurewebsites.net/github/issues', {
params,
});
}}
editable={{
type: 'multiple',
}}
columnsState={{
persistenceKey: 'pro-table-singe-demos',
persistenceType: 'localStorage',
defaultValue: {
option: { fixed: 'right', disable: true },
},
onChange: () => {
message.info('列设置已更新');
},
}}
rowKey="id"
search={{
labelWidth: 'auto',
}}
options={{
setting: {
listsHeight: 400,
},
}}
form={{
syncToUrl: (values, type) => {
if (type === 'get') {
return {
...values,
created_at: [values.startTime, values.endTime],
};
}
return values;
},
}}
pagination={{
pageSize: 5,
onChange: (page, pageSize) => {
message.info(`第 ${page} 页${pageSize ? `,每页 ${pageSize} 条` : ''}`);
},
}}
dateFormatter="string"
headerTitle="Issue 管理"
toolBarRender={() => [
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
actionRef.current?.reload();
}}
type="primary"
>
新建
</Button>,
<Dropdown
key="menu"
menu={{
items: [
{ label: '导入数据', key: 'import' },
{ label: '导出数据', key: 'export' },
{ label: '批量分配', key: 'assign' },
],
}}
>
<Button>
<EllipsisOutlined />
</Button>
</Dropdown>,
]}
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
无查询表单
import { DownOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button } from 'antd';
import {
createTableDataSource,
DEMO_CREATOR_VALUE_ENUM,
DEMO_STATUS_VALUE_ENUM,
} from '../mockData';
export type TableListItem = {
key: number;
name: string;
containers: number;
creator: string;
status: string;
createdAt: number;
memo: string;
};
const tableListDataSource = createTableDataSource({
count: 5,
}) as TableListItem[];
const columns: ProColumns<TableListItem>[] = [
{
title: '应用名称',
width: 120,
dataIndex: 'name',
render: (_) => <a>{_}</a>,
},
{
title: '容器数量',
dataIndex: 'containers',
align: 'right',
sorter: (a, b) => a.containers - b.containers,
},
{
title: '状态',
width: 80,
dataIndex: 'status',
initialValue: 'all',
valueEnum: DEMO_STATUS_VALUE_ENUM,
},
{
title: '负责人',
width: 80,
dataIndex: 'creator',
valueEnum: DEMO_CREATOR_VALUE_ENUM,
},
{
title: '操作',
width: 180,
key: 'option',
valueType: 'option',
render: () => [
<a key="detail">详情</a>,
<a key="log">日志</a>,
<a key="monitor">监控</a>,
<TableDropdown
key="actionGroup"
menus={[
{ key: 'restart', name: '重启' },
{ key: 'delete', name: '下线' },
]}
/>,
],
},
];
const Demo = () => {
return (
<ProTable<TableListItem>
dataSource={tableListDataSource}
rowKey="key"
pagination={{
showQuickJumper: true,
}}
columns={columns}
search={false}
dateFormatter="string"
headerTitle="微服务应用列表"
toolBarRender={() => [
<Button key="log">查看日志</Button>,
<Button key="export">
导出数据
<DownOutlined />
</Button>,
<Button type="primary" key="primary">
部署应用
</Button>,
]}
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
卡片边框:
基础表格
| 名称 | 状态 | 创建时间 | 进度 | 金额 | 操作 |
|---|---|---|---|---|---|
暂无数据 | |||||
卡片边框
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Button, Space, Switch } from 'antd';
import React, { useRef, useState } from 'react';
const valueEnum: Record<number, string> = {
0: 'close',
1: 'running',
2: 'online',
3: 'error',
};
export type TableListItem = {
key: number;
name: string;
status: string;
updatedAt: number;
createdAt: number;
progress: number;
money: number;
};
const tableListDataSource: TableListItem[] = [];
for (let i = 0; i < 5; i += 1) {
tableListDataSource.push({
key: i,
name: `TradeCode ${i}`,
status: valueEnum[Math.floor(Math.random() * 10) % 4],
updatedAt: Date.now() - Math.floor(Math.random() * 1000),
createdAt: Date.now() - Math.floor(Math.random() * 2000),
money: Math.floor(Math.random() * 2000) * i,
progress: Math.ceil(Math.random() * 100) + 1,
});
}
const columns: ProColumns<TableListItem>[] = [
{
title: '名称',
dataIndex: 'name',
render: (_) => <a>{_}</a>,
},
{
title: '状态',
dataIndex: 'status',
initialValue: 'all',
filters: true,
valueEnum: {
all: { text: '全部', status: 'Default' },
close: { text: '关闭', status: 'Default' },
running: { text: '运行中', status: 'Processing' },
online: { text: '已上线', status: 'Success' },
error: { text: '异常', status: 'Error' },
},
},
{
title: '创建时间',
dataIndex: 'createdAt',
valueType: 'date',
},
{
title: '进度',
dataIndex: 'progress',
valueType: 'progress',
},
{
title: '金额',
dataIndex: 'money',
valueType: 'money',
},
{
title: '操作',
key: 'option',
width: 120,
valueType: 'option',
render: () => [
<a key="link">链路</a>,
<a key="link2">报警</a>,
<a key="link3">监控</a>,
],
},
];
const Demo = () => {
const actionRef = useRef<ActionType>();
const [bordered, setBordered] = useState(false);
return (
<>
<Space style={{ marginBlockEnd: 16 }}>
<span>卡片边框:</span>
<Switch checked={bordered} onChange={setBordered} />
</Space>
<ProTable<TableListItem>
columns={columns}
actionRef={actionRef}
cardBordered={bordered}
request={async () => {
return {
data: tableListDataSource,
success: true,
};
}}
rowKey="key"
search={{
labelWidth: 'auto',
}}
pagination={{
pageSize: 5,
}}
dateFormatter="string"
headerTitle="基础表格"
toolBarRender={() => [
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
actionRef.current?.reload();
}}
type="primary"
>
新建
</Button>,
]}
/>
</>
);
};
export default Demo;
应用管理
| 排序 | 应用名称 | 负责人 | 状态 | 备注 | 操作 |
|---|---|---|---|---|---|
暂无数据 | |||||
使用 DataSource
import { EllipsisOutlined, SearchOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button, Dropdown, Input } from 'antd';
import {
createTableDataSource,
DEMO_CREATOR_VALUE_ENUM,
DEMO_STATUS_VALUE_ENUM,
} from '../mockData';
export type TableListItem = {
key: number;
name: string;
containers: number;
creator: string;
status: string;
createdAt: number;
progress: number;
money: number;
memo: string;
};
const tableListDataSource = createTableDataSource({
count: 5,
withProgress: true,
withMoney: true,
}) as TableListItem[];
const columns: ProColumns<TableListItem>[] = [
{
title: '排序',
dataIndex: 'index',
valueType: 'indexBorder',
width: 48,
},
{
title: '应用名称',
dataIndex: 'name',
render: (_) => <a>{_}</a>,
filterDropdown: () => (
<div style={{ padding: 8 }}>
<Input style={{ width: 188, marginBlockEnd: 8, display: 'block' }} />
</div>
),
filterIcon: (filtered) => (
<SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} />
),
},
{
title: '负责人',
dataIndex: 'creator',
valueEnum: DEMO_CREATOR_VALUE_ENUM,
},
{
title: '状态',
dataIndex: 'status',
initialValue: 'all',
filters: true,
onFilter: true,
valueEnum: DEMO_STATUS_VALUE_ENUM,
},
{
title: '备注',
dataIndex: 'memo',
ellipsis: true,
copyable: true,
},
{
title: '操作',
width: 180,
key: 'option',
valueType: 'option',
render: () => [
<a key="detail">详情</a>,
<a key="log">日志</a>,
<a key="monitor">监控</a>,
<TableDropdown
key="actionGroup"
menus={[
{ key: 'restart', name: '重启' },
{ key: 'delete', name: '下线' },
]}
/>,
],
},
];
const Demo = () => {
return (
<ProTable<TableListItem>
columns={columns}
request={(params, sorter, filter) => {
console.log(params, sorter, filter);
return Promise.resolve({
data: tableListDataSource,
total: tableListDataSource.length,
success: true,
});
}}
rowKey="key"
pagination={{
showQuickJumper: true,
}}
search={{
layout: 'vertical',
defaultCollapsed: false,
}}
dateFormatter="string"
toolbar={{
title: '应用管理',
tooltip: '管理所有已部署的微服务应用',
}}
toolBarRender={() => [
<Button key="danger" danger>
批量下线
</Button>,
<Button key="log">查看日志</Button>,
<Button type="primary" key="primary">
部署应用
</Button>,
<Dropdown
key="menu"
menu={{
items: [
{ label: '导入配置', key: 'import' },
{ label: '导出配置', key: 'export' },
{ label: '批量更新', key: 'batch' },
],
}}
>
<Button>
<EllipsisOutlined />
</Button>
</Dropdown>,
]}
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
| 成员名称 | 账号 | 角色 | 权限范围 | 操作 |
|---|---|---|---|---|
暂无数据 | ||||
无 ToolBar 的表格
import { DownOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Avatar, Dropdown, Popconfirm, Space } from 'antd';
import React from 'react';
export type Member = {
avatar: string;
realName: string;
nickName: string;
email: string;
outUserNo: string;
phone: string;
role: RoleType;
permission?: string[];
};
export type RoleMapType = Record<
string,
{
name: string;
desc: string;
}
>;
export type RoleType = 'admin' | 'operator';
const RoleMap: RoleMapType = {
admin: {
name: '管理员',
desc: '仅拥有指定项目的权限',
},
operator: {
name: '操作员',
desc: '拥有所有权限',
},
};
const tableListDataSource: Member[] = [];
const realNames = ['马巴巴', '测试', '测试2', '测试3'];
const nickNames = ['巴巴', '测试', '测试2', '测试3'];
const emails = [
'baba@antfin.com',
'test@antfin.com',
'test2@antfin.com',
'test3@antfin.com',
];
const phones = ['12345678910', '10923456789', '109654446789', '109223346789'];
const permissions = [[], ['权限点名称1', '权限点名称4'], ['权限点名称1'], []];
for (let i = 0; i < 5; i += 1) {
tableListDataSource.push({
outUserNo: `${102047 + i}`,
avatar:
'https://gw.alipayobjects.com/zos/antfincdn/upvrAjAPQX/Logo_Tech%252520UI.svg',
role: i === 0 ? 'admin' : 'operator',
realName: realNames[i % 4],
nickName: nickNames[i % 4],
email: emails[i % 4],
phone: phones[i % 4],
permission: permissions[i % 4],
});
}
const MemberList: React.FC = () => {
const renderRemoveUser = (text: string) => (
<Popconfirm
key="popconfirm"
title={`确认${text}吗?`}
okText="是"
cancelText="否"
>
<a>{text}</a>
</Popconfirm>
);
const columns: ProColumns<Member>[] = [
{
dataIndex: 'avatar',
title: '成员名称',
valueType: 'avatar',
width: 150,
render: (dom, record) => (
<Space>
<span>{dom}</span>
{record.nickName}
</Space>
),
},
{
dataIndex: 'email',
title: '账号',
ellipsis: true,
copyable: true,
renderText: (_dom, row) => {
return (
<React.Fragment>
<Avatar src={row.avatar} />
{row.nickName}
</React.Fragment>
);
},
},
{
dataIndex: 'role',
title: '角色',
render: (_, record) => (
<Dropdown
menu={{
items: [
{
label: '管理员',
key: 'admin',
},
{
label: '操作员',
key: 'operator',
},
],
}}
>
<a>
{RoleMap[record.role || 'admin'].name} <DownOutlined />
</a>
</Dropdown>
),
},
{
dataIndex: 'permission',
title: '权限范围',
render: (_, record) => {
const { role, permission = [] } = record;
if (role === 'admin') {
return '所有权限';
}
return permission && permission.length > 0
? permission.join('、')
: '无';
},
},
{
title: '操作',
dataIndex: 'x',
valueType: 'option',
render: (_, record) => {
let node = renderRemoveUser('退出');
if (record.role === 'admin') {
node = renderRemoveUser('移除');
}
return [<a key="edit">编辑</a>, node];
},
},
];
return (
<ProTable<Member>
columns={columns}
request={(_params, _sorter, _filter) => {
// 表单搜索项会从 params 传入,传递给后端接口。
return Promise.resolve({
data: tableListDataSource,
total: tableListDataSource.length,
success: true,
});
}}
rowKey="outUserNo"
pagination={{
showQuickJumper: true,
}}
toolBarRender={false}
search={false}
/>
);
<div
style={{
marginTop: '20px',
padding: '20px',
backgroundColor: '#f5f5f5',
borderRadius: '6px',
}}
>
<h4>ProTable 无标题 Props 说明:</h4>
<ul>
<li>
<strong>ProTable</strong>: 专业表格组件
</li>
<li>
<strong>Dropdown</strong>: 下拉菜单组件
</li>
<li>
<strong>Popconfirm</strong>: 气泡确认框组件
</li>
<li>
<strong>Space</strong>: 间距组件
</li>
<li>
<strong>无标题</strong>: 展示无标题功能
</li>
</ul>
<h4>ProTable 配置:</h4>
<ul>
<li>
<strong>columns</strong>: 列配置
</li>
<li>
<strong>request</strong>: 请求函数
</li>
<li>
<strong>rowKey</strong>: 行键
</li>
<li>
<strong>pagination</strong>: 分页配置
</li>
<li>
<strong>toolBarRender</strong>: 工具栏渲染
</li>
<li>
<strong>search</strong>: 搜索配置
</li>
</ul>
<h4>无标题特点:</h4>
<ul>
<li>
<strong>头像显示</strong>: 支持头像显示
</li>
<li>
<strong>角色管理</strong>: 支持角色管理
</li>
<li>
<strong>权限控制</strong>: 支持权限控制
</li>
<li>
<strong>下拉菜单</strong>: 支持下拉菜单
</li>
<li>
<strong>确认操作</strong>: 支持确认操作
</li>
<li>
<strong>简洁布局</strong>: 支持简洁布局
</li>
</ul>
<h4>使用场景:</h4>
<ul>
<li>
<strong>成员管理</strong>: 成员管理系统
</li>
<li>
<strong>权限管理</strong>: 权限管理功能
</li>
<li>
<strong>用户列表</strong>: 用户列表展示
</li>
</ul>
</div>;
};
export default () => (
<div style={{ padding: 24 }}>
<MemberList />
</div>
);
#搜索栏类型切换
通过 Segmented 切换 search.filterType,在查询表单(query)和轻量筛选(light)之间一键切换。
search.filterType 搜索栏类型:
搜索栏类型切换
| 应用名称 | 负责人 | 状态 |
|---|---|---|
暂无数据 | ||
搜索栏类型切换
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Segmented } from 'antd';
import { useState } from 'react';
import {
createTableDataSource,
DEMO_CREATOR_VALUE_ENUM,
DEMO_STATUS_VALUE_ENUM,
FIXED_BASE_DATE,
} from '../mockData';
type TableListItem = {
key: number;
name: string;
creator: string;
status: string;
createdAt: number;
};
const tableListDataSource = createTableDataSource({
count: 5,
}) as TableListItem[];
const columns: ProColumns<TableListItem>[] = [
{
title: '应用名称',
dataIndex: 'name',
render: (_) => <a>{_}</a>,
},
{
title: '负责人',
dataIndex: 'creator',
valueType: 'select',
valueEnum: DEMO_CREATOR_VALUE_ENUM,
},
{
title: '状态',
dataIndex: 'status',
valueEnum: DEMO_STATUS_VALUE_ENUM,
},
{
title: '日期范围',
dataIndex: 'startTime',
valueType: 'dateRange',
hideInTable: true,
initialValue: [FIXED_BASE_DATE, FIXED_BASE_DATE.add(7, 'day')],
},
];
const Demo = () => {
const [filterType, setFilterType] = useState<'query' | 'light'>('query');
return (
<div>
<div style={{ marginBlockEnd: 16 }}>
<span>search.filterType 搜索栏类型:</span>
<Segmented
value={filterType}
onChange={(v) => setFilterType(v as any)}
options={[
{ label: '查询表单 query', value: 'query' },
{ label: '轻量筛选 light', value: 'light' },
]}
/>
</div>
<ProTable<TableListItem>
columns={columns}
request={() =>
Promise.resolve({
data: tableListDataSource,
total: tableListDataSource.length,
success: true,
})
}
rowKey="key"
search={{ filterType }}
dateFormatter="string"
headerTitle="搜索栏类型切换"
/>
</div>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
#搜索与筛选
应用列表(无操作按钮)
| 应用名称 | 容器数量 | 状态 | 部署时间 |
|---|---|---|---|
暂无数据 | |||
查询(无按钮)表格
import { DownOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Button } from 'antd';
import { createTableDataSource, DEMO_STATUS_VALUE_ENUM } from '../mockData';
export type TableListItem = {
key: number;
name: string;
containers: number;
creator: string;
status: string;
createdAt: number;
memo: string;
};
const tableListDataSource = createTableDataSource({
count: 5,
}) as TableListItem[];
const columns: ProColumns<TableListItem>[] = [
{
title: '应用名称',
width: 120,
dataIndex: 'name',
render: (_) => <a>{_}</a>,
},
{
title: '容器数量',
dataIndex: 'containers',
align: 'right',
sorter: (a, b) => a.containers - b.containers,
},
{
title: '状态',
width: 80,
dataIndex: 'status',
initialValue: 'all',
valueEnum: DEMO_STATUS_VALUE_ENUM,
},
{
title: '部署时间',
tooltip: '最近一次部署的时间',
width: 140,
key: 'since',
search: false,
dataIndex: 'createdAt',
valueType: 'date',
sorter: (a, b) => a.createdAt - b.createdAt,
},
];
const Demo = () => {
return (
<ProTable<TableListItem>
columns={columns}
request={(params, sorter, filter) => {
console.log(params, sorter, filter);
return Promise.resolve({
data: tableListDataSource,
total: tableListDataSource.length,
success: true,
});
}}
rowKey="key"
pagination={{
showQuickJumper: true,
}}
search={{
optionRender: false,
collapsed: false,
}}
dateFormatter="string"
headerTitle="应用列表(无操作按钮)"
toolBarRender={() => [
<Button key="log">查看日志</Button>,
<Button key="export">
导出数据
<DownOutlined />
</Button>,
<Button type="primary" key="primary">
部署应用
</Button>,
]}
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
轻量筛选
| 应用名称 | 负责人 |
|---|---|
暂无数据 | |
轻量筛选替换查询表单
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import {
createTableDataSource,
DEMO_CREATOR_VALUE_ENUM,
FIXED_BASE_DATE,
} from '../mockData';
export type TableListItem = {
key: number;
name: string;
creator: string;
createdAt: number;
};
const tableListDataSource = createTableDataSource({
count: 1,
}) as TableListItem[];
const columns: ProColumns<TableListItem>[] = [
{
title: '应用名称',
dataIndex: 'name',
render: (_) => <a>{_}</a>,
formItemProps: {},
},
{
title: '日期范围',
dataIndex: 'startTime',
valueType: 'dateRange',
hideInTable: true,
initialValue: [FIXED_BASE_DATE, FIXED_BASE_DATE.add(1, 'day')],
},
{
title: '负责人',
dataIndex: 'creator',
valueType: 'select',
valueEnum: DEMO_CREATOR_VALUE_ENUM,
},
];
const Demo = () => {
return (
<ProTable<TableListItem>
columns={columns}
request={(params, sorter, filter) => {
console.log(params, sorter, filter);
return Promise.resolve({
data: tableListDataSource,
total: tableListDataSource.length,
success: true,
});
}}
headerTitle="轻量筛选"
rowKey="key"
pagination={{
showQuickJumper: true,
}}
options={false}
search={{
filterType: 'light',
}}
dateFormatter="string"
/>
);
};
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
快速搜索服务
| 序号 | 服务名称 |
|---|---|
暂无数据 | |
使用自带 keyWords 搜索的 table
import { ProTable } from '@ant-design/pro-components';
type ServiceItem = {
key: number;
name: string;
createdAt: number;
};
const SearchTable = () => (
<ProTable<ServiceItem>
columns={[
{
title: '序号',
dataIndex: 'index',
valueType: 'indexBorder',
},
{
title: '服务名称',
dataIndex: 'name',
search: false,
},
]}
request={async (_params) => {
return {
data: [
{
key: 1,
name: '用户认证服务',
createdAt: 1705286400000,
},
{
key: 2,
name: '订单处理中心',
createdAt: 1705200000000,
},
{
key: 3,
name: '支付网关',
createdAt: 1705113600000,
},
],
total: 3,
success: true,
};
}}
search={false}
rowKey="key"
options={{
search: true,
}}
headerTitle="快速搜索服务"
/>
);
export default () => (
<div style={{ padding: 24 }}>
<SearchTable />
</div>
);
搜索选项自定义
| 序号 | 服务名称 | 合同金额 |
|---|---|---|
暂无数据 | ||
搜索选项自定义
import { PlusOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Button } from 'antd';
type ServiceItem = {
key: number;
name: string;
createdAt: number;
};
const columns: ProColumns<ServiceItem>[] = [
{
title: '序号',
dataIndex: 'index',
valueType: 'indexBorder',
},
{
title: '服务名称',
dataIndex: 'name',
},
{
title: '合同金额',
dataIndex: 'title',
width: 100,
valueType: 'money',
renderText: () => '128000',
},
];
const Demo = () => (
<ProTable<ServiceItem>
columns={columns}
request={async () => {
return {
data: [
{
key: 1,
name: '企业版云服务套餐',
createdAt: 1705286400000,
},
],
total: 1,
success: true,
};
}}
rowKey="key"
dateFormatter="string"
headerTitle="搜索选项自定义"
search={{
defaultCollapsed: false,
labelWidth: 'auto',
optionRender: (searchConfig, formProps, dom) => [
...dom.reverse(),
<Button key="export" onClick={() => {}}>
导出
</Button>,
],
}}
toolBarRender={() => [
<Button key="primary" type="primary">
<PlusOutlined />
新建
</Button>,
]}
/>
);
export default () => (
<div style={{ padding: 24 }}>
<Demo />
</div>
);
高级表格
标题 | 状态 | 标 签 | 创建时间 |
|---|---|---|---|
暂无数据 | |||