Hi,
I am trying add a dropdown as filter in the column template. Using this I managed to do it but I doesn't apply the filter to the grid. The Plunker doesn't work due to 'Access-Control-Allow-Origin' problem so I can't see any live example. The dropbownlist is shown and the value returns correctly but nothing happens in the grid. I've added field parameter since the fieldName and valueField is not the same. I've recognized that the filter is always undefined.
My HTML:
<
kendo-grid-column
field
=
"sSY90Falttyp"
title
=
"Fälttyp"
width
=
"160px"
>
<
ng-template
kendoGridFilterCellTemplate let-filter>
<
my-dropdown-filter
[filter]="filter" [data]="fieldTypes"
textField
=
"text"
valueField
=
"value"
field
=
"sSY90Falttyp"
>
</
my-dropdown-filter
>
</
ng-template
>
<
ng-template
kendoGridCellTemplate let-dataItem>
{{getFieldTypeText(dataItem.sSY90Falttyp)}}
</
ng-template
>
</
kendo-grid-column
>
DropdownlistFilterComponent:
import { Component, OnInit, Input } from
'@angular/core'
;
import { CompositeFilterDescriptor, FilterDescriptor } from
'@progress/kendo-data-query'
;
import { FilterService, BaseFilterCellComponent } from
'@progress/kendo-angular-grid'
;
@Component({
selector:
'my-dropdown-filter'
,
templateUrl:
'./dropdownlist-filter.component.html'
,
styleUrls: [
'./dropdownlist-filter.component.scss'
]
})
export class DropdownlistFilterComponent extends BaseFilterCellComponent {
public get selectedValue(): any {
const filter =
this
.filterByField(
this
.field);
return
filter ? filter.value :
null
;
}
@Input() public filter = <CompositeFilterDescriptor>
null
;
@Input() public data: any[];
@Input() public textField: string;
@Input() public valueField: string;
@Input() public field: string;
public get defaultItem(): any {
return
{
[
this
.textField]:
"Select item..."
,
[
this
.valueField]:
null
};
}
constructor(filterService: FilterService) {
super
(filterService);
}
public onChange(value: any): void {
this
.applyFilter(
value ===
null
?
// value of the default item
this
.removeFilter(
this
.valueField) :
// remove the filter
this
.updateFilter({
// add a filter for the field with the value
field:
this
.field,
operator:
"eq"
,
value: value
})
);
// update the root filter
}
}