Hello,
I'm using datatable component V3 and it working very well. However, to bring more dynamic I'd like to bring the "filters" variable from my Webservice. It's possible?
Look at the code below, I'll explain better my needs:
<Datatable>
...
<Column v-for="col of columns" :field="col.field" :header="col.header" :key="col.field" :sortable="col.sortable" :showFilterOperator="col.showFilterOperator" :showFilterMenu="col.showFilterMenu" >
<template #filter="{ filterModel }">
<InputText v-if="col.input"
type="text"
v-model="filterModel.value"
class="p-column-filter"
placeholder="Pesquise aqui"
/>
<Calendar v-if="col.calendar"
v-model="filterModel.value"
dateFormat="dd/mm/yy"
placeholder="dd/mm/yyyy"
/>
</template>
</Column>
</Datatable>
This code provides a dynamic column generation. The problem is the filterModel.
The filterModel demands a declared variable called filters, that means, it needs to be fixed in the code for each column that was automatically generated:
filters: {
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
name_each_column: {
operator: FilterOperator.AND,
constraints: [
{ value: null, matchMode: FilterMatchMode.STARTS_WITH },
],
I'd like to generated filters columns automatically such as I did with <Column v-for="col of columns" .
It is possible?
I tried bringing it from the JSON variable, but I took several errors when I filled it programmatically.
thank you for any help.
DataTable - Creating dynamically filters
-
- Posts: 8
- Joined: 10 Mar 2021, 21:50
I finally solved the problem
I was creating the variable with FilterMatchMode.CONTAINS constant value.
When I created the filters with the content of the constant value ("contains") the problem was solved.
I was creating the variable with FilterMatchMode.CONTAINS constant value.
When I created the filters with the content of the constant value ("contains") the problem was solved.