This article shares the specific code of vue+elementui to realize multiple selection and search of drop-down table for your reference. The specific content is as follows Combine the drop-down box and table based on elementui template <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px" id="selecTable" @click.native="closeup"> <el-select v-model="dataForm.processDefinitionId" placeholder="Please select" @change="handselect" ref="select" @click.native="deptogglePanel($event)" multiple collapse-tags size="medium"> <el-option v-for="(item,index) in processDefinition" :key="index" :label="item.name" :value="item.id"> </el-option> </el-select> <div v-if="showTree" class="treeDiv" ref="tableList"> <el-input placeholder="Search" v-model="ss" @input="handinput" size="medium"> </el-input> <el-table @select="handleSelectClick" @row-click="handleRegionNodeClick" @selection-change="handleChange" ref="moviesTable" :data="memberList" border :row-key="getRowKeys" :cell-style="getCellStyle" :header-cell-style="getHeaderCellStyle" @select-all="selectAll"> <el-table-column type="selection" header-align="center" align="center" :reserve-selection="true" width="50"> </el-table-column> <el-table-column v-for="(item, index) in Columns" :key="index" :prop="item.prop" :label="item.label" :show-overflow-tooltip="true"> </el-table-column> </el-table> </div> </el-form> js <script> export default { data() { return { ss: '', visible: false, isDisabled: false, dataForm: { termName: '', //Project nameprocessDefinitionId: [] }, dataRule: { processDefinitionId: [{ required: true, message: 'Please select the file', trigger: 'change' }], termName: [{ required: true, message: 'Project name cannot be empty', trigger: 'blur' }], }, arr: [], processDefinition: [], //Process template drop-down box memberList: [], // list showTree: false, Columns: [{ prop: 'number', label: 'File encoding' }, { prop: 'name', label: 'File name' }, { prop: 'typename', label: 'Template type' }, { prop: 'efilename', label: 'File type' }, { prop: 'version', label: 'version' }, ], getRowKeys(row) { return row.id; }, multipleSelection: [], isShowSelect: true } }, created() {}, mounted() { }, watch: isShowSelect(val) { // Hide the drop-down box that comes with select this.$refs.select.blur(); }, }, methods: { init() { this.$nextTick(() => { this.$refs['dataForm'].resetFields(); this.isDisabled = false; this.arr = []; this.multipleSelection = []; }).then(() => { //Archive file drop-down box this.$axios.get("/term/getFileArchiveSelect").then((res) => { console.log('Archive file drop-down box:', res); if (res.data.code != 200) { this.memberList = [] } else { this.processDefinition = res.data.page.list this.memberList = res.data.page.list // table assignment} }) if (!this.dataForm.id) { // New // this.menuListTreeSetCurrentNode() } else { this.$axios.get("/term/getTermDeatil/" + this.dataForm.id).then((res) => { console.log("Project details:", res); if (res.data.code != 200) { // this.$message.error(res.data.msg) } else { let data = res.data.termResVO; if (data.fileArchiveIds != '') { this.dataForm.processDefinitionId = data.fileArchiveIds.split(',') } else { this.dataForm.processDefinitionId = [] } this.multipleSelection = data.child; this.rowMultipleChecked(this.multipleSelection); } }) } }).catch((error) => { console.log(error); }); }, // Table css getCellStyle() { return "text-align:center;" }, getHeaderCellStyle() { return "background: rgba(9, 37, 56,0.1);text-align:center; background: linear-gradient(to bottom,#ffffff 0,#eeeeee 100%);padding: 4px 5px;" }, // Click input to prevent bubbling and control table display and hide deptogglePanel(event) { this.isShowSelect = !this.isShowSelect; //Hide the original select drop-down box event || (event = window.event) event.stopPropagation ? event.stopPropagation() : (event.cancelBubble = true) this.showTree ? this.tableHide() : this.tableShow() }, //Show the table tableShow() { this.showTree = true document.addEventListener('click', this.tableHideList, false) this.rowMultipleChecked(this.multipleSelection); }, //Hide the table tableHide() { this.showTree = false document.addEventListener('click', this.tableHideList, false) }, tableHideList(e) { if (this.$refs.tableList && !this.$refs.tableList.contains(e.target)) { this.tableHide() } }, // Click on the table node handleRegionNodeClick(data) { this.showTree = true }, //Multiple selection handleSelectClick(data) { this.showTree = true }, //Select all selectAll(data) { this.showTree = true }, // selection-change table multiple selection box change event handleChange(data) {//Selected row in the table this.arr = []; for (let i in data) { this.arr.push(data[i].id) } this.dataForm.processDefinitionId = this.arr; //select assignment this.multipleSelection = data; //Check and put it in the multipleSelection array}, //Table multiple selection box selection judgment rowMultipleChecked(multipleSelection) { console.log(multipleSelection) if (multipleSelection != null) { for (let j = 0; j < multipleSelection.length; j++) { for (let i = 0; i < this.memberList.length; i++) { if (multipleSelection[j].id == this.memberList[i].id) {//If the id exists in the value sent from the backend, select the multiple selection box this.$nextTick(() => {//Required if (this.$refs.moviesTable != undefined) { this.$refs.moviesTable.toggleRowSelection(this.memberList[i], true); } }) } } } } }, //Delete the file handselect(value) {//Select is associated with the table let data = this.multipleSelection; let arr = []; if (value.length > 0) {//Delete the value in multipleSelection (all selected values) for (let j = 0; j < data.length; j++) { if (value.indexOf(data[j].id) == -1) { data.splice(j, 1) } } this.multipleSelection = data } else { this.multipleSelection = []; data = []; } for (let s in data) { arr.push(data[s].id) } if (arr != null) {//Need to determine which values need to be unchecked for (let i = 0; i < this.memberList.length; i++) { if (arr.indexOf(this.memberList[i].id) == -1) { this.$refs.moviesTable.toggleRowSelection(this.memberList[i], false); } } } }, //Search handinput() { console.log(this.ss); this.tableShow() this.$axios.get('/term/getFileArchiveSelect').then((res) => { console.log(res); if (res.data.code != 200) {} else { this.processDefinition = res.data.page.list this.memberList = res.data.page.list console.log(this.memberList) let resultData = this.memberList.filter(data => { if (data.number.indexOf(this.ss) != -1 || data.name.indexOf(this.ss) != -1 || data.typename.indexOf(this.ss) != -1 || data.version.indexOf(this.ss) != - 1 || data.efilename.indexOf(this.ss) != -1) { //You can continue to add judgment conditions return true; } }); this.memberList = resultData; } }) }, // Form submission dataFormSubmit() { this.$refs['dataForm'].validate((valid) => { if (valid) { let url = this.dataForm.id ? '/term/updateTerm' : '/term/addTerm' if (this.dataForm.id == '') { this.isDisabled = true; } this.dataForm.id = this.dataForm.id || undefined; console.log(this.dataForm); } }) }, }, } </script> CSS <style> .applicaWord .el-upload-list__item .el-icon-close-tip { display: none !important; } .treeDiv { position: absolute; top: 52px; left: -1px; z-index: 1000; width: 100%; overflow:auto; max-height: 280px; /* border: 1px solid #ccc; */ border-radius: 6px; background: #FFFFFF; } .treeDiv::-webkit-scrollbar { /*Overall scroll bar style*/ width: 4px; /*Height and width correspond to the size of the horizontal and vertical scroll bars respectively*/ height: 4px; } .treeDiv::-webkit-scrollbar-thumb { /*Small square inside the scroll bar*/ border-radius: 5px; -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); background: rgba(0, 0, 0, 0.2); } .treeDiv::-webkit-scrollbar-track { /*Scroll bar track*/ -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); border-radius: 0; background: rgba(0, 0, 0, 0.1); } .treeDiv .el-table { font-size: 14px; } .treeDiv .el-table /deep/ td { padding: 4px 0; } #selectTable .el-select { width: 100%; } #selectTable .el-input { width: 100%; } #kuan .el-form-item__content { width: 80%; } </style> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Sample code for cool breathing effect using CSS3+JavaScript
>>: Detailed explanation of HTML body tag and commonly used control tags in HTML
Table of contents Preface toDoList just do it Pre...
Preface <br />I have been working in the fro...
The steps are as follows 1. Create a docker group...
I won't go into details about how important b...
By turning on the Recycle Bin function, you can r...
1. Time difference functions (TIMESTAMPDIFF, DATE...
I accidentally discovered a great artificial inte...
This article will introduce a very interesting at...
Flexible layout (Flexbox) is becoming increasingl...
Application nesting of unordered lists Copy code T...
01. Infinity Font Download 02. Banda Font Download...
Table of contents 1. Concurrent access control 2....
I have been studying and reviewing the developmen...
This article shares the specific code of JavaScri...