import { Component } from
'@angular/core'
;
import { SelectItem, FilterService,
FilterMatchMode } from
'primeng/api'
;
@Component({
selector:
'app-root'
,
templateUrl:
'./app.component.html'
,
})
export class AppComponent {
cols: any[];
tutorials: Tutorial[];
matchModeOptions: SelectItem[];
constructor(private filterService: FilterService) { }
ngOnInit() {
this
.tutorials = [
{
title:
'Queue'
,
category:
'Data Structure'
,
rating: 8,
},
{
title:
'Circularly LinkedList'
,
category:
'Data Structure'
,
rating: 1,
},
{
title:
'Doubly LinkedList'
,
category:
'Data Structure'
,
rating: 3,
},
{
title:
'Singly LinkedList'
,
category:
'Data Structure'
,
rating: 5,
},
{
title:
'Doubly Ended Queue'
,
category:
'Data Structure'
,
rating: 10,
},
{
title:
'Binary Search Tree'
,
category:
'Data Structure'
,
rating: 2,
},
{
title:
'Red Black Tree'
,
category:
'Data Structure'
,
rating: 9,
},
{
title:
'Breadth First Search'
,
category:
'Graph'
,
rating: 6,
},
{
title:
"Floyd's Cycle"
,
category: 'Algorithm
',
rating: 7,
},
{
title: '
Travelling Salesman Problem
',
category: '
Algorithm
',
rating: 4,
},
{
title: '
Bellman Ford
',
category: '
Graph
',
rating: 8,
},
{
title: '
KMP Algorithm
',
category: '
String
',
rating: 10,
},
];
this.cols = [
{ field: '
title
', header: '
Title
' },
{ field: '
category
', header: '
Category
' },
{ field: '
rating
', header: '
Rating
' },
];
const customFilterName = '
custom-equals
';
this.filterService.register(customFilterName,
(value, filter): boolean => {
if (filter === undefined || filter === null
|| filter.trim() === '
') {
return true;
}
if (value === undefined || value === null) {
return false;
}
return value % 2 === 1;
});
this.matchModeOptions = [
{ label: '
Custom Equals
',
value: customFilterName },
{ label: '
Starts With
',
value: FilterMatchMode.STARTS_WITH },
{ label: '
Contains',
value: FilterMatchMode.CONTAINS },
];
}
}
export interface Tutorial {
title?: string;
category?: string;
rating?: number;
}