Skip to content

Instantly share code, notes, and snippets.

@ZhaoRd
Created October 12, 2018 09:35
Show Gist options
  • Select an option

  • Save ZhaoRd/8c1f975773739323fad75e3a641065a7 to your computer and use it in GitHub Desktop.

Select an option

Save ZhaoRd/8c1f975773739323fad75e3a641065a7 to your computer and use it in GitHub Desktop.
antd for vue tsx render table
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,
}];
<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