From 7f34c510307215cc599a2ba86d638570e16e0fe5 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Sat, 26 Nov 2016 08:57:09 +0800 Subject: [PATCH] update Table --- src/components/table/cell.vue | 23 +++++++++++++---------- src/components/table/table-body.vue | 60 ++++++++++++++++++++++++++++++++++++++++++++++++------------ src/components/table/table-head.vue | 37 +++++++++++++++++++++---------------- src/components/table/table.vue | 91 +++++++++++++++++++++++++++++++++++++++++-------------------------------------------------- src/styles/components/table.less | 25 +++++++++++++++++++++++++ test/routers/table.vue | 2 +- 6 files changed, 149 insertions(+), 89 deletions(-) diff --git a/src/components/table/cell.vue b/src/components/table/cell.vue index 15be5a7..e31c6a6 100644 --- a/src/components/table/cell.vue +++ b/src/components/table/cell.vue @@ -17,7 +17,8 @@ row: Object, column: Object, index: Number, - checked: Boolean + checked: Boolean, + fixed: Boolean }, data () { return { @@ -30,7 +31,7 @@ return [ `${this.prefixCls}-cell`, { - [`${this.prefixCls}-hidden`]: this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right') + [`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right') } ] } @@ -38,29 +39,31 @@ methods: { compile () { if (this.column.render) { + const $parent = this.$parent.$parent.$parent; const template = this.column.render(this.row, this.column, this.index); const cell = document.createElement('div'); cell.innerHTML = template; - const _oldParentChildLen = this.$parent.$parent.$children.length; - this.$parent.$parent.$compile(cell); - const _newParentChildLen = this.$parent.$parent.$children.length; + const _oldParentChildLen = $parent.$children.length; + $parent.$compile(cell); + const _newParentChildLen = $parent.$children.length; if (_oldParentChildLen !== _newParentChildLen) { // if render normal html node, do not tag - this.uid = this.$parent.$parent.$children[this.$parent.$parent.$children.length - 1]._uid; // tag it, and delete when data or columns update + this.uid = $parent.$children[$parent.$children.length - 1]._uid; // tag it, and delete when data or columns update } this.$el.innerHTML = ''; this.$el.appendChild(cell); } }, destroy () { - for (let i = 0; i < this.$parent.$parent.$children.length; i++) { - if (this.$parent.$parent.$children[i]._uid === this.uid) { - this.$parent.$parent.$children[i].$destroy(); + const $parent = this.$parent.$parent.$parent; + for (let i = 0; i < $parent.$children.length; i++) { + if ($parent.$children[i]._uid === this.uid) { + $parent.$children[i].$destroy(); } } }, toggleSelect (index) { - this.$parent.toggleSelect(index); + this.$parent.$parent.toggleSelect(index); } }, compiled () { diff --git a/src/components/table/table-body.vue b/src/components/table/table-body.vue index 080ffc4..af99b5e 100644 --- a/src/components/table/table-body.vue +++ b/src/components/table/table-body.vue @@ -1,23 +1,59 @@ \ No newline at end of file diff --git a/src/components/table/table-head.vue b/src/components/table/table-head.vue index 7761338..dfd85c0 100644 --- a/src/components/table/table-head.vue +++ b/src/components/table/table-head.vue @@ -1,14 +1,19 @@