Table data support to set cell className

Table data support to set cell className
This commit is contained in:
梁灏 2017-01-10 18:36:13 +08:00
parent f9f1865ca5
commit c211f71778
3 changed files with 39 additions and 10 deletions

View file

@ -1,9 +1,14 @@
export default {
methods: {
alignCls (column, type) {
alignCls (column, type, row = {}) {
let cellClassName = '';
if (row.cellClassName && column.key && row.cellClassName[column.key]) {
cellClassName = row.cellClassName[column.key];
}
return [
{
[`${column.className}`]: column.className && type === 'body',
[`${cellClassName}`]: cellClassName, // cell className
[`${column.className}`]: column.className && type === 'body', // column className
[`${this.prefixCls}-column-${column.align}`]: column.align,
[`${this.prefixCls}-hidden`]: (this.fixed === 'left' && column.fixed !== 'left') || (this.fixed === 'right' && column.fixed !== 'right') || (!this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right'))
}

View file

@ -11,7 +11,7 @@
@mouseleave.stop="handleMouseOut(row._index)"
@click.stop="clickCurrentRow(row._index)"
@dblclick.stop="dblclickCurrentRow(row._index)">
<td v-for="column in columns" :class="alignCls(column, 'body')">
<td v-for="column in columns" :class="alignCls(column, 'body', row)">
<Cell
:fixed="fixed"
:prefix-cls="prefixCls"

View file

@ -16,6 +16,18 @@
.ivu-table .table-address-col{
background: #187;
}
.ivu-table .class-cell-age{
background: #187;
color: #fff;
}
.ivu-table .class-cell-address{
background: #f60;
color: #fff;
}
.ivu-table .class-cell-name{
background: #2db7f5;
color: #fff;
}
</style>
<template>
<i-table :row-class-name="rowClassName" :columns="columns1" :data="data1"></i-table>
@ -25,29 +37,38 @@
data () {
return {
columns1: [
{
type: 'selection',
width: 60,
align: 'center'
},
{
title: '姓名',
key: 'name',
fixed: 'right',
className: 'table-name-col'
// fixed: 'right',
// className: 'table-name-col'
},
{
title: '年龄',
key: 'age',
fixed: 'right',
className: 'table-age-col'
// fixed: 'right',
// className: 'table-age-col'
},
{
title: '地址',
key: 'address',
className: 'table-address-col'
// className: 'table-address-col'
}
],
data1: [
{
name: '王小明',
age: 18,
address: '北京市朝阳区芍药居'
address: '北京市朝阳区芍药居',
cellClassName: {
age: 'class-cell-age',
address: 'class-cell-address'
}
},
{
name: '张小刚',
@ -57,7 +78,10 @@
{
name: '李小红',
age: 30,
address: '上海市浦东新区世纪大道'
address: '上海市浦东新区世纪大道',
cellClassName: {
name: 'class-cell-name'
}
},
{
name: '周小伟',