-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue-grid): add the Advanced filtering feature (#1186)
- Loading branch information
1 parent
c19907f
commit b5a468c
Showing
26 changed files
with
932 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
packages/dx-vue-demos/src/demo-sources/grid-filtering/none/advanced-filter-row.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { | ||
DxDataTypeProvider, | ||
DxFilteringState, | ||
DxIntegratedFiltering, | ||
} from '@devexpress/dx-vue-grid'; | ||
import { | ||
DxGrid, | ||
DxTable, | ||
DxTableHeaderRow, | ||
DxTableFilterRow, | ||
} from '@devexpress/dx-vue-grid-bootstrap4'; | ||
|
||
import { | ||
generateRows, | ||
globalSalesValues, | ||
} from '../../../demo-data/generator'; | ||
|
||
const MyDateFilterCell = { | ||
template: ` | ||
<span class="d-block oi oi-calendar" /> | ||
`, | ||
}; | ||
|
||
const FilterIcon = { | ||
props: ['type'], | ||
computed: { | ||
componentId() { | ||
return this.type === 'month' ? 'my-date-filter-cell' : 'dx-icon'; | ||
}, | ||
}, | ||
template: ` | ||
<component | ||
:is="componentId" | ||
v-bind="$attrs" | ||
v-on="$listeners" | ||
:type="type" | ||
/> | ||
`, | ||
components: { | ||
DxIcon: DxTableFilterRow.components.DxIcon, | ||
MyDateFilterCell, | ||
}, | ||
}; | ||
|
||
const CurrencyFormatter = { | ||
props: ['value'], | ||
template: ` | ||
<b style="color: darkblue">\${{ value }}</b> | ||
`, | ||
}; | ||
|
||
const CurrencyTypeProvider = { | ||
template: ` | ||
<dx-data-type-provider | ||
:formatterComponent="$options.components.CurrencyFormatter" | ||
:availableFilterOperations="$attrs.availableFilterOperations" | ||
:for="$attrs.for" | ||
/> | ||
`, | ||
components: { | ||
DxDataTypeProvider, | ||
CurrencyFormatter, | ||
}, | ||
}; | ||
|
||
const DateFormatter = { | ||
props: ['value'], | ||
template: ` | ||
<span>{{ value.replace(/(\\d{4})-(\\d{2})-(\\d{2})/, '$3.$2.$1') }}</span> | ||
`, | ||
}; | ||
|
||
const DateTypeProvider = { | ||
template: ` | ||
<dx-data-type-provider | ||
:formatterComponent="$options.components.DateFormatter" | ||
:availableFilterOperations="$attrs.availableFilterOperations" | ||
:for="$attrs.for" | ||
/> | ||
`, | ||
components: { | ||
DxDataTypeProvider, | ||
DateFormatter, | ||
}, | ||
}; | ||
|
||
export default { | ||
data() { | ||
return { | ||
columns: [ | ||
{ name: 'customer', title: 'Customer' }, | ||
{ name: 'product', title: 'Product' }, | ||
{ name: 'saleDate', title: 'Sale Date' }, | ||
{ name: 'amount', title: 'Sale Amount' }, | ||
], | ||
rows: generateRows({ columnValues: globalSalesValues, length: 8 }), | ||
tableColumnExtensions: [ | ||
{ columnName: 'amount', align: 'right' }, | ||
], | ||
filters: [], | ||
dateColumns: ['saleDate'], | ||
currencyColumns: ['amount'], | ||
dateFilterOperations: ['month', 'contains', 'startsWith', 'endsWith'], | ||
currencyFilterOperations: ['equal', 'notEqual', 'greaterThan', 'greaterThanOrEqual', 'lessThan', 'lessThanOrEqual'], | ||
filteringColumnExtensions: [ | ||
{ | ||
columnName: 'saleDate', | ||
predicate: (value, filter, row) => { | ||
if (!filter.value.length) return true; | ||
if (filter && filter.operation === 'month') { | ||
const month = parseInt(value.split('-')[1], 10); | ||
return month === parseInt(filter.value, 10); | ||
} | ||
return DxIntegratedFiltering.defaultPredicate(value, filter, row); | ||
}, | ||
}, | ||
], | ||
filterMessages: { month: 'Month equals' }, | ||
}; | ||
}, | ||
template: ` | ||
<div class="card"> | ||
<dx-grid | ||
:rows="rows" | ||
:columns="columns" | ||
> | ||
<currency-type-provider | ||
:for="currencyColumns" | ||
:availableFilterOperations="currencyFilterOperations" | ||
/> | ||
<date-type-provider | ||
:for="dateColumns" | ||
:availableFilterOperations="dateFilterOperations" | ||
/> | ||
<dx-filtering-state | ||
:filters.sync="filters" | ||
/> | ||
<dx-integrated-filtering | ||
:columnExtensions="filteringColumnExtensions" | ||
/> | ||
<dx-table | ||
:columnExtensions="tableColumnExtensions" | ||
/> | ||
<dx-table-filter-row | ||
showFilterSelector | ||
:iconComponent="$options.components.FilterIcon" | ||
:messages="filterMessages" | ||
/> | ||
<dx-table-header-row /> | ||
</dx-grid> | ||
</div> | ||
`, | ||
components: { | ||
DxGrid, | ||
DxTable, | ||
DxTableHeaderRow, | ||
CurrencyTypeProvider, | ||
DateTypeProvider, | ||
DxFilteringState, | ||
DxIntegratedFiltering, | ||
DxTableFilterRow, | ||
FilterIcon, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 30 additions & 1 deletion
31
packages/dx-vue-grid-bootstrap4/src/plugins/table-filter-row.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
import { DxTableFilterRow as DxTableFilterRowBase } from '@devexpress/dx-vue-grid'; | ||
import { TableFilterCell } from '../templates/table-filter-cell'; | ||
import { TableRow } from '../templates/table-row'; | ||
import { Editor } from '../templates/filter-row/editor'; | ||
import { FilterSelector } from '../templates/filter-row/filter-selector'; | ||
import { Icon } from '../templates/filter-row/icon'; | ||
|
||
const defaultMessages = { | ||
filterPlaceholder: 'Filter...', | ||
contains: 'Contains', | ||
notContains: 'Does not contain', | ||
startsWith: 'Starts with', | ||
endsWith: 'Ends with', | ||
equal: 'Equals', | ||
notEqual: 'Does not equal', | ||
greaterThan: 'Greater than', | ||
greaterThanOrEqual: 'Greater than or equal to', | ||
lessThan: 'Less than', | ||
lessThanOrEqual: 'Less than or equal to', | ||
}; | ||
|
||
export const DxTableFilterRow = { | ||
name: 'DxTableFilterRow', | ||
functional: true, | ||
props: { | ||
messages: { | ||
type: Object, | ||
}, | ||
}, | ||
render(h, context) { | ||
return ( | ||
<DxTableFilterRowBase | ||
cellComponent={TableFilterCell} | ||
rowComponent={TableRow} | ||
{...{ attrs: context.props, on: context.listeners }} | ||
filterSelectorComponent={FilterSelector} | ||
iconComponent={Icon} | ||
editorComponent={Editor} | ||
messages={{ ...defaultMessages, ...context.props.messages }} | ||
{...{ attrs: context.data.attrs, on: context.listeners }} | ||
/> | ||
); | ||
}, | ||
components: { | ||
DxCell: TableFilterCell, | ||
DxRow: TableRow, | ||
DxEditor: Editor, | ||
DxFilterSelector: FilterSelector, | ||
DxIcon: Icon, | ||
}, | ||
}; |
42 changes: 42 additions & 0 deletions
42
packages/dx-vue-grid-bootstrap4/src/templates/filter-row/editor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export const Editor = { | ||
name: 'Editor', | ||
inheritAttrs: false, | ||
props: { | ||
value: { | ||
type: [Number, String], | ||
default: '', | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
getMessage: { | ||
type: Function, | ||
required: true, | ||
}, | ||
}, | ||
methods: { | ||
handleChange(e) { | ||
this.$emit('changeValue', e.target.value); | ||
}, | ||
}, | ||
render() { | ||
const { | ||
value, | ||
disabled, | ||
getMessage, | ||
} = this; | ||
|
||
return ( | ||
<input | ||
{...{ attrs: { ...this.$attrs }, on: { ...this.$listeners } }} | ||
type="text" | ||
class="form-control" | ||
value={value} | ||
onInput={this.handleChange} | ||
readOnly={disabled} | ||
placeholder={getMessage('filterPlaceholder')} | ||
/> | ||
); | ||
}, | ||
}; |
Oops, something went wrong.