fixed-head
This commit is contained in:
parent
3f14387d1a
commit
c1e965c371
4 changed files with 37 additions and 27 deletions
|
@ -3,7 +3,7 @@
|
||||||
<br><br><br><br><br>
|
<br><br><br><br><br>
|
||||||
<Table border :columns="columns1" height="500" :data="data1"></Table>
|
<Table border :columns="columns1" height="500" :data="data1"></Table>
|
||||||
<br><br><br><br><br>
|
<br><br><br><br><br>
|
||||||
<!--<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>-->
|
<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>
|
||||||
<br><br><br><br><br>
|
<br><br><br><br><br>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -84,8 +84,7 @@
|
||||||
key: 'gender',
|
key: 'gender',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
width: 200,
|
width: 200,
|
||||||
fixed: 'right',
|
fixed: 'right'
|
||||||
// fixed: 'left'
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
columns2: [
|
columns2: [
|
||||||
|
|
|
@ -87,7 +87,8 @@
|
||||||
type: [Boolean, String],
|
type: [Boolean, String],
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
columnRows: Array
|
columnRows: Array,
|
||||||
|
fixedColumnRows: Array
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
styles () {
|
styles () {
|
||||||
|
@ -116,7 +117,11 @@
|
||||||
},
|
},
|
||||||
headRows () {
|
headRows () {
|
||||||
const isGroup = this.columnRows.length > 1;
|
const isGroup = this.columnRows.length > 1;
|
||||||
return isGroup ? this.columnRows : [this.columns];
|
if (isGroup) {
|
||||||
|
return this.fixed ? this.fixedColumnRows : this.columnRows;
|
||||||
|
} else {
|
||||||
|
return [this.columns];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
:styleObject="fixedTableStyle"
|
:styleObject="fixedTableStyle"
|
||||||
:columns="leftFixedColumns"
|
:columns="leftFixedColumns"
|
||||||
:column-rows="columnRows"
|
:column-rows="columnRows"
|
||||||
|
:fixed-column-rows="leftFixedColumnRows"
|
||||||
:obj-data="objData"
|
:obj-data="objData"
|
||||||
:columns-width="columnsWidth"
|
:columns-width="columnsWidth"
|
||||||
:data="rebuildData"></table-head>
|
:data="rebuildData"></table-head>
|
||||||
|
@ -68,6 +69,7 @@
|
||||||
:styleObject="fixedRightTableStyle"
|
:styleObject="fixedRightTableStyle"
|
||||||
:columns="rightFixedColumns"
|
:columns="rightFixedColumns"
|
||||||
:column-rows="columnRows"
|
:column-rows="columnRows"
|
||||||
|
:fixed-column-rows="rightFixedColumnRows"
|
||||||
:obj-data="objData"
|
:obj-data="objData"
|
||||||
:columns-width="columnsWidth"
|
:columns-width="columnsWidth"
|
||||||
:data="rebuildData"></table-head>
|
:data="rebuildData"></table-head>
|
||||||
|
@ -184,7 +186,9 @@
|
||||||
objData: this.makeObjData(), // checkbox or highlight-row
|
objData: this.makeObjData(), // checkbox or highlight-row
|
||||||
rebuildData: [], // for sort or filter
|
rebuildData: [], // for sort or filter
|
||||||
cloneColumns: this.makeColumns(),
|
cloneColumns: this.makeColumns(),
|
||||||
columnRows: this.makeColumnRows(),
|
columnRows: this.makeColumnRows(false),
|
||||||
|
leftFixedColumnRows: this.makeColumnRows('left'),
|
||||||
|
rightFixedColumnRows: this.makeColumnRows('right'),
|
||||||
allColumns: getAllColumns(this.columns), // for multiple table-head, get columns that have no children
|
allColumns: getAllColumns(this.columns), // for multiple table-head, get columns that have no children
|
||||||
showSlotHeader: true,
|
showSlotHeader: true,
|
||||||
showSlotFooter: true,
|
showSlotFooter: true,
|
||||||
|
@ -779,8 +783,8 @@
|
||||||
return left.concat(center).concat(right);
|
return left.concat(center).concat(right);
|
||||||
},
|
},
|
||||||
// create a multiple table-head
|
// create a multiple table-head
|
||||||
makeColumnRows () {
|
makeColumnRows (fixedType) {
|
||||||
return convertToRows(this.columns);
|
return convertToRows(this.columns, fixedType);
|
||||||
},
|
},
|
||||||
exportCsv (params) {
|
exportCsv (params) {
|
||||||
if (params.filename) {
|
if (params.filename) {
|
||||||
|
@ -858,7 +862,9 @@
|
||||||
// todo 这里有性能问题,可能是左右固定计算属性影响的
|
// todo 这里有性能问题,可能是左右固定计算属性影响的
|
||||||
this.allColumns = getAllColumns(this.columns);
|
this.allColumns = getAllColumns(this.columns);
|
||||||
this.cloneColumns = this.makeColumns();
|
this.cloneColumns = this.makeColumns();
|
||||||
this.columnRows = this.makeColumnRows();
|
this.columnRows = this.makeColumnRows(false);
|
||||||
|
this.leftFixedColumnRows = this.makeColumnRows('left');
|
||||||
|
this.rightFixedColumnRows = this.makeColumnRows('right');
|
||||||
this.rebuildData = this.makeDataWithSortAndFilter();
|
this.rebuildData = this.makeDataWithSortAndFilter();
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
import { deepCopy } from '../../utils/assist';
|
import { deepCopy } from '../../utils/assist';
|
||||||
|
|
||||||
|
const convertColumnOrder = (columns, fixedType) => {
|
||||||
|
let list = [];
|
||||||
|
let other = [];
|
||||||
|
columns.forEach((col) => {
|
||||||
|
if (col.fixed && col.fixed === fixedType) {
|
||||||
|
list.push(col);
|
||||||
|
} else {
|
||||||
|
other.push(col);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return list.concat(other);
|
||||||
|
};
|
||||||
|
|
||||||
|
export {convertColumnOrder};
|
||||||
|
|
||||||
// set forTableHead to true when convertToRows, false in normal cases like table.vue
|
// set forTableHead to true when convertToRows, false in normal cases like table.vue
|
||||||
const getAllColumns = (cols, forTableHead = false) => {
|
const getAllColumns = (cols, forTableHead = false) => {
|
||||||
const columns = deepCopy(cols);
|
const columns = deepCopy(cols);
|
||||||
|
@ -17,8 +32,8 @@ const getAllColumns = (cols, forTableHead = false) => {
|
||||||
|
|
||||||
export {getAllColumns};
|
export {getAllColumns};
|
||||||
|
|
||||||
const convertToRows = (columns) => {
|
const convertToRows = (columns, fixedType = false) => {
|
||||||
const originColumns = deepCopy(columns);
|
const originColumns = fixedType ? fixedType === 'left' ? deepCopy(convertColumnOrder(columns, 'left')) : deepCopy(convertColumnOrder(columns, 'right')) : deepCopy(columns);
|
||||||
let maxLevel = 1;
|
let maxLevel = 1;
|
||||||
const traverse = (column, parent) => {
|
const traverse = (column, parent) => {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
@ -64,18 +79,3 @@ const convertToRows = (columns) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export {convertToRows};
|
export {convertToRows};
|
||||||
|
|
||||||
const convertColumnOrder = (columns, FixedType) => {
|
|
||||||
let list = [];
|
|
||||||
let other = [];
|
|
||||||
columns.forEach((col) => {
|
|
||||||
if (col.fixed && col.fixed === FixedType) {
|
|
||||||
list.push(col);
|
|
||||||
} else {
|
|
||||||
other.push(col);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return list.concat(other);
|
|
||||||
};
|
|
||||||
|
|
||||||
export {convertColumnOrder};
|
|
Loading…
Add table
Reference in a new issue