-
-
Notifications
You must be signed in to change notification settings - Fork 612
add: The table stripe display can be set. #1290
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
base: master
Are you sure you want to change the base?
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,8 @@ | ||
--- | ||
title: stripe | ||
nav: | ||
title: Demo | ||
path: /demo | ||
--- | ||
|
||
<code src="../examples/stripe.tsx"></code> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import type { TableProps } from 'rc-table'; | ||
import Table from 'rc-table'; | ||
import '../../assets/index.less'; | ||
|
||
interface FieldType { | ||
name?: string; | ||
age?: string; | ||
address?: string; | ||
} | ||
|
||
const columns: TableProps<FieldType>['columns'] = [ | ||
{ | ||
title: 'Name', | ||
dataIndex: 'name', | ||
key: 'name', | ||
}, | ||
{ | ||
title: 'Age', | ||
dataIndex: 'age', | ||
key: 'age', | ||
}, | ||
{ | ||
title: 'Address', | ||
dataIndex: 'address', | ||
key: 'address', | ||
}, | ||
]; | ||
|
||
const data = [ | ||
{ name: 'John', age: '25', address: '1 A Street' }, | ||
{ name: 'Fred', age: '38', address: '2 B Street' }, | ||
{ name: 'Anne', age: '47', address: '3 C Street' }, | ||
{ name: 'Ben', age: '14', address: '4 C Street' }, | ||
{ name: 'Hali', age: '34', address: '5 C Street' }, | ||
{ name: 'Hama', age: '25', address: '6 C Street' }, | ||
]; | ||
|
||
const Demo = () => ( | ||
<div> | ||
<h2>Table with stripe</h2> | ||
<Table columns={columns} data={data} stripe /> | ||
</div> | ||
); | ||
|
||
export default Demo; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,14 +14,15 @@ | |||||
export interface BodyProps<RecordType> { | ||||||
data: readonly RecordType[]; | ||||||
measureColumnWidth: boolean; | ||||||
stripe: boolean; | ||||||
} | ||||||
|
||||||
function Body<RecordType>(props: BodyProps<RecordType>) { | ||||||
if (process.env.NODE_ENV !== 'production') { | ||||||
devRenderTimes(props); | ||||||
} | ||||||
|
||||||
const { data, measureColumnWidth } = props; | ||||||
const { data, measureColumnWidth, stripe } = props; | ||||||
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. 🛠️ Refactor suggestion 添加默认值处理 应该为 - const { data, measureColumnWidth, stripe } = props;
+ const { data, measureColumnWidth, stripe = false } = props; 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||
|
||||||
const { | ||||||
prefixCls, | ||||||
|
@@ -96,10 +97,14 @@ | |||||
if (data.length) { | ||||||
rows = flattenData.map((item, idx) => { | ||||||
const { record, indent, index: renderIndex, rowKey } = item; | ||||||
|
||||||
let className = ''; | ||||||
if (stripe && idx % 2 === 1) { | ||||||
className = `${prefixCls}-row-striped`; | ||||||
} | ||||||
return ( | ||||||
<BodyRow | ||||||
classNames={bodyCls} | ||||||
className={className} | ||||||
styles={bodyStyles} | ||||||
key={rowKey} | ||||||
rowKey={rowKey} | ||||||
|
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.
修复类型定义不一致问题
BodyProps
中的stripe
属性应该标记为可选,以与TableProps
中的定义保持一致。📝 Committable suggestion
🤖 Prompt for AI Agents