(component): table 多列固定

This commit is contained in:
就眠儀式 2022-07-11 09:07:46 +08:00
parent 7e5f0ab0e7
commit dec00677f4
4 changed files with 51 additions and 5 deletions

View File

@ -122,6 +122,24 @@ const renderRowClassName = (data: any, index: number) => {
}; };
const childrenIndentSize = props.currentIndentSize + props.indentSize; const childrenIndentSize = props.currentIndentSize + props.indentSize;
const renderFixedStyle = (column: any, columnIndex: number) => {
if(column.fixed) {
if(column.fixed == 'left') {
var left = 0;
for(var i = 0;i< columnIndex;i ++) {
left = left + props.columns[i]?.width.replace("px","");
}
return `left:${left}px`;
} else {
var right = 0;
for(var i = columnIndex + 1;i< props.columns.length;i ++) {
right = right + props.columns[i]?.width.replace("px","");
}
return `right:${right}px`;
}
}
}
</script> </script>
<template> <template>
@ -156,6 +174,7 @@ const childrenIndentSize = props.currentIndentSize + props.indentSize;
textAlign: column.align, textAlign: column.align,
whiteSpace: column.ellipsisTooltip ? 'nowrap' : 'normal', whiteSpace: column.ellipsisTooltip ? 'nowrap' : 'normal',
}, },
renderFixedStyle(column,columnIndex),
renderCellStyle(data, column, index, columnIndex), renderCellStyle(data, column, index, columnIndex),
]" ]"
:class="[ :class="[
@ -209,6 +228,7 @@ const childrenIndentSize = props.currentIndentSize + props.indentSize;
textAlign: column.align, textAlign: column.align,
whiteSpace: column.ellipsisTooltip ? 'nowrap' : 'normal', whiteSpace: column.ellipsisTooltip ? 'nowrap' : 'normal',
}, },
renderFixedStyle(column,columnIndex),
renderCellStyle(data, column, index, columnIndex), renderCellStyle(data, column, index, columnIndex),
]" ]"
:class="[ :class="[

View File

@ -403,7 +403,6 @@
.layui-table-fixed-left { .layui-table-fixed-left {
left: 0; left: 0;
z-index: 2; z-index: 2;
display: block;
background: white; background: white;
position: sticky!important; position: sticky!important;
} }
@ -411,13 +410,21 @@
.layui-table-fixed-right { .layui-table-fixed-right {
right: 0; right: 0;
z-index: 2; z-index: 2;
display: block;
background: white; background: white;
position: sticky!important; position: sticky!important;
border-left: 1px solid #eee!important; border-left: 1px solid #eee!important;
border-right: none!important; border-right: none!important;
} }
.layui-table-fixed-left,
.layui-table-fixed-right {
outline-width: 1px;
outline-style: solid;
outline-color: #eee;
border: none!important;
}
.layui-table-view .layui-table tr th:last-child, .layui-table-view .layui-table tr th:last-child,
.layui-table-view .layui-table tr td:last-child { .layui-table-view .layui-table tr td:last-child {
border-right: none!important; border-right: none!important;

View File

@ -249,6 +249,24 @@ props.dataSource.map((value: any) => {
childrenExpandSpace.value = true; childrenExpandSpace.value = true;
} }
}); });
const renderFixedStyle = (column: any, columnIndex: number) => {
if(column.fixed) {
if(column.fixed == 'left') {
var left = 0;
for(var i = 0;i< columnIndex;i ++) {
left = left + props.columns[i]?.width.replace("px","");
}
return `left:${left}px`;
} else {
var right = 0;
for(var i = columnIndex + 1;i< props.columns.length;i ++) {
right = right + props.columns[i]?.width.replace("px","");
}
return `right:${right}px`;
}
}
}
</script> </script>
<template> <template>
@ -326,16 +344,16 @@ props.dataSource.map((value: any) => {
/> />
</div> </div>
</th> </th>
<template v-for="column in columns" :key="column"> <template v-for="(column, columnIndex) in columns" :key="column">
<th <th
v-if="tableColumnKeys.includes(column.key)" v-if="tableColumnKeys.includes(column.key)"
class="layui-table-cell" class="layui-table-cell"
:class="[ :class="[
column.fixed ? `layui-table-fixed-${column.fixed}` : '', column.fixed ? `layui-table-fixed-${column.fixed}` : '',
]" ]"
:style="{ :style="[{
textAlign: column.align, textAlign: column.align,
}" },renderFixedStyle(column,columnIndex)]"
> >
<span> <span>
<template v-if="column.titleSlot"> <template v-if="column.titleSlot">

View File

@ -678,6 +678,7 @@ export default {
width:"200px", width:"200px",
key:"username" key:"username"
},{ },{
fixed:"left",
title:"密码", title:"密码",
width: "300px", width: "300px",
key:"password" key:"password"