update Table
update Table
This commit is contained in:
parent
24b201465e
commit
5d0499ce1e
7 changed files with 80 additions and 29 deletions
|
@ -19,7 +19,10 @@
|
||||||
naturalIndex: Number, // index of rebuildData
|
naturalIndex: Number, // index of rebuildData
|
||||||
index: Number, // _index of data
|
index: Number, // _index of data
|
||||||
checked: Boolean,
|
checked: Boolean,
|
||||||
fixed: Boolean
|
fixed: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
alignCls (column) {
|
alignCls (column) {
|
||||||
return column.align ? `${this.prefixCls}-column-${column.align}` : '';
|
return [
|
||||||
|
{
|
||||||
|
[`${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'))
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
isPopperShow (column) {
|
||||||
|
return column.filters && ((!this.fixed && !column.fixed) || (this.fixed === 'left' && column.fixed === 'left') || (this.fixed === 'right' && column.fixed === 'right'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,10 @@
|
||||||
columns: Array,
|
columns: Array,
|
||||||
data: Array, // rebuildData
|
data: Array, // rebuildData
|
||||||
objData: Object,
|
objData: Object,
|
||||||
fixed: Boolean
|
fixed: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
rowClasses (_index) {
|
rowClasses (_index) {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<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
|
<Poptip
|
||||||
v-if="column.filters && (fixed || (!fixed && !column.fixed))"
|
v-if="isPopperShow(column)"
|
||||||
:visible.sync="column._filterVisible"
|
:visible.sync="column._filterVisible"
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
@on-popper-hide="handleFilterHide($index)">
|
@on-popper-hide="handleFilterHide($index)">
|
||||||
|
@ -69,7 +69,10 @@
|
||||||
columns: Array,
|
columns: Array,
|
||||||
objData: Object,
|
objData: Object,
|
||||||
data: Array, // rebuildData
|
data: Array, // rebuildData
|
||||||
fixed: Boolean
|
fixed: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
isSelectAll () {
|
isSelectAll () {
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
:data="rebuildData"
|
:data="rebuildData"
|
||||||
:obj-data="objData"></table-body>
|
:obj-data="objData"></table-body>
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-fixed']">
|
<div :class="[prefixCls + '-fixed']" :style="fixedTableStyle">
|
||||||
<div :class="[prefixCls + '-fixed-header']" v-if="showHeader">
|
<div :class="[prefixCls + '-fixed-header']" v-if="showHeader">
|
||||||
<table-head
|
<table-head
|
||||||
fixed
|
fixed="left"
|
||||||
:prefix-cls="prefixCls"
|
:prefix-cls="prefixCls"
|
||||||
:style="fixedTableStyle"
|
:style="fixedTableStyle"
|
||||||
:columns="leftFixedColumns"
|
:columns="leftFixedColumns"
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" v-el:fixed-body>
|
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" v-el:fixed-body>
|
||||||
<table-body
|
<table-body
|
||||||
fixed
|
fixed="left"
|
||||||
:prefix-cls="prefixCls"
|
:prefix-cls="prefixCls"
|
||||||
:style="fixedTableStyle"
|
:style="fixedTableStyle"
|
||||||
:columns="leftFixedColumns"
|
:columns="leftFixedColumns"
|
||||||
|
@ -39,10 +39,10 @@
|
||||||
:obj-data="objData"></table-body>
|
:obj-data="objData"></table-body>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-fixed-right']">
|
<div :class="[prefixCls + '-fixed-right']" :style="fixedRightTableStyle">
|
||||||
<div :class="[prefixCls + '-fixed-header']" v-if="showHeader">
|
<div :class="[prefixCls + '-fixed-header']" v-if="showHeader">
|
||||||
<table-head
|
<table-head
|
||||||
fixed
|
fixed="right"
|
||||||
:prefix-cls="prefixCls"
|
:prefix-cls="prefixCls"
|
||||||
:style="fixedRightTableStyle"
|
:style="fixedRightTableStyle"
|
||||||
:columns="rightFixedColumns"
|
:columns="rightFixedColumns"
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" v-el:fixed-right-body>
|
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" v-el:fixed-right-body>
|
||||||
<table-body
|
<table-body
|
||||||
fixed
|
fixed="right"
|
||||||
:prefix-cls="prefixCls"
|
:prefix-cls="prefixCls"
|
||||||
:style="fixedRightTableStyle"
|
:style="fixedRightTableStyle"
|
||||||
:columns="rightFixedColumns"
|
:columns="rightFixedColumns"
|
||||||
|
@ -126,7 +126,7 @@
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
compiledUids: [],
|
compiledUids: [],
|
||||||
objData: this.makeObjData(), // checkbox or highlight-row
|
objData: this.makeObjData(), // checkbox or highlight-row
|
||||||
rebuildData: this.makeData(), // for sort or filter
|
rebuildData: [], // for sort or filter
|
||||||
cloneColumns: this.makeColumns(),
|
cloneColumns: this.makeColumns(),
|
||||||
showSlotHeader: true,
|
showSlotHeader: true,
|
||||||
showSlotFooter: true,
|
showSlotFooter: true,
|
||||||
|
@ -168,12 +168,20 @@
|
||||||
},
|
},
|
||||||
fixedTableStyle () {
|
fixedTableStyle () {
|
||||||
let style = {};
|
let style = {};
|
||||||
if (this.leftFixedColumns.length) style.width = this.leftFixedColumns.reduce((a, b) => a + b);
|
let width = 0;
|
||||||
|
this.leftFixedColumns.forEach((col) => {
|
||||||
|
if (col.fixed && col.fixed === 'left') width += col.width;
|
||||||
|
});
|
||||||
|
style.width = `${width}px`;
|
||||||
return style;
|
return style;
|
||||||
},
|
},
|
||||||
fixedRightTableStyle () {
|
fixedRightTableStyle () {
|
||||||
let style = {};
|
let style = {};
|
||||||
if (this.rightFixedColumns.length) style.width = this.rightFixedColumns.reduce((a, b) => a + b);
|
let width = 0;
|
||||||
|
this.rightFixedColumns.forEach((col) => {
|
||||||
|
if (col.fixed && col.fixed === 'right') width += col.width;
|
||||||
|
});
|
||||||
|
style.width = `${width}px`;
|
||||||
return style;
|
return style;
|
||||||
},
|
},
|
||||||
bodyStyle () {
|
bodyStyle () {
|
||||||
|
@ -188,21 +196,27 @@
|
||||||
},
|
},
|
||||||
leftFixedColumns () {
|
leftFixedColumns () {
|
||||||
let left = [];
|
let left = [];
|
||||||
|
let other = [];
|
||||||
this.cloneColumns.forEach((col) => {
|
this.cloneColumns.forEach((col) => {
|
||||||
if (col.fixed && col.fixed === 'left') {
|
if (col.fixed && col.fixed === 'left') {
|
||||||
left.push(col);
|
left.push(col);
|
||||||
|
} else {
|
||||||
|
other.push(col);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return left;
|
return left.concat(other);
|
||||||
},
|
},
|
||||||
rightFixedColumns () {
|
rightFixedColumns () {
|
||||||
let right = [];
|
let right = [];
|
||||||
|
let other = [];
|
||||||
this.cloneColumns.forEach((col) => {
|
this.cloneColumns.forEach((col) => {
|
||||||
if (col.fixed && col.fixed === 'right') {
|
if (col.fixed && col.fixed === 'right') {
|
||||||
right.push(col);
|
right.push(col);
|
||||||
|
} else {
|
||||||
|
other.push(col);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return right;
|
return right.concat(other);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -457,6 +471,10 @@
|
||||||
} else {
|
} else {
|
||||||
column._filterMultiple = true;
|
column._filterMultiple = true;
|
||||||
}
|
}
|
||||||
|
if ('filteredValue' in column) {
|
||||||
|
column._filterChecked = column.filteredValue;
|
||||||
|
column._isFiltered = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (column.fixed && column.fixed === 'left') {
|
if (column.fixed && column.fixed === 'left') {
|
||||||
left.push(column);
|
left.push(column);
|
||||||
|
@ -472,6 +490,7 @@
|
||||||
compiled () {
|
compiled () {
|
||||||
this.showSlotHeader = this.$els.title.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
|
this.showSlotHeader = this.$els.title.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
|
||||||
this.showSlotFooter = this.$els.footer.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
|
this.showSlotFooter = this.$els.footer.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
|
||||||
|
this.rebuildData = this.makeDataWithSortAndFilter();
|
||||||
},
|
},
|
||||||
ready () {
|
ready () {
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
|
|
|
@ -206,7 +206,6 @@
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
//box-shadow: @shadow-right;
|
|
||||||
box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.2);
|
box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.2);
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
|
@ -224,13 +223,10 @@
|
||||||
top: 0;
|
top: 0;
|
||||||
left: auto;
|
left: auto;
|
||||||
right: 0;
|
right: 0;
|
||||||
//box-shadow: @shadow-left;
|
|
||||||
box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2);
|
box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
&-fixed-header{
|
&-fixed-header{
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
//position: relative;
|
|
||||||
//z-index: 3;
|
|
||||||
}
|
}
|
||||||
&-fixed-body{
|
&-fixed-body{
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<!--<i-table size="large" border stripe :columns="columns" :data="data"></i-table>-->
|
<!--<i-table size="large" border stripe :columns="columns" :data="data"></i-table>-->
|
||||||
<br>
|
<br>
|
||||||
<i-table
|
<i-table
|
||||||
width="450"
|
width="850"
|
||||||
:height="height"
|
:height="height"
|
||||||
stripe
|
stripe
|
||||||
:border="true"
|
:border="true"
|
||||||
|
@ -40,8 +40,8 @@
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
type: 'selection',
|
type: 'selection',
|
||||||
width: 50,
|
width: 90,
|
||||||
fixed: 'left',
|
// fixed: 'left',
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
title: '姓名',
|
title: '姓名',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
fixed: 'left',
|
// fixed: 'left',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
width: 100,
|
width: 100,
|
||||||
filters: [
|
filters: [
|
||||||
|
@ -91,6 +91,7 @@
|
||||||
filterMethod (value, row) {
|
filterMethod (value, row) {
|
||||||
return row.tag === value;
|
return row.tag === value;
|
||||||
},
|
},
|
||||||
|
// filteredValue: ['company'],
|
||||||
render (row) {
|
render (row) {
|
||||||
const type = `${row.tag}` === 'home' ? 'green' : 'red';
|
const type = `${row.tag}` === 'home' ? 'green' : 'red';
|
||||||
return `<tag color="${type}">${row.tag}</tag>`;
|
return `<tag color="${type}">${row.tag}</tag>`;
|
||||||
|
@ -129,7 +130,7 @@
|
||||||
title: '地址',
|
title: '地址',
|
||||||
key: 'address',
|
key: 'address',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
// fixed: 'right',
|
// fixed: 'left',
|
||||||
width: 100,
|
width: 100,
|
||||||
// render (row, column, index) {
|
// render (row, column, index) {
|
||||||
// if (row.edit) {
|
// if (row.edit) {
|
||||||
|
@ -142,17 +143,35 @@
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
fixed: 'right',
|
// fixed: 'right',
|
||||||
width: 120,
|
width: 250,
|
||||||
render (row, column, index) {
|
render (row, column, index) {
|
||||||
return `<i-button @click="edit(${index})">${row.name}${index}</i-button>`;
|
return `<i-button @click="edit(${index})">${row.name}${index}</i-button>`;
|
||||||
return `<a>${row.name}</a>`;
|
// return `<a href="#">${row.name}</a>`;
|
||||||
|
},
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
label: '两个字',
|
||||||
|
value: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '三个字',
|
||||||
|
value: 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
filterMultiple: false,
|
||||||
|
filterMethod (value, row) {
|
||||||
|
if (value === 1) {
|
||||||
|
return row.name.length == 2;
|
||||||
|
} else if (value === 2) {
|
||||||
|
return row.name.length == 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
name: '梁灏',
|
name: '梁灏梁灏梁灏梁灏梁灏梁灏梁灏',
|
||||||
age: 25,
|
age: 25,
|
||||||
address: '北京市朝阳区',
|
address: '北京市朝阳区',
|
||||||
edit: false,
|
edit: false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue