UNPKG

8.22 kBTypeScriptView Raw
1/// <reference types="angular" />
2import { IAttributes, IPromise, IScope } from 'angular';
3/**
4 * The scope available to a table column getter
5 */
6export declare type ColumnFieldContext = IScope & {
7 $column?: IColumnDef;
8 $columns: IColumnDef[];
9};
10/**
11 * Signature of a getter/setter on a {@link IColumnDef} instance
12 */
13export interface IColumnField<T> {
14 (context?: ColumnFieldContext): T;
15 (value: T): void;
16 assign($scope: IScope, value: T): void;
17}
18/**
19 * The definition of the column within a ngTable.
20 * When using `ng-table` directive a column definition will be parsed from each `td` tag found in the
21 * `tr` data row tag.
22 *
23 * @example
24 * ```html
25 * <tr>
26 * <td data-title="'Name of User'" filter="{ username: 'text'}" sortable="'username'" />
27 * <td data-title="'Age of User'" filter="{ age: 'number'}" sortable="'age'" />
28 * </tr>
29 * ```
30 */
31export interface IColumnDef {
32 /**
33 * Custom CSS class that should be added to the `th` tag(s) of this column in the table header
34 *
35 * To set this on the `td` tag of a html table use the attribute `header-class` or `data-header-class`
36 */
37 class: IColumnField<string>;
38 /**
39 * The `ISelectOption`s that can be used in a html filter template for this colums.
40 */
41 data?: SelectData;
42 /**
43 * The index position of this column within the `$columns` container array
44 */
45 id: number;
46 /**
47 * The definition of 0 or more html filter templates that should be rendered for this column in
48 * the table header
49 */
50 filter: IColumnField<IFilterTemplateDefMap>;
51 /**
52 * Supplies the `ISelectOption`s that can be used in a html filter template for this colums.
53 * At the creation of the `NgTableParams` this field will be called and the result then assigned
54 * to the `data` field of this column.
55 */
56 filterData: IColumnField<IPromise<SelectData> | SelectData>;
57 /**
58 * The name of the data row field that will be used to group on, or false when this column
59 * does not support grouping
60 */
61 groupable: IColumnField<string | boolean>;
62 /**
63 * The url of a custom html template that should be used to render a table header for this column
64 *
65 * To set this on the `td` tag for a html table use the attribute `header` or `data-header`
66 */
67 headerTemplateURL: IColumnField<string | boolean>;
68 /**
69 * The text that should be used as a tooltip for this column in the table header
70 */
71 headerTitle: IColumnField<string>;
72 /**
73 * Determines whether this column should be displayed in the table
74 *
75 * To set this on the `td` tag for a html table use the attribute `ng-if`
76 */
77 show: IColumnField<boolean>;
78 /**
79 * The name of the data row field that will be used to sort on, or false when this column
80 * does not support sorting
81 */
82 sortable: IColumnField<string | boolean>;
83 /**
84 * The title of this column that should be displayed in the table header
85 */
86 title: IColumnField<string>;
87 /**
88 * An alternate column title. Typically this can be used for responsive table layouts
89 * where the titleAlt should be used for small screen sizes
90 */
91 titleAlt: IColumnField<string>;
92}
93export declare type DynamicTableColField<T> = IDynamicTableColFieldFunc<T> | T;
94/**
95 * Signature of a getter/setter on a {@link IDynamicTableColDef} instance
96 */
97export interface IDynamicTableColFieldFunc<T> {
98 (context: ColumnFieldContext): T;
99}
100/**
101 * The definition of the column supplied to a {@link ngTableDynamic} directive.
102 */
103export interface IDynamicTableColDef {
104 /**
105 * Custom CSS class that should be added to the `th` tag(s) of this column in the table header
106 */
107 class?: DynamicTableColField<string>;
108 /**
109 * The definition of 0 or more html filter templates that should be rendered for this column in
110 * the table header
111 */
112 filter?: DynamicTableColField<IFilterTemplateDefMap>;
113 /**
114 * Supplies the `ISelectOption`s that can be used in a html filter template for this colums.
115 * At the creation of the `NgTableParams` this field will be called and the result then assigned
116 * to the `data` field of this column.
117 */
118 filterData?: DynamicTableColField<IPromise<SelectData> | SelectData>;
119 /**
120 * The name of the data row field that will be used to group on, or false when this column
121 * does not support grouping
122 */
123 groupable?: DynamicTableColField<string | boolean>;
124 /**
125 * The url of a custom html template that should be used to render a table header for this column
126 */
127 headerTemplateURL?: DynamicTableColField<string | boolean>;
128 /**
129 * The text that should be used as a tooltip for this column in the table header
130 */
131 headerTitle?: DynamicTableColField<string>;
132 /**
133 * Determines whether this column should be displayed in the table
134 */
135 show?: DynamicTableColField<boolean>;
136 /**
137 * The name of the data row field that will be used to sort on, or false when this column
138 * does not support sorting
139 */
140 sortable?: DynamicTableColField<string | boolean>;
141 /**
142 * The title of this column that should be displayed in the table header
143 */
144 title?: DynamicTableColField<string>;
145 /**
146 * An alternate column title. Typically this can be used for responsive table layouts
147 * where the titleAlt should be used for small screen sizes
148 */
149 titleAlt?: DynamicTableColField<string>;
150}
151/**
152 * Configuration values that determine the behaviour of the `ngTableFilterConfig` service
153 */
154export interface IFilterConfigValues {
155 /**
156 * The default base url to use when deriving the url for a filter template given just an alias name
157 * Defaults to 'ng-table/filters/'
158 */
159 defaultBaseUrl?: string;
160 /**
161 * The extension to use when deriving the url of a filter template when given just an alias name
162 */
163 defaultExt?: string;
164 /**
165 * A map of alias names and their corrosponding urls. A lookup against this map will be used
166 * to find the url matching an alias name.
167 * If no match is found then a url will be derived using the following pattern `${defaultBaseUrl}${aliasName}.${defaultExt}`
168 */
169 aliasUrls?: {
170 [name: string]: string;
171 };
172}
173/**
174 * A key value-pair map where the key is the name of a field in a data row and the value is the definition
175 * for the template used to render a filter cell in the header of a html table.
176 * Where the value is supplied as a string this should either be url to a html template or an alias to a url registered
177 * using the {@link ngTableFilterConfigProvider}
178 * @example
179 * ```js
180 * vm.ageFilter = { "age": "number" }
181 * ```
182 * @example
183 * ```js
184 * vm.ageFilter = { "age": "my/custom/ageTemplate.html" }
185 * ```
186 * @example
187 * ```js
188 * vm.ageFilter = { "age": { id: "number", placeholder: "Age of person"} }
189 * ```
190 */
191export interface IFilterTemplateDefMap {
192 [name: string]: string | IFilterTemplateDef;
193}
194/**
195 * A fully qualified template definition for a single filter
196 */
197export interface IFilterTemplateDef {
198 /**
199 * A url to a html template or an alias to a url registered using the {@link ngTableFilterConfigProvider}
200 */
201 id: string;
202 /**
203 * The text that should be rendered as a prompt to assist the user when entering a filter value
204 */
205 placeholder: string;
206}
207export declare type SelectData = ISelectOption[] | ISelectDataFunc;
208/**
209 * An object to be rendered as a html select option
210 */
211export interface ISelectOption {
212 id: string | number;
213 title: string;
214}
215/**
216 * Signature of a function that will return the options that will be rendered by a html select
217 */
218export interface ISelectDataFunc {
219 (): ISelectOption[] | IPromise<ISelectOption[]>;
220}
221/**
222 * The definition of the html attributes accepted by the {@link ngTable ngTable} and {@link ngTableDynamic} directives
223 */
224export interface ITableInputAttributes extends IAttributes {
225 disableFilter?: string;
226 ngTable?: string;
227 ngTableDynamic?: string;
228 showFilter?: string;
229 showGroup?: string;
230 templateHeader?: string;
231 templatePagination?: string;
232}