Fixed #1061 - Add filters to lazy loading demo

pull/1073/head
Yiğit FINDIKLI 2021-03-10 16:59:36 +03:00
parent d9c831fa1e
commit 3740f71343
1 changed files with 16 additions and 10 deletions

View File

@ -12,26 +12,27 @@
<div class="content-section implementation"> <div class="content-section implementation">
<div class="card"> <div class="card">
<DataTable :value="customers" :lazy="true" :paginator="true" :rows="10" :filters="filters" ref="dt" <DataTable :value="customers" :lazy="true" :paginator="true" :rows="10" v-model:filters="filters" ref="dt"
:totalRecords="totalRecords" :loading="loading" @page="onPage($event)" @sort="onSort($event)"> :totalRecords="totalRecords" :loading="loading" @page="onPage($event)" @sort="onSort($event)" filterDisplay="row"
:globalFilterFields="['name','country.name', 'company', 'representative.name']">
<Column field="name" header="Name" filterMatchMode="startsWith" ref="name" :sortable="true"> <Column field="name" header="Name" filterMatchMode="startsWith" ref="name" :sortable="true">
<template #filter> <template #filter="{filterModel,filterCallback}">
<InputText type="text" v-model="filters['name']['value']" @keydown.enter="onFilter($event)" class="p-column-filter" placeholder="Search by name"/> <InputText type="text" v-model="filterModel.value" @keydown.enter="filterCallback()" class="p-column-filter" placeholder="Search by name"/>
</template> </template>
</Column> </Column>
<Column field="country.name" header="Country" filterField="country.name" filterMatchMode="contains" ref="country.name" :sortable="true"> <Column field="country.name" header="Country" filterField="country.name" filterMatchMode="contains" ref="country.name" :sortable="true">
<template #filter> <template #filter="{filterModel,filterCallback}">
<InputText type="text" v-model="filters['country.name']['value']" @keydown.enter="onFilter($event)" class="p-column-filter" placeholder="Search by country"/> <InputText type="text" v-model="filterModel.value" @keydown.enter="filterCallback()" class="p-column-filter" placeholder="Search by country"/>
</template> </template>
</Column> </Column>
<Column field="company" header="Company" filterMatchMode="contains" ref="company" :sortable="true"> <Column field="company" header="Company" filterMatchMode="contains" ref="company" :sortable="true">
<template #filter> <template #filter="{filterModel,filterCallback}">
<InputText type="text" v-model="filters['company']['value']" @keydown.enter="onFilter($event)" class="p-column-filter" placeholder="Search by company"/> <InputText type="text" v-model="filterModel.value" @keydown.enter="filterCallback()" class="p-column-filter" placeholder="Search by company"/>
</template> </template>
</Column> </Column>
<Column field="representative.name" header="Representative" filterField="representative.name" ref="representative.name" :sortable="true"> <Column field="representative.name" header="Representative" filterField="representative.name" ref="representative.name" :sortable="true">
<template #filter> <template #filter="{filterModel,filterCallback}">
<InputText type="text" v-model="filters['representative.name']['value']" @keydown.enter="onFilter($event)" class="p-column-filter" placeholder="Search by representative"/> <InputText type="text" v-model="filterModel.value" @keydown.enter="filterCallback()" class="p-column-filter" placeholder="Search by representative"/>
</template> </template>
</Column> </Column>
</DataTable> </DataTable>
@ -154,6 +155,11 @@ import CustomerService from '../../service/CustomerService';
import LiveEditor from '../liveeditor/LiveEditor'; import LiveEditor from '../liveeditor/LiveEditor';
export default { export default {
watch: {
filters() {
this.onFilter();
}
},
data() { data() {
return { return {
loading: false, loading: false,