I'm having templates in the header of primeNg DataTable.
- Custom DateRange Filter (child) component
- Dropdown to list activities
- Regular column
- Regular template column
I've a Global Filter Reset button, on which all filters has to be reset. dataTable.reset()
method is resetting regular column (#3) and regular template custom (#4), but NOT other header controls (#1, #2).
I tried to invoke childComponent.Reset()
using @ViewChild
option, but I'm getting the childComponent
as "undefined"
on runtime. I could see @ViewChild
option is working for regular child controls outside the dataTable.
How can I reset all controls in the primeNg DataTable in the right way?
<p-column field="updatedOn" header="Updated On" sortable="custom" (sortFunction)="dateSort($event)" [style]="{'width':'180px'}" filter="true" filterMatchMode="contains">
<template pTemplate="filter" let-col>
<date-range-filter #dateRangeFilter (dateRangeUpdated)="onRangeUpdated($event)"></date-range-filter>
</template>
<template let-col let-val="rowData" pTemplate="body">
<div class="bodyText">
{{val[col.field] | date: 'MM/dd/yyyy hh:mm a'}}
</div>
</template>
</p-column>
<p-column field="activity" header="Activity" sortable="true" filter="true" filterMatchMode="equals" [style]="{'width':'100px', 'overflow':'visible'}">
<template pTemplate="filter" let-col>
<p-dropdown #activityType appendTo="body" [options]="_activityList" [style]="{'width':'100%'}" (onChange)="memoTable.filter($event.value,col.field,col.filterMatchMode)"
styleClass="ui-column-filter"></p-dropdown>
</template>
<template let-col let-val="rowData" pTemplate="body">
<span class="ActivityBox" [ngClass]="getActivityColor(val[col.field])">{{getActivityType(val[col.field])}}</span>
</template>
</p-column>
<p-column field="User" header="User" sortable="true" filter="true" filterMatchMode="contains" [style]="{'width':'95px'}"></p-column>
<p-column field="comment" header="comment" sortable="true" filter="true" filterMatchMode="contains">
<template let-col let-val="rowData" pTemplate="body">
<div>
<div class="NotesColumn" [ngClass]="val[col.field].length > 15? 'underlined' : ''" (mouseenter)="op.show($event)" (mouseleave)="op.hide($event)">
{{val[col.field]}}
</div>
<p-overlayPanel #op [styleClass]="overlayDiv" [appendTo]="overlayTarget">
<div class="overlayDiv">
{{val[col.field]}}
</div>
</p-overlayPanel>
</div>
</template>
</p-column>
[(ngModel)]="_selectedActivityType"
to capture the selected value. 2: Reset_selectedActivityType
to default value from the activityList - 'this._selectedActivityType = this._activityList[0]'. The issue still persists on custom control. I believe the component is not getting rendered during the globalFilterClear event which results in errorCannot read property 'clearDates' of undefined
.clearDates()
is custom component public method. – Shyam Sailendran