nx-primeng-sakai-v17/src/app/demo/view/listdemo.component.ts

67 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-12-09 14:24:42 +00:00
import {Component, OnInit} from '@angular/core';
import {SelectItem} from 'primeng/api';
import {Product} from '../domain/product';
import {ProductService} from '../service/productservice';
@Component({
templateUrl: './listdemo.component.html',
})
export class ListDemoComponent implements OnInit {
products: Product[];
sortOptions: SelectItem[];
sortOrder: number;
sortField: string;
sourceCities: any[];
targetCities: any[];
orderCities: any[];
constructor(private productService: ProductService) {}
ngOnInit() {
this.productService.getProducts().then(data => this.products = data);
this.sourceCities = [
{name: 'San Francisco', code: 'SF'},
{name: 'London', code: 'LDN'},
{name: 'Paris', code: 'PRS'},
{name: 'Istanbul', code: 'IST'},
{name: 'Berlin', code: 'BRL'},
{name: 'Barcelona', code: 'BRC'},
{name: 'Rome', code: 'RM'}];
this.targetCities = [];
this.orderCities = [
{name: 'San Francisco', code: 'SF'},
{name: 'London', code: 'LDN'},
{name: 'Paris', code: 'PRS'},
{name: 'Istanbul', code: 'IST'},
{name: 'Berlin', code: 'BRL'},
{name: 'Barcelona', code: 'BRC'},
{name: 'Rome', code: 'RM'}];
this.sortOptions = [
{label: 'Price High to Low', value: '!price'},
{label: 'Price Low to High', value: 'price'}
];
}
onSortChange(event) {
const value = event.value;
if (value.indexOf('!') === 0) {
this.sortOrder = -1;
this.sortField = value.substring(1, value.length);
} else {
this.sortOrder = 1;
this.sortField = value;
}
}
}