diff --git a/src/components/column/Column.d.ts b/src/components/column/Column.d.ts index 56428fd39..702ff610b 100644 --- a/src/components/column/Column.d.ts +++ b/src/components/column/Column.d.ts @@ -14,6 +14,7 @@ export declare class Column extends Vue { footerStyle?: object; footerClass?: string; filterMatchMode?: string; + filterFunction?: Function; excludeGlobalFilter?: boolean; selectionMode?: string; expander?: boolean; diff --git a/src/components/column/Column.vue b/src/components/column/Column.vue index 15f3458c8..10f048246 100644 --- a/src/components/column/Column.vue +++ b/src/components/column/Column.vue @@ -54,6 +54,10 @@ export default { type: String, default: 'startsWith' }, + filterFunction: { + type: Function, + default: null + }, excludeGlobalFilter: { type: Boolean, default: false diff --git a/src/components/datatable/DataTable.vue b/src/components/datatable/DataTable.vue index 5c65c33e3..08f2fd7c3 100644 --- a/src/components/datatable/DataTable.vue +++ b/src/components/datatable/DataTable.vue @@ -577,8 +577,7 @@ export default { if (Object.prototype.hasOwnProperty.call(this.filters, columnField)) { let filterValue = this.filters[columnField]; let dataFieldValue = ObjectUtils.resolveFieldData(data[i], columnField); - let filterConstraint = FilterUtils[col.filterMatchMode]; - + let filterConstraint = col.filterMatchMode === 'custom' ? col.filterFunction : FilterUtils[col.filterMatchMode]; if (!filterConstraint(dataFieldValue, filterValue)) { localMatch = false; } diff --git a/src/views/datatable/DataTableDoc.vue b/src/views/datatable/DataTableDoc.vue index 15a8ec2ae..6cbe20af6 100644 --- a/src/views/datatable/DataTableDoc.vue +++ b/src/views/datatable/DataTableDoc.vue @@ -208,6 +208,14 @@ export default {
Filtering is enabled by defining a filter template per column to populate the filters property of the DataTable. The filters property should be an key-value object where keys are the field name and the value is the filter value. The filter template receives the column properties via the slotProps and accepts any form element as the filter element. Default match mode is "startsWith" and this can be configured per column using the filterMatchMode property that also accepts - "contains", "endsWith", "equals", "notEquals" and "in" as available modes.
+ "contains", "endsWith", "equals", "notEquals", "in" and "custom" as available modes.Optionally a global filter is available to search against all the fields, in this case the special global keyword should be the property to be populated.
Custom filtering is implemented by setting the filterMatchMode to "custom" and defining a filter function.
+