From 5319c59d010cc38d6a79f02529dd4c9ff610ced1 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Fri, 14 May 2021 18:50:45 +0300 Subject: [PATCH] Fixed #1105 - Filter Event for Lazy Loading --- src/components/datatable/DataTable.vue | 17 ++---- src/views/datatable/DataTableDoc.vue | 68 ++--------------------- src/views/datatable/DataTableLazyDemo.vue | 21 +------ 3 files changed, 14 insertions(+), 92 deletions(-) diff --git a/src/components/datatable/DataTable.vue b/src/components/datatable/DataTable.vue index a44c3611e..31491f35d 100755 --- a/src/components/datatable/DataTable.vue +++ b/src/components/datatable/DataTable.vue @@ -1544,16 +1544,6 @@ export default { this.$emit('row-edit-cancel', event); }, createLazyLoadEvent(event) { - let filterMatchModes; - if (this.hasFilters) { - filterMatchModes = {}; - this.columns.forEach(col => { - if (col.field) { - filterMatchModes[col.field] = col.filterMatchMode; - } - }); - } - return { originalEvent: event, first: this.d_first, @@ -1561,8 +1551,7 @@ export default { sortField: this.d_sortField, sortOrder: this.d_sortOrder, multiSortMeta: this.d_multiSortMeta, - filters: this.filters, - filterMatchModes: filterMatchModes + filters: this.d_filters }; }, hasGlobalFilter() { @@ -1578,6 +1567,10 @@ export default { this.d_first = 0; this.$emit('update:first', this.d_first); this.$emit('update:filters', this.d_filters); + + if (this.lazy) { + this.$emit('filter', this.createLazyLoadEvent()); + } }, cloneFilters() { let cloned = {}; diff --git a/src/views/datatable/DataTableDoc.vue b/src/views/datatable/DataTableDoc.vue index c895fbd72..f522cb599 100755 --- a/src/views/datatable/DataTableDoc.vue +++ b/src/views/datatable/DataTableDoc.vue @@ -1030,68 +1030,13 @@ matchModes: [ data are still displayed. No additional configuration is required to enable this feature. View the Row Grouğ demo for an example.

Lazy Loading
-

Lazy mode is handy to deal with large datasets, instead of loading the entire data, small chunks of data is loaded by invoking corresponding callbacks such as paging and sorting. Sample belows imitates lazy paging by using an in memory list. - It is also important to assign the logical number of rows to totalRecords by doing a projection query for paginator configuration so that paginator displays the UI - assuming there are actually records of totalRecords size although in reality they aren't as in lazy mode, only the records that are displayed on the current page exist.

+

Lazy mode is handy to deal with large datasets, instead of loading the entire data, small chunks of data is loaded by invoking corresponding callbacks such as paging and sorting. + It is also important to assign the logical number of rows to totalRecords by doing a projection query for paginator configuration so that paginator displays the UI accordingly.

-

Lazy loading is implemented by handling pagination and sorting using page and sort events by making a remote query using the information - passed to the events such as first offset, number of rows and sort field for ordering. Filtering is handled differently as filter elements are defined using templates. filter event is not triggered in - lazy mode instead use the event you prefer on your form elements such as input, change, blur to make a remote call by passing the filters property to update the displayed data. Note that, - in lazy filtering, totalRecords should also be updated to align the data with the paginator.

+

Lazy loading is implemented by handling page, sort, filter events by making a remote query using the information + passed to these events such as first offset, number of rows, sort field for ordering and filters. Note that, in lazy filtering totalRecords should also be updated to align the data with the paginator.

-

Here is a sample paging implementation with in memory data, a more enhanced example with a backend is being worked on and will be available at a github repository.

-

-
- -

-import CarService from '../../service/CarService';
-
-export default {
-    data() {
-        return {
-            loading: false,
-            totalRecords: 0,
-            cars: null
-        }
-    },
-    datasource: null,
-    carService: null,
-    created() {
-        this.carService = new CarService();
-    },
-    mounted() {
-        this.loading = true;
-
-        setTimeout(() => {
-            this.carService.getCarsLarge().then(data => {
-                this.datasource = data;
-                this.totalRecords = data.length,
-                this.cars = this.datasource.slice(0, 10);
-                this.loading = false;
-            });
-        }, 1000);
-    },
-    methods: {
-        onPage(event) {
-            this.loading = true;
-
-            setTimeout(() => {
-                this.cars = this.datasource.slice(event.first, event.first + event.rows);
-                this.loading = false;
-            }, 1000);
-        }
-    }
-}
-
-
+

Visit the lazy loading demo for an example with a remote datasource.

Row Expansion

Rows can be expanded to display additional content using the expandedRows property with the v-model directive accompanied by a template named "expansion". row-expand and row-collapse are optional callbacks that are invoked when a row is expanded or toggled.

@@ -2285,8 +2230,7 @@ export default { event.sortOrder: Sort order as integer
event.multiSortMeta: MultiSort metadata
event.filters: Collection of active filters
- event.filteredValue: Filtered collection
- event.filterMatchModes: Match modes per field + event.filteredValue: Filtered collection (non-lazy only)
Event to emit after filtering, not triggered in lazy mode. diff --git a/src/views/datatable/DataTableLazyDemo.vue b/src/views/datatable/DataTableLazyDemo.vue index 150e572f4..52dd8b3da 100755 --- a/src/views/datatable/DataTableLazyDemo.vue +++ b/src/views/datatable/DataTableLazyDemo.vue @@ -14,7 +14,7 @@