import { DataSource } from '@angular/cdk/collections'; import { Observable } from 'rxjs'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { RequestParameterInterface } from './request-parameter.interface'; import { TerraFilter } from './filter'; import { TerraPagerInterface } from '../pager/data/terra-pager.interface'; /** * @experimental * * A custom implementation of angular cdk's data source that * simplifies connection of table to a plentymarkets rest api. * Can be used with any combination of paging, sorting and filtering functionality. * To enable paging, sorting and/or filtering just pass the respective class/component to this data source. * * MyFilterData is optional. To simplify the access of filter parameters. * * @example * ```typescript * class MyDataSource extends TerraTableDataSource * { * constructor(private service:MyDataService) {} * * public request():Observable | TerraPagerInterface> { * return this.service.getData(); * } * } * * @Component({ * template: ` * * ...
* ` * }) * class MyComponent implements OnInit * { * public dataSource:MyDataSource = new MyDataSource(this.service); * public filter:TerraFilter = new TerraFilter(); * @ViewChild(MatPaginator, {static: true}) * public paginator:MatPaginator; * @ViewChild(MatSort, {static: true}) * public sort:MatSort; * * constructor(private service:MyDataService) {} * * ngOnInit() { * this.dataSource.sort = this.sort; // enable sorting * this.dataSource.paginator = this.paginator; // enable paging * this.dataSource.filter = this.filter; // enable filtering * this.dataSource.search(); // trigger an initial search * } * } * ``` */ export declare abstract class TerraTableDataSource extends DataSource { /** Snapshot of the currently displayed data. */ get data(): Array; set data(data: Array); private _data; /** Instance of the TerraFilter class used to narrow results. */ get filter(): TerraFilter; set filter(f: TerraFilter); private _filter; /** * Instance of the MatSort directive used by the table to control its sorting. * Sort changes emitted by the MatSort will trigger an update to the table's rendered data. */ get sort(): MatSort; set sort(s: MatSort); private _sort; /** * Instance of the MatPaginator component used by the table to control what page and * how many items of the data are displayed. * Page changes emitted by the MatPaginator will trigger an update to the table's rendered data. */ get paginator(): MatPaginator; set paginator(p: MatPaginator); private _paginator; /** A stream that emits whenever data has been requested from the server. */ dataRequested$: Observable; private _dataRequested$; /** A stream that emits whenever a manual search is requested. */ private _search; /** A stream that emits whenever a reload is requested. */ private _reload; /** Reference to the latest subscription to update the table's data. */ private _subscription; constructor(); /** * The request to get the data. Either paginated or a plain list. * @returns Observable | TerraPagerInterface> */ abstract request(requestParams: RequestParameterInterface): Observable | TerraPagerInterface>; /** Initiates a request that fetches data from the server */ search(): void; /** Initiates a request that reloads the data with the currently set filters and page data **/ reload(): void; /** Called by the table when it connects to this data source. */ connect(): Observable | ReadonlyArray>; /** Called by the table when it is destroyed. No-op. */ disconnect(): void; /** * Subscribe to changes that should trigger an update to the table's rendered data. When the * changes occur, process the current state of the filter, sort, and pagination and fetch the requested * data from the server using the provided implementation of the `request` method. * * Sorting and pagination is only watched if MatSort and/or MatPaginator are provided. */ private _updateSubscription; }