Commit 891700ae0c462ee88f8dc8d48092837bac08c2d5
1 parent
012cbf28
update Table
update Table
Showing
4 changed files
with
89 additions
and
49 deletions
Show diff stats
src/components/table/mixin.js
| 1 | 1 | export default { |
| 2 | 2 | methods: { |
| 3 | - alignCls (column, type, row = {}) { | |
| 3 | + alignCls (column, row = {}) { | |
| 4 | 4 | let cellClassName = ''; |
| 5 | 5 | if (row.cellClassName && column.key && row.cellClassName[column.key]) { |
| 6 | 6 | cellClassName = row.cellClassName[column.key]; |
| ... | ... | @@ -8,7 +8,7 @@ export default { |
| 8 | 8 | return [ |
| 9 | 9 | { |
| 10 | 10 | [`${cellClassName}`]: cellClassName, // cell className |
| 11 | - [`${column.className}`]: column.className && type === 'body', // column className | |
| 11 | + [`${column.className}`]: column.className, // column className | |
| 12 | 12 | [`${this.prefixCls}-column-${column.align}`]: column.align, |
| 13 | 13 | [`${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')) |
| 14 | 14 | } | ... | ... |
src/components/table/table-body.vue
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | @mouseleave.stop="handleMouseOut(row._index)" |
| 12 | 12 | @click.stop="clickCurrentRow(row._index)" |
| 13 | 13 | @dblclick.stop="dblclickCurrentRow(row._index)"> |
| 14 | - <td v-for="column in columns" :class="alignCls(column, 'body', row)"> | |
| 14 | + <td v-for="column in columns" :class="alignCls(column, row)"> | |
| 15 | 15 | <Cell |
| 16 | 16 | :fixed="fixed" |
| 17 | 17 | :prefix-cls="prefixCls" | ... | ... |
src/components/table/table-head.vue
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | </colgroup> |
| 6 | 6 | <thead> |
| 7 | 7 | <tr> |
| 8 | - <th v-for="(index, column) in columns" :class="alignCls(column, 'head')"> | |
| 8 | + <th v-for="(index, column) in columns" :class="alignCls(column)"> | |
| 9 | 9 | <div :class="cellClasses(column)"> |
| 10 | 10 | <template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template> |
| 11 | 11 | <template v-else> | ... | ... |
test/routers/table.vue
| 1 | +<style> | |
| 2 | + .ivu-table .demo-table-info-row td{ | |
| 3 | + background-color: #2db7f5; | |
| 4 | + color: #fff; | |
| 5 | + } | |
| 6 | + .ivu-table .demo-table-error-row td{ | |
| 7 | + background-color: #ff6600; | |
| 8 | + color: #fff; | |
| 9 | + } | |
| 10 | + .ivu-table td.demo-table-info-column{ | |
| 11 | + background-color: #2db7f5; | |
| 12 | + color: #fff; | |
| 13 | + } | |
| 14 | + .ivu-table .demo-table-info-cell-name { | |
| 15 | + background-color: #2db7f5; | |
| 16 | + color: #fff; | |
| 17 | + } | |
| 18 | + .ivu-table .demo-table-info-cell-age { | |
| 19 | + background-color: #ff6600; | |
| 20 | + color: #fff; | |
| 21 | + } | |
| 22 | + .ivu-table .demo-table-info-cell-address { | |
| 23 | + background-color: #187; | |
| 24 | + color: #fff; | |
| 25 | + } | |
| 26 | +</style> | |
| 1 | 27 | <template> |
| 2 | - <i-table border :content="self" :columns="columns7" :data="data6"></i-table> | |
| 28 | + <p>自定义行样式:</p> | |
| 29 | + <!--<i-table :row-class-name="rowClassName" :columns="columns1" :data="data1"></i-table>--> | |
| 30 | + <p>自定义列样式:</p> | |
| 31 | + <i-table :columns="columns9" :data="data1"></i-table> | |
| 32 | + <p>自定义任意单元格样式:</p> | |
| 33 | + <!--<i-table :columns="columns1" :data="data8"></i-table>--> | |
| 3 | 34 | </template> |
| 4 | 35 | <script> |
| 5 | 36 | export default { |
| 6 | 37 | data () { |
| 7 | 38 | return { |
| 8 | - self: this, | |
| 9 | - columns7: [ | |
| 39 | + columns1: [ | |
| 10 | 40 | { |
| 11 | 41 | title: '姓名', |
| 12 | - key: 'name', | |
| 13 | - render (row, column, index) { | |
| 14 | - return `<Icon type="person"></Icon> <strong>${row.name}</strong>`; | |
| 15 | - } | |
| 42 | + key: 'name' | |
| 16 | 43 | }, |
| 17 | 44 | { |
| 18 | 45 | title: '年龄', |
| ... | ... | @@ -20,40 +47,25 @@ |
| 20 | 47 | }, |
| 21 | 48 | { |
| 22 | 49 | title: '地址', |
| 23 | - key: 'address', | |
| 24 | - render () { | |
| 25 | - return ` | |
| 26 | -<Poptip title="提示标题" content="提示内容" placement="bottom-end"> | |
| 27 | - <i-button>click 激活</i-button> | |
| 28 | - </Poptip> | |
| 29 | -` | |
| 30 | - } | |
| 50 | + key: 'address' | |
| 51 | + } | |
| 52 | + ], | |
| 53 | + columns9: [ | |
| 54 | + { | |
| 55 | + title: '姓名', | |
| 56 | + key: 'name' | |
| 31 | 57 | }, |
| 32 | 58 | { |
| 33 | - title: '操作', | |
| 34 | - key: 'action', | |
| 35 | - width: 150, | |
| 36 | - align: 'center', | |
| 37 | - render (row, column, index) { | |
| 38 | - return ` | |
| 39 | -<Dropdown trigger="click" style="margin-left: 20px"> | |
| 40 | - <a href="javascript:void(0)"> | |
| 41 | - click 触发 | |
| 42 | - <Icon type="arrow-down-b"></Icon> | |
| 43 | - </a> | |
| 44 | - <Dropdown-menu slot="list"> | |
| 45 | - <Dropdown-item>驴打滚</Dropdown-item> | |
| 46 | - <Dropdown-item>炸酱面</Dropdown-item> | |
| 47 | - <Dropdown-item>豆汁儿</Dropdown-item> | |
| 48 | - <Dropdown-item>冰糖葫芦</Dropdown-item> | |
| 49 | - <Dropdown-item>北京烤鸭</Dropdown-item> | |
| 50 | - </Dropdown-menu> | |
| 51 | - </Dropdown><br><br><br><br><br> | |
| 52 | -`; | |
| 53 | - } | |
| 59 | + title: '年龄', | |
| 60 | + key: 'age', | |
| 61 | + className: 'demo-table-info-column' | |
| 62 | + }, | |
| 63 | + { | |
| 64 | + title: '地址', | |
| 65 | + key: 'address' | |
| 54 | 66 | } |
| 55 | 67 | ], |
| 56 | - data6: [ | |
| 68 | + data1: [ | |
| 57 | 69 | { |
| 58 | 70 | name: '王小明', |
| 59 | 71 | age: 18, |
| ... | ... | @@ -74,18 +86,46 @@ |
| 74 | 86 | age: 26, |
| 75 | 87 | address: '深圳市南山区深南大道' |
| 76 | 88 | } |
| 89 | + ], | |
| 90 | + data8: [ | |
| 91 | + { | |
| 92 | + name: '王小明', | |
| 93 | + age: 18, | |
| 94 | + address: '北京市朝阳区芍药居' | |
| 95 | + }, | |
| 96 | + { | |
| 97 | + name: '张小刚', | |
| 98 | + age: 25, | |
| 99 | + address: '北京市海淀区西二旗', | |
| 100 | + cellClassName: { | |
| 101 | + age: 'demo-table-info-cell-age', | |
| 102 | + address: 'demo-table-info-cell-address' | |
| 103 | + } | |
| 104 | + }, | |
| 105 | + { | |
| 106 | + name: '李小红', | |
| 107 | + age: 30, | |
| 108 | + address: '上海市浦东新区世纪大道' | |
| 109 | + }, | |
| 110 | + { | |
| 111 | + name: '周小伟', | |
| 112 | + age: 26, | |
| 113 | + address: '深圳市南山区深南大道', | |
| 114 | + cellClassName: { | |
| 115 | + name: 'demo-table-info-cell-name' | |
| 116 | + } | |
| 117 | + } | |
| 77 | 118 | ] |
| 78 | 119 | } |
| 79 | 120 | }, |
| 80 | 121 | methods: { |
| 81 | - show (index) { | |
| 82 | - this.$Modal.info({ | |
| 83 | - title: '用户信息', | |
| 84 | - content: `姓名:${this.data6[index].name}<br>年龄:${this.data6[index].age}<br>地址:${this.data6[index].address}` | |
| 85 | - }) | |
| 86 | - }, | |
| 87 | - remove (index) { | |
| 88 | - this.data6.splice(index, 1); | |
| 122 | + rowClassName (row, index) { | |
| 123 | + if (index === 1) { | |
| 124 | + return 'demo-table-info-row'; | |
| 125 | + } else if (index === 3) { | |
| 126 | + return 'demo-table-error-row'; | |
| 127 | + } | |
| 128 | + return ''; | |
| 89 | 129 | } |
| 90 | 130 | } |
| 91 | 131 | } | ... | ... |