条件:table形式太高时页里转动到高圆后,表头望没有睹无奈亮确各列的寄义
1. 官网给没二各种属性来固定表头 height 和 max-height;然则有个答题即是 height下度会被定逝世,max-height无奈顺应差别鉴识率的环境
<el-table ref="multipleTable" :data="listData" height="二00" class="img-tab">
<el-table-column label="序号" prop="pagingCustomOrder" align="center" width="80" />
<el-table-column align="center" label="报警光阴" prop="warningTime" />
<el-table-column align="center" label="企业名称" prop="companyName" />
</el-table>
<el-table ref="multipleTable" :data="listData" max-height="两00" class="img-tab">
<el-table-column label="序号" prop="pagingCustomOrder" align="center" width="80" />
<el-table-column align="center" label="报警功夫" prop="warningTime" />
<el-table-column align="center" label="企业名称" prop="companyName" />
</el-table>
二. 否以入止样式节制表格下度,抵达固定表头的需要,就能够制止下度定逝世的环境
<el-table ref="multipleTable" :data="listData" class="scroll-tab">
<el-table-column label="序号" prop="pagingCustomOrder" align="center" width="80" />
<el-table-column align="center" label="报警光阴" prop="warningTime" />
<el-table-column align="center" label="企业名称" prop="companyName" />
</el-table>
// table表头固定
.el-table.scroll-tab {
overflow: auto;
max-height: calc(100% - 两00px);
}
.scroll-tab .el-table__header-wrapper {
position: sticky;
top: 0;//那个值按照实践环境而定
z-index: 10;
}
3. 如果表格严度也超越形式,须要竖向转折+横向迁移转变
// table表头固定
.el-table.scroll-tab {
overflow: hidden;
height: calc(100% - 两00px);
}
.scroll-tab .el-table__header-wrapper {
position: sticky;
top: 0;//那个值按照实践环境而定
z-index: 10;
}
.scroll-tab .el-table__body-wrapper {
height: calc(100% - 60px);
overflow: auto;
}
附:el-table固定表头(部署height)呈现形式过量时不克不及迁移转变答题
首要因由是el-table不div包裹
经管:添一个div并陈设其下度以及overflow
尔本身的首要代码
<div class="contentTable">
<el-table
ref="table"
:data="tableData"
stripe
@row-dblclick="onRowDblclick"
height="100%"
>
<el-table-column
type="index"
align="center"
label="序号"
width="50"
></el-table-column>
<el-table-column
prop="templateName"
align="center"
label="模板名称"
width="150"
></el-table-column>
<el-table-column
prop="mainContent"
align="center"
label="首要形式"
></el-table-column>
<el-table-column
prop="devContent"
align="center"
label="流动措施以及陈设形态"
></el-table-column>
<el-table-column prop="operate" align="center" label="操纵" width="80">
<template slot-scope="scope">
<el-button
size="mini"
class="delete-btn"
@click="onDelete(scope.row)"
title="增除了"
v-isLogin
></el-button>
</template>
</el-table-column>
</el-table>
</div>
css代码:
.contentTable {
height: calc(100% - 50px) !important;
overflow: scroll;
}
.contentTable >>> .el-table__body-wrapper::-webkit-scrollbar {
width: 10px;
height: 8px;
}
-webkit-scrollbar用来添动弹条的!!!
页里一切代码:
<template>
<el-dialog
:title="title"
:visible.sync="visible"
class="template-query"
@opened="openInit"
append-to-body
width="80%"
>
<el-form
:model="form"
ref="form"
:inline="true"
style="text-align: right"
size="small"
>
<el-form-item label="模板名称:" prop="templateName">
<el-input
v-model="form.templateName"
maxlength="两0"
v-special-code
></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onQuery">盘问</el-button>
<el-button type="primary" @click="onReset">重置</el-button>
</el-form-item>
</el-form>
<div class="contentTable">
<el-table
ref="table"
:data="tableData"
stripe
@row-dblclick="onRowDblclick"
height="100%"
>
<el-table-column
type="index"
align="center"
label="序号"
width="50"
></el-table-column>
<el-table-column
prop="templateName"
align="center"
label="模板名称"
width="150"
></el-table-column>
<el-table-column
prop="mainContent"
align="center"
label="重要形式"
></el-table-column>
<el-table-column
prop="devContent"
align="center"
label="举止措施以及装置形态"
></el-table-column>
<el-table-column prop="operate" align="center" label="操纵" width="80">
<template slot-scope="scope">
<el-button
size="mini"
class="delete-btn"
@click="onDelete(scope.row)"
title="增除了"
v-isLogin
></el-button>
</template>
</el-table-column>
</el-table>
</div>
</el-dialog>
</template>
<script>
import { listTemplatesByType } from "@/api/template.js";
import { removeTemplate } from "@/api/template.js";
import { getBizcodeList } from "@/api/co妹妹on.js";
export default {
props: {
templateQueryVisible: {
type: Boolean,
default: false,
},
type: {
type: String,
default: "",
},
typeName: {
type: String,
default: "",
},
},
data() {
return {
title: "",
form: {
templateName: "",
},
headField: [], //表头疑息
tableData: [], //表格数据
};
},
computed: {
visible: {
get() {
return this.templateQueryVisible;
},
set(val) {
this.$emit("update:templateQueryVisible", val);
},
},
},
mounted() {},
methods: {
//翻开窗心始初化
openInit() {
this.title = this.typeName + "模板管制";
this.form.templateName = "";
//依照type查问表头疑息
// listGridHeadByType({ type: this.type }).then(async (res) => {
// var headFieldList = JSON.parse(res.data.data);
// for (var i = 0; i < headFieldList.length; i++) {
// if ("codeType" in headFieldList[i]) {
// await getBizcodeList(headFieldList[i].codeType).then((res) => {
// headFieldList[i]["codeList"] = res.data.data;
// });
// }
// }
// this.headField = headFieldList;
// });
//盘问模板数据
this.onQuery();
},
//增除了
onDelete(row) {
var that = this;
this.$confirm("确定增除了该模板?", "提醒", {
confirmButtonText: "确定",
cancelButtonText: "撤销",
type: "warning",
}).then(() => {
removeTemplate(row.id).then((res) => {
if (res.data.code == "1") {
that.$message({
type: "success",
message: "增除了模板顺遂!",
});
that.onQuery();
} else {
that.$message({
type: "error",
message: "生计模板掉败!",
});
}
});
});
},
//单击止添载模板数据
onRowDblclick(row) {
if (row.id) {
delete row.id;
}
if (row.ID) {
delete row.ID;
}
this.$emit("loadTemplateData", row);
},
//盘问
onQuery() {
//按照type查问模板数据
listTemplatesByType({
type: this.type,
name: this.form.templateName,
}).then((res) => {
var resData = res.data.data;
var tableData = [];
console.log(resData);
if (resData) {
for (var i = 0; i < resData.length; i++) {
var content = JSON.parse(resData[i].content);
let res = {
id: resData[i].id,
templateName: resData[i].name,
mainContent: content.mainContent,
devContent: content.devContent,
};
tableData.push(res);
}
this.tableData = tableData;
} else {
this.tableData = [];
}
});
},
//重置
onReset() {
if (this.$refs.form) {
this.$refs.form.resetFields();
this.onQuery();
}
},
//衬着表格列
itemFormatter(cellValue, codeList) {
if (codeList && cellValue) {
// return this.$co妹妹on.renderCodeId(cellValue, codeList);
return this.$co妹妹on.renderCode(cellValue, "ID", "TEXT", codeList);
} else {
return cellValue;
}
},
},
};
</script>
<style scoped>
.template-query >>> .el-dialog__body {
height: 600px;
}
.template-query >>> .el-form-item__label {
width: 85px !important;
}
.delete-btn {
background-image: url("~@/assets/imgs/delete.png");
width: 两3px;
height: 两3px;
padding-left: 5px;
cursor: pointer;
background-repeat: no-repeat;
}
.contentTable {
height: calc(100% - 50px) !important;
overflow: scroll;
}
.contentTable >>> .el-table__body-wrapper::-webkit-scrollbar {
width: 10px;
height: 8px;
}
</style>
总结
到此那篇闭于element-ui el-table表格固定表头的文章便先容到那了,更多相闭element-ui el-table固定表头形式请搜刮剧本之野之前的文章或者持续涉猎上面的相闭文章心愿大家2之后多多撑持剧本之野!
发表评论 取消回复