-
Notifications
You must be signed in to change notification settings - Fork 284
feat(table): table新增自定义行 #2390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(table): table新增自定义行 #2390
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useState } from 'react' | ||
import { Table, TableColumnProps } from '@nutui/nutui-react' | ||
|
||
const Demo14 = () => { | ||
const [columns] = useState<Array<TableColumnProps>>([ | ||
{ | ||
title: '姓名', | ||
key: 'name', | ||
align: 'center', | ||
}, | ||
{ | ||
title: '性别', | ||
key: 'gender', | ||
}, | ||
{ | ||
title: '学历', | ||
key: 'record', | ||
}, | ||
]) | ||
|
||
const [data] = useState([ | ||
{ | ||
name: 'Tom', | ||
gender: '男', | ||
record: '小学', | ||
}, | ||
{ | ||
height: '50px', | ||
text: '这里是自定义行', | ||
Component: (props: any) => { | ||
return ( | ||
<div style={{ height: props.height }}> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
height: props.height, | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
borderBottom: | ||
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))', | ||
}} | ||
> | ||
{props.text} | ||
</div> | ||
</div> | ||
) | ||
}, | ||
rowRender: (item: any) => { | ||
const { Component, ...rest } = item | ||
return <Component {...rest} /> | ||
}, | ||
}, | ||
{ | ||
name: 'Lucy', | ||
gender: '女', | ||
record: '本科', | ||
}, | ||
{ | ||
name: 'Jack', | ||
gender: '男', | ||
record: '高中', | ||
}, | ||
]) | ||
|
||
return <Table columns={columns} data={data} /> | ||
} | ||
export default Demo14 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useState } from 'react' | ||
import { Table, TableColumnProps } from '@nutui/nutui-react-taro' | ||
|
||
const Demo14 = () => { | ||
const [columns] = useState<Array<TableColumnProps>>([ | ||
{ | ||
title: '姓名', | ||
key: 'name', | ||
align: 'center', | ||
}, | ||
{ | ||
title: '性别', | ||
key: 'gender', | ||
}, | ||
{ | ||
title: '学历', | ||
key: 'record', | ||
}, | ||
]) | ||
|
||
const [data] = useState([ | ||
{ | ||
name: 'Tom', | ||
gender: '男', | ||
record: '小学', | ||
}, | ||
{ | ||
height: '50px', | ||
text: '这里是自定义行', | ||
Component: (props: any) => { | ||
return ( | ||
<div style={{ height: props.height }}> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
height: props.height, | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
borderBottom: | ||
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))', | ||
}} | ||
> | ||
{props.text} | ||
</div> | ||
</div> | ||
) | ||
}, | ||
rowRender: (item: any) => { | ||
const { Component, ...rest } = item | ||
return <Component {...rest} /> | ||
}, | ||
}, | ||
{ | ||
name: 'Lucy', | ||
gender: '女', | ||
record: '本科', | ||
}, | ||
{ | ||
name: 'Jack', | ||
gender: '男', | ||
record: '高中', | ||
}, | ||
]) | ||
|
||
return <Table columns={columns} data={data} /> | ||
} | ||
export default Demo14 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Table } from './table.taro' | ||
|
||
export type { TableProps } from './table.taro' | ||
export type { TableColumnProps } from './types' | ||
export default Table |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Table } from './table' | ||
|
||
export type { TableProps } from './table' | ||
export type { TableColumnProps } from './types' | ||
export default Table |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,10 @@ export const Table: FunctionComponent< | |
} | ||
|
||
const renderBodyTds = (item: any, rowIndex: number) => { | ||
const { rowRender } = item | ||
if (rowRender && typeof rowRender === 'function') { | ||
return rowRender(item, rowIndex) | ||
} | ||
Comment on lines
+125
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification 需要增加键盘访问性支持。 在文件
Analysis chain自定义行渲染逻辑正确。 但需要增加键盘访问性支持。 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the onClick event in the table has corresponding keyboard event handlers.
# Test: Search for onClick events in the file. Expect: Corresponding onKeyUp, onKeyDown, or onKeyPress events.
rg --type typescript $'onClick' src/packages/table/table.tsx
Length of output: 94 Script: #!/bin/bash
# Description: Verify the onClick event in the table has corresponding keyboard event handlers.
# Test: Search for onClick events in the file. Expect: Corresponding onKeyUp, onKeyDown, or onKeyPress events.
rg 'onClick' src/packages/table/table.tsx
Length of output: 91 Script: #!/bin/bash
# Description: Verify the presence of keyboard event handlers corresponding to the onClick event in the table component.
# Test: Search for onKeyUp, onKeyDown, or onKeyPress events in the file.
rg 'on(KeyUp|KeyDown|KeyPress)' src/packages/table/table.tsx
Length of output: 62 |
||
return sortDataItem().map(([value, render]) => { | ||
return ( | ||
<div | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
优化列定义
columns
数组是常量,不需要使用useState
来定义。可以直接定义为常量数组以减少不必要的状态管理复杂性。Committable suggestion