UNPKG

svogv

Version:

A decorator based approach for model driven forms, including an advanced DataGrid and a TreeView component.

100 lines (99 loc) 3.44 kB
import { Type, EventEmitter } from '@angular/core'; import '../../../utils/object-extensions'; import { DataGridHeaderModel } from './datagridheader.model'; /** * Sort direction, controlled by simple string comparision or a callback. */ export declare enum Direction { Ascending = 0, Descending = 1 } /** * The controlling class for Grid applications. * * This class takes an array of elements and handles: * - visible headers, managed by @Hidden() decorator * - create header titles, managed by @Display() decorator * - sorting * - filtering * - count total rows * - paging */ export declare class DataGridModel<T> { /** * Returns the number of rows regardless the actual filter (the total). */ get totalRows(): number; get totalFilteredRows(): number; private get currentRowStart(); private get currentRowEnd(); get startRow(): number; get maxPageIndex(): number; set items(value: T[]); get items(): T[]; get itemsFiltered(): T[]; get itemsOnCurrentPage(): T[]; /** * Get all headers (column names) and their properties. */ get headers(): DataGridHeaderModel[]; /** * Returns the columns currently not shown. {@link addColumn and @see removeColumn for more}information. */ get headersNotVisible(): DataGridHeaderModel[]; /** * The search value filters the rows. Provide the property name and the filter instruction. Search is pure client. */ searchValue: { [prop: string]: any; }; currentPageIndex: number; pageSize: number; /** * Event fired if user clicks Edit button. */ onEdit: EventEmitter<T>; /** * Event fired if user clicks Delete button. */ onDelete: EventEmitter<T>; /** * Current sort direction per column. */ sortDirection: { [column: string]: Direction; }; private _items; private _headers; constructor(items: T[], type: Type<T>, pageSize?: number); /** * Simple sort fucntion that makes a array sort call for the specified column. * @param colName The column which has to be sorted after. * // tslint:disable-next-line:max-line-length * @param dir The order, descended is *desc*, any other string is ascending. * If nothing is provided, the direction toggles. Initital value is *ascending*. */ sortColumn(colName: string, dir: Direction, sortCallback?: (a: any, b: any) => 1 | -1 | 0): void; /** * Make a column invisible. This is just changing the render process, the column is still * in the headers collection and can be made visible again by calling {@link addColumn}later. */ removeColumn(colname: string): void; /** * Add a column to the current grid, that has been removed recently. * It's just adding columns that already exists in the headers collection. * If the column name provided does not exists, the method does nothing. */ addColumn(colname: string): void; /** * Called by infrastructure to inform caller of edit wish * @param item The item to edit */ editItem(item: T): void; /** * Called by infrastructure to inform caller of delete wish * @param item The item to delete */ deleteItem(item: T): void; private createHeadersForType; }