DataTable - Creating dynamically filters

UI Components for Vue
Post Reply
Dicipulofer
Posts: 8
Joined: 10 Mar 2021, 21:50

10 Apr 2021, 17:08

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.

Dicipulofer
Posts: 8
Joined: 10 Mar 2021, 21:50

14 Apr 2021, 14:38

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.

tugce.kucukoglu
Posts: 121
Joined: 23 Oct 2020, 09:28

11 Jun 2021, 16:36

Thanks for the feedback.

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests