HTML:字體
<a-table ref="table" size="small" rowKey="id" bordered :columns="physicalSurveyColumns" :data-source="physicalSurveyData" :pagination="pagination" :customRow="customRow" > </a-table>
JS -> methods:this
// 自定義行 customRow(record) { return { on: { click: (e) => { const oldList = document.querySelectorAll('.checked-td-of-add-table') if (oldList) { for (let j = 0; j < oldList.length; j++) { oldList[j].classList.remove('checked-td-of-add-table') } } const children = e.target.parentNode.children for (let i = 0; i < children.length; i++) { children[i].classList.add('checked-td-of-add-table') } } } } }
CSS:spa
/deep/ .checked-td-of-add-table { background-color: rgba(24, 144, 255, 0.5); }
HTML:code
<a-table ref="table" size="small" rowKey="id" bordered :columns="physicalSurveyColumns" :data-source="physicalSurveyData" :pagination="pagination" :customRow="customRow" > </a-table>
JS -> methods:blog
// 自定義行 customRow(record, index) { return { // 自定義屬性,也就是官方文檔中的props,可經過條件來控制樣式 style: { // 字體顏色 'color': record.id === this.physicalSurveyCurrRowId ? 'orange' : 'rgba(0, 0, 0, 0.65)', // 行背景色 'background-color': record.id === this.physicalSurveyCurrRowId ? '#FFFF99' : 'white' // // 字體類型 // 'font-family': 'Microsoft YaHei', // // 下劃線 // 'text-decoration': 'underline', // // 字體樣式-斜體 // 'font-style': 'italic', // // 字體樣式-斜體 // 'font-weight': 'bolder' }, on: { // 鼠標單擊行 click: event => { // 記錄當前點擊的行標識 this.physicalSurveyCurrRowId = record.id } } } }
HTML:rem
<a-table ref="table" size="small" rowKey="id" bordered :columns="physicalSurveyColumns" :data-source="physicalSurveyData" :pagination="pagination" :customRow="customRow" > </a-table>
JS -> methods:文檔
// 自定義行 customRow(record, index) { return { on: { // 鼠標單擊行 click: event => { event.currentTarget.parentNode.querySelectorAll('tr').forEach(item => { item.style.background = 'white' }) event.currentTarget.style.background = 'green' } } } }
HTML:get
<a-table ref="table" size="small" rowKey="id" bordered :columns="physicalSurveyColumns" :data-source="physicalSurveyData" :pagination="pagination" :customRow="customRow" :rowClassName="setRowClassName" > </a-table>
JS -> methods:it
// 選中行 customRow(record, index) { return { on: { click: () => { this.physicalSurveyCurrRowId = record.id } } } }, setRowClassName(record) { return record.id === this.physicalSurveyCurrRowId ? 'clickRowStyl' : '' }
CSS:設置自定義行的懸浮樣式io
.ant-table-tbody { .clickRowStyl:hover { td { background-color: #00b4ed; } } }
都能達到目的,按須要選擇。