拓展使用 customRow
https://blog.csdn.net/EasonGG/article/details/105687765
https://blog.csdn.net/u012215273/article/details/107907460
https://segmentfault.com/q/1010000021780046
通用方式:
{ title: '17:30', width: '4%', scopedSlots: { customRender: 'tdSlot173' }, customCell:this.renderTdBackground173 },
renderTdBackground173(record){ return this.renderTdBackground('17:30',record) }, //渲染有數據的單元格的顏色 renderTdBackground (time,record) { let bookedList = record.bookedList if(null==bookedList||undefined==bookedList){ return } let currentDate ...return { style: { // 行背景色
'background-color': '#8fd0fa',
'cursor': 'pointer', }, on: { // 鼠標單擊行 click: event => { console.log(123); this.meetingroomBook() }, }, }; } }
我發現 customCell 函數的第二個參數rowIndex恆為0,
另外 每一項的函數如果寫在method里則無法判斷當前列,於是項目中采用了如下寫法
<a-table :columns="renderColumns(columns)" :data-source="tableData" > </a-table>
methods: { renderColumns(columns) { const _this = this return columns.map(item => { return { ...item, customCell(record, index) { return { click: (event) => {}, dblclick: (event) => {}, contextmenu: (event) => {}, mouseenter: (event) => {}, mouseleave: (event) => {},
style: {
// 單元格背景色
'background-color': '#f9999a'
}
}
}
}
})
}
}