1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 12:01:57 +08:00

Fast filtering in the tables (#885)

* Filter on tables by columns marked as isSelectionColumn

* remove unnecessary code

* Search Table Children

* minimal chages

Co-authored-by: elsiosanchez <elsiossanches@gmail.com>
This commit is contained in:
Elsio Sanchez 2021-05-28 17:55:38 -04:00 committed by GitHub
parent 615aeacd99
commit ffd495501b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 16 deletions

View File

@ -73,13 +73,17 @@ export default {
currentTable: 0, currentTable: 0,
visible: this.getShowContextMenuTable, visible: this.getShowContextMenuTable,
searchTable: '', // text from search searchTable: '', // text from search
searchTableChildren: '', // text from search
defaultMaxPagination: 50, defaultMaxPagination: 50,
activeName, activeName,
rowStyle: { rowStyle: {
height: '52px' height: '52px'
}, },
uuidCurrentRecordSelected: '', uuidCurrentRecordSelected: '',
showTableSearch: false showTableSearch: false,
searchColumnName: [],
recordsSearchTable: [],
recordsSearchTableChildren: []
} }
}, },
computed: { computed: {
@ -257,6 +261,15 @@ export default {
return this.currentTable return this.currentTable
} }
return this.currentTable + 1 return this.currentTable + 1
},
allRecordsData() {
if (this.isParent && !this.isEmptyValue(this.searchTable)) {
return this.recordsSearchTable
} else if (!this.isParent && !this.isEmptyValue(this.searchTableChildren)) {
return this.recordsSearchTableChildren
}
return this.recordsData
} }
}, },
watch: { watch: {
@ -631,21 +644,37 @@ export default {
selection: rowsSelection selection: rowsSelection
}) })
}, },
filterResult() { filterResult(value) {
const data = this.recordsData.filter(rowItem => { const selectionColumn = this.fieldsList.filter(element => element.isSelectionColumn)
if (this.searchTable.trim().length) { this.searchColumnName = selectionColumn.map(element => {
let find = false if (element.isSelectionColumn) {
Object.keys(rowItem).forEach(key => { return element.columnName
if (String(rowItem[key]).toLowerCase().includes(String(this.searchTable).toLowerCase())) {
find = true
return find
}
})
return find
} }
return true
}) })
return data if (this.isParent) {
this.searchTable = value
} else {
this.searchTableChildren = value
}
const result = this.getterDataRecordsAndSelection.record.filter(record => {
let list
this.searchColumnName.forEach(validate => {
if (typeof record[validate] !== 'boolean' && !this.isEmptyValue(record[validate]) || !this.isEmptyValue(record['DisplayColumn_' + validate])) {
const SearchColumns = typeof record[validate] === 'number' ? record['DisplayColumn_' + validate] : record[validate]
if (SearchColumns.includes(value)) {
list = record
}
}
})
return list
})
if (this.isParent) {
this.searchTable = value
this.recordsSearchTable = result
} else {
this.searchTableChildren = value
this.recordsSearchTableChildren = result
}
}, },
/** /**
* Verify is displayed field in column table * Verify is displayed field in column table

View File

@ -84,6 +84,7 @@
size="mini" size="mini"
:placeholder="$t('table.dataTable.search')" :placeholder="$t('table.dataTable.search')"
class="header-search-input" class="header-search-input"
@input="filterResult"
/> />
</div> </div>
</div> </div>
@ -138,7 +139,6 @@
:is-mobile="isMobile" :is-mobile="isMobile"
:panel-metadata="panelMetadata" :panel-metadata="panelMetadata"
/> />
<el-table <el-table
ref="multipleTable" ref="multipleTable"
v-loading="!isCreateNewRoute && isLoaded" v-loading="!isCreateNewRoute && isLoaded"
@ -149,7 +149,7 @@
reserve-selection reserve-selection
highlight-current-row highlight-current-row
:row-style="rowStyle" :row-style="rowStyle"
:data="showTableSearch ? filterResult() : recordsData" :data="allRecordsData"
:element-loading-text="$t('notifications.loading')" :element-loading-text="$t('notifications.loading')"
element-loading-background="rgba(255, 255, 255, 0.8)" element-loading-background="rgba(255, 255, 255, 0.8)"
cell-class-name="datatable-max-cell-height" cell-class-name="datatable-max-cell-height"