Created
October 12, 2018 09:35
-
-
Save ZhaoRd/8c1f975773739323fad75e3a641065a7 to your computer and use it in GitHub Desktop.
antd for vue tsx render table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private renderContent(value:any, record: any, index: number) { | |
| const obj = { | |
| children: value, | |
| attrs: {}, | |
| }; | |
| if (index === 4) { | |
| obj.attrs.colSpan = 0; | |
| } | |
| return obj; | |
| }; | |
| public nameRender(text: string, record: any, index: number){ | |
| if (index < 4) { | |
| return <a href="javascript:;">{text}</a>; | |
| } | |
| return { | |
| children: <a href="javascript:;">{text}</a>, | |
| attrs: { | |
| colSpan: 5, | |
| }, | |
| }; | |
| } | |
| private telRender(value: string, row: any, index: number) { | |
| const obj = { | |
| children: value, | |
| attrs: {}, | |
| }; | |
| if (index === 2) { | |
| obj.attrs.rowSpan = 2; | |
| } | |
| // These two are merged into above cell | |
| if (index === 3) { | |
| obj.attrs.rowSpan = 0; | |
| } | |
| if (index === 4) { | |
| obj.attrs.colSpan = 0; | |
| } | |
| return obj; | |
| } | |
| public columns: any[] = [{ | |
| title: 'Name', | |
| dataIndex: 'name', | |
| customRender:this.nameRender, | |
| }, { | |
| title: 'Age', | |
| dataIndex: 'age', | |
| customRender: this.renderContent, | |
| }, { | |
| title: 'Home phone', | |
| colSpan: 2, | |
| dataIndex: 'tel', | |
| customRender: this.telRender, | |
| }, { | |
| title: 'Phone', | |
| colSpan: 0, | |
| dataIndex: 'phone', | |
| customRender: this.renderContent, | |
| }, { | |
| title: 'Address', | |
| dataIndex: 'address', | |
| customRender: this.renderContent, | |
| }]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a-table :columns="columns" :dataSource="data" bordered> | |
| </a-table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment