update Table

update Table
This commit is contained in:
梁灏 2016-11-29 11:04:48 +08:00
parent 7f1edb6a15
commit adaeca88ba
4 changed files with 65 additions and 16 deletions

View file

@ -14,25 +14,31 @@
<i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort($index, 'asc')"></i> <i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort($index, 'asc')"></i>
<i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort($index, 'desc')"></i> <i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort($index, 'desc')"></i>
</span> </span>
<Poptip v-if="column.filters" :visible.sync="column._filterVisible" placement="bottom"> <Poptip
v-if="column.filters && (fixed || (!fixed && !column.fixed))"
:visible.sync="column._filterVisible"
placement="bottom"
@on-popper-hide="handleFilterHide($index)">
<span :class="[prefixCls + '-filter']"> <span :class="[prefixCls + '-filter']">
<i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i> <i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
</span> </span>
<div slot="content" :class="[prefixCls + '-filter-list']"> <div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
<div :class="[prefixCls + '-filter-list-item']"> <div :class="[prefixCls + '-filter-list-item']">
<checkbox-group :model.sync="column._filterChecked"> <checkbox-group :model.sync="column._filterChecked">
<checkbox v-for="item in column.filters" :value="item.value">{{ item.label }}</checkbox> <checkbox v-for="item in column.filters" :value="item.value">{{ item.label }}</checkbox>
</checkbox-group> </checkbox-group>
</div> </div>
<ul>
<!--<li v-for="(filterIndex, item) in column.filters"><Checkbox :checked="column._filterChecked.indexOf(item.value) > -1" @on-change="handleFilterChecked(index, filterIndex)">{{ item.label }}</Checkbox></li>-->
</ul>
<div :class="[prefixCls + '-filter-footer']"> <div :class="[prefixCls + '-filter-footer']">
<i-button type="text" size="small" @click="handleFilter($index)">筛选</i-button> <i-button type="text" size="small" :disabled="!column._filterChecked.length" @click="handleFilter($index)">筛选</i-button>
<i-button type="text" size="small" @click="handleReset($index)">重置</i-button> <i-button type="text" size="small" @click="handleReset($index)">重置</i-button>
</div> </div>
</div> </div>
<div slot="content" :class="[prefixCls + '-filter-list']" v-else>
<ul>
<li :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: !column._filterChecked.lengtg}]">全部</li>
<li :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: column._filterChecked[0] === item.value}]" v-for="item in column.filters">{{ item.label }}</li>
</ul>
</div>
</Poptip> </Poptip>
</template> </template>
</div> </div>
@ -99,13 +105,13 @@
this.$parent.handleSort(index, type); this.$parent.handleSort(index, type);
}, },
handleFilter (index) { handleFilter (index) {
this.$parent.handleFilter(index);
}, },
handleReset (index) { handleReset (index) {
this.$parent.handleFilterReset(index);
}, },
handleFilterChecked (index, filterIndex) { handleFilterHide (index) {
this.$parent.handleFilterHide(index);
} }
} }
} }

View file

@ -115,6 +115,7 @@
}, },
data () { data () {
return { return {
ready: false,
tableWidth: 0, tableWidth: 0,
columnsWidth: [], columnsWidth: [],
prefixCls: prefixCls, prefixCls: prefixCls,
@ -132,6 +133,7 @@
return [ return [
`${prefixCls}`, `${prefixCls}`,
{ {
[`${prefixCls}-hide`]: !this.ready,
[`${prefixCls}-${this.size}`]: !!this.size, [`${prefixCls}-${this.size}`]: !!this.size,
[`${prefixCls}-border`]: this.border, [`${prefixCls}-border`]: this.border,
[`${prefixCls}-stripe`]: this.stripe, [`${prefixCls}-stripe`]: this.stripe,
@ -344,6 +346,27 @@
order: type order: type
}) })
}, },
handleFilterHide (index) { // clear checked that not filter now
if (!this.cloneColumns[index]._isFiltered) this.cloneColumns[index]._filterChecked = [];
},
handleFilter (index) {
const column = this.cloneColumns[index];
const filterData = this.makeData();
this.rebuildData = filterData.filter((row) => {
let status = false;
for (let i = 0; i < column._filterChecked.length; i++) {
status = column.filterMethod(column._filterChecked[i], row);
if (status) break;
}
return status;
});
this.cloneColumns[index]._isFiltered = true;
this.cloneColumns[index]._filterVisible = false;
},
handleFilterReset (index) {
this.cloneColumns[index]._isFiltered = false;
},
makeData () { makeData () {
let data = deepCopy(this.data); let data = deepCopy(this.data);
data.forEach((row, index) => row._index = index); data.forEach((row, index) => row._index = index);
@ -373,6 +396,12 @@
column._isFiltered = false; column._isFiltered = false;
column._filterChecked = []; column._filterChecked = [];
if ('filterMultiple' in column) {
column._filterMultiple = column.filterMultiple;
} else {
column._filterMultiple = true;
}
if (column.fixed && column.fixed === 'left') { if (column.fixed && column.fixed === 'left') {
left.push(column); left.push(column);
} else if (column.fixed && column.fixed === 'right') { } else if (column.fixed && column.fixed === 'right') {
@ -391,6 +420,7 @@
ready () { ready () {
this.handleResize(); this.handleResize();
this.fixedHeader(); this.fixedHeader();
this.$nextTick(() => this.ready = true);
window.addEventListener('resize', this.handleResize, false); window.addEventListener('resize', this.handleResize, false);
}, },
beforeDestroy () { beforeDestroy () {

View file

@ -1,4 +1,5 @@
@table-prefix-cls: ~"@{css-prefix}table"; @table-prefix-cls: ~"@{css-prefix}table";
@table-select-item-prefix-cls: ~"@{table-prefix-cls}-filter-select-item";
.@{table-prefix-cls} { .@{table-prefix-cls} {
width: 100%; width: 100%;
@ -13,6 +14,10 @@
box-sizing: border-box; box-sizing: border-box;
position: relative; position: relative;
&-hide{
opacity: 0;
}
&:before{ &:before{
content: ''; content: '';
width: 100%; width: 100%;
@ -262,6 +267,10 @@
} }
} }
} }
ul{
padding-bottom: 8px;
}
.select-item(@table-prefix-cls, @table-select-item-prefix-cls);
} }
&-footer{ &-footer{
padding: 4px; padding: 4px;

View file

@ -63,6 +63,7 @@
value: 'company' value: 'company'
} }
], ],
filterMultiple: false
}, },
{ {
title: '标签', title: '标签',
@ -78,8 +79,11 @@
value: 'company' value: 'company'
} }
], ],
filterMethod (value, row) {
return row.tag === value;
},
render (row) { render (row) {
const type = `${row.tag}` === '家' ? 'green' : 'red'; const type = `${row.tag}` === 'home' ? 'green' : 'red';
return `<tag color="${type}">${row.tag}</tag>`; return `<tag color="${type}">${row.tag}</tag>`;
} }
}, },
@ -135,28 +139,28 @@
age: 25, age: 25,
address: '北京市朝阳区', address: '北京市朝阳区',
edit: false, edit: false,
tag: '' tag: 'home'
}, },
{ {
name: '段模', name: '段模',
age: 21, age: 21,
address: '北京市海淀区', address: '北京市海淀区',
edit: false, edit: false,
tag: '公司' tag: 'company'
}, },
{ {
name: '刘天娇', name: '刘天娇',
age: 27, age: 27,
address: '北京市东城区', address: '北京市东城区',
edit: false, edit: false,
tag: '公司' tag: 'company'
}, },
{ {
name: '胡国伟', name: '胡国伟',
age: 22, age: 22,
address: '北京市西城区', address: '北京市西城区',
edit: false, edit: false,
tag: '' tag: 'home'
} }
], ],
height: 200 height: 200