Skip to content

Commit

Permalink
docs: 完善文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Barrior committed Jul 9, 2024
1 parent a206247 commit f178a48
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
54 changes: 54 additions & 0 deletions examples/search-table-react/050-tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,60 @@ const Demo = () => {
export default Demo
```

## 分类不同列数据

```tsx
import { useState } from 'react'
import { sleep } from '@examples/utils'
import schema from './helpers/schema'
import columns from './helpers/columns'
import columnsVT from './helpers/columns-value-type'
import createDataSource from './helpers/createDataSource'
import createDataSourceVT from './helpers/createDataSource-vt'
import SearchTable from '@schema-render/search-table-react'

const items = [
{ key: '1', label: '分类一' },
{ key: '2', label: '分类二' },
]

const Demo = () => {
const [activeKey, setActiveKey] = useState('1')

return (
<SearchTable
search={{ schema }}
title={{
showSetting: true,
tabs: {
activeKey,
items,
onChange: setActiveKey,
},
}}
table={{
columns: activeKey === '1' ? columns : columnsVT,
showRowNumber: true,
actionItems: () => [{ text: '编辑' }, { text: '详情' }],
}}
request={async (searchParams) => {
// 模拟请求接口获取表格数据
await sleep()
const fetchData = activeKey === '1' ? createDataSource : createDataSourceVT
const data = fetchData(searchParams.pageSize)

// 主动抛错,验证异常场景
if (Math.random() > 0.7) throw new Error('抛出一个错误')

return { data, total: 100 }
}}
/>
)
}

export default Demo
```

## 开启列设置

设置 `showSetting` 属性为 `true` 可以开启列设置功能。
Expand Down
7 changes: 1 addition & 6 deletions examples/search-table-react/100-columns-setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const items = [

const Demo = () => {
const [activeKey, setActiveKey] = useState('1')
const [cols, setCols] = useState(columns)

return (
<SearchTable
Expand All @@ -123,7 +122,7 @@ const Demo = () => {
},
}}
table={{
columns: cols,
columns: activeKey === '1' ? columns : columnsVT,
showRowNumber: true,
actionItems: () => [{ text: '编辑' }, { text: '详情' }],
}}
Expand All @@ -132,10 +131,6 @@ const Demo = () => {
await sleep()
const fetchData = activeKey === '1' ? createDataSource : createDataSourceVT
const data = fetchData(searchParams.pageSize)

// 接口请求完毕再更新 columns 数据
setCols(activeKey === '1' ? columns : columnsVT)

return { data, total: 100 }
}}
/>
Expand Down

0 comments on commit f178a48

Please sign in to comment.