forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ko-grid.d.ts
279 lines (203 loc) · 10.4 KB
/
ko-grid.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Type definitions for ko-grid
// Project: http://knockout-contrib.github.io/KoGrid/
// Definitions by: huer12 <https://github.com/huer12/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// These are very definitely preliminary. Please feel free to improve.
/// <reference path="../knockout/knockout.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
declare namespace kg {
interface DomUtilityService {
UpdateGridLayout(grid: Grid<any>): void;
BuildStyles(grid: Grid<any>): void;
}
interface Row<EntityType> {
selected: KnockoutObservable<boolean>;
entity: EntityType;
}
interface RowFactory<EntityType> {
rowCache: Row<EntityType>[];
}
interface SelectionService<EntityType> {
setSelection(row: Row<EntityType>, selected: boolean): void;
multi: boolean;
lastClickedRow: Row<EntityType>;
}
interface Grid<EntityType> {
configureColumnWidths(): void;
rowFactory: RowFactory<EntityType>;
config: GridOptions<EntityType>;
$$selectionPhase: boolean;
selectionService: SelectionService<EntityType>;
}
interface Plugin<EntityType> {
onGridInit(grid: Grid<EntityType>): void;
}
interface GridOptions<EntityType> {
/** Callback for when you want to validate something after selection. */
afterSelectionChange?(row: Row<EntityType>): void;
/** Callback if you want to inspect something before selection,
return false if you want to cancel the selection. return true otherwise.
If you need to wait for an async call to proceed with selection you can
use rowItem.changeSelection(event) method after returning false initially.
Note: when shift+ Selecting multiple items in the grid this will only get called
once and the rowItem will be an array of items that are queued to be selected. */
beforeSelectionChange?(row: Row<EntityType>): boolean;
/** To be able to have selectable rows in grid. */
canSelectRows?:boolean;
/** definitions of columns as an array [], if not defined columns are auto-generated. See github wiki for more details. */
columnDefs?: ColumnDef[] | KnockoutObservable<ColumnDef[]>;
/** Column width of columns in grid. */
columnWidth?: number;
/** Data being displayed in the grid. Each item in the array is mapped to a row being displayed. */
data?: KnockoutObservableArray<EntityType>;
/** Row selection check boxes appear as the first column. */
displaySelectionCheckbox: boolean;
/** Enable or disable resizing of columns */
enableColumnResize?: boolean;
/** Enables the server-side paging feature */
enablePaging?: boolean;
/** Enable drag and drop row reordering. Only works in HTML5 compliant browsers. */
enableRowReordering?: boolean;
/** Enables or disables sorting in grid. */
enableSorting?: boolean;
/** filterOptions -
filterText: The text bound to the built-in search box.
useExternalFilter: Bypass internal filtering if you want to roll your own filtering mechanism but want to use builtin search box.
*/
filterOptions?: FilterOptions;
/** Defining the height of the footer in pixels. */
footerRowHeight?: number;
/** Show or hide the footer alltogether the footer is enabled by default */
footerVisible?: boolean;
/** Initial fields to group data by. Array of field names, not displayName. */
groups?: string[];
/** The height of the header row in pixels. */
headerRowHeight?: number;
/** Define a header row template for further customization. See github wiki for more details. */
headerRowTemplate?: string | JQueryGenericPromise<string>;
/** Enables the use of jquery UI reaggable/droppable plugin. requires jqueryUI to work if enabled.
Useful if you want drag + drop but your users insist on crappy browsers. */
jqueryUIDraggable?: boolean;
/** Enable the use jqueryUIThemes */
jqueryUITheme?: boolean;
/** Prevent unselections when in single selection mode. */
keepLastSelected?: boolean;
/** Maintains the column widths while resizing.
Defaults to true when using *'s or undefined widths. Can be ovverriden by setting to false. */
maintainColumnRatios?: any;
/** Set this to false if you only want one item selected at a time */
multiSelect?: boolean;
/** pagingOptions - */
pagingOptions?: PagingOptions;
/** Array of plugin functions to register in ng-grid */
plugins?: Plugin<EntityType>[];
/** Row height of rows in grid. */
rowHeight?: number;
/** Define a row template to customize output. See github wiki for more details. */
rowTemplate?: string | JQueryGenericPromise<string>;
/** Defines the binding to select all at once */
selectAllState?: KnockoutObservable<boolean>;
/** all of the items selected in the grid. In single select mode there will only be one item in the array. */
selectedItems?: KnockoutObservableArray<any>;
/** Disable row selections by clicking on the row and only when the checkbox is clicked. */
selectWithCheckboxOnly?: boolean;
/** Enables menu to choose which columns to display and group by.
If both showColumnMenu and showFilter are false the menu button will not display.*/
showColumnMenu?: boolean;
/** Enables display of the filterbox in the column menu.
If both showColumnMenu and showFilter are false the menu button will not display.*/
showFilter?: boolean;
/** Show the dropzone for drag and drop grouping */
showGroupPanel?: boolean;
/** Define a sortInfo object to specify a default sorting state.
You can also observe this variable to utilize server-side sorting (see useExternalSorting).
Syntax is sortinfo: { fields: ['fieldName1',' fieldName2'], direction: 'ASC'/'asc' || 'desc'/'DESC'}*/
sortInfo?: SortInfo | KnockoutObservable<SortInfo>;
/** Set the tab index of the Vieport. */
tabIndex?: number;
/** Prevents the internal sorting from executing.
The sortInfo object will be updated with the sorting information so you can handle sorting (see sortInfo)*/
useExternalSorting?: boolean;
}
type Direction = "asc" | "desc";
interface SortInfo {
/** Which column to sort */
column: SortColumn;
/** Which direction to sort */
direction: Direction;
}
interface SortColumn {
/** The string name of the property in your data model you want that column to represent. Can also be a property path on your data model. 'foo.bar.myField', 'Name.First', etc.. */
field: string;
/** Sets the sort function for the column. Useful when you have data that is formatted in an unusal way or if you want to sort on an underlying data type. Example: function(a,b){return a > b} */
sortingAlgorithm?: ((a:any, b:any) => number);
}
interface ColumnDef {
/** Appends a css class for the column cells */
cellClass?:string;
/**
* A function which takes the value of the cell and returns the display value. Useful when your data model has an underlying value which you need to convert to a human readable format.
* @param val
* @returns the display value
* @example function(unixTimeTicks) { return new Date(unixTimeTicks); }
*/
cellFormatter?(val:any): string;
/**Sets the cell template for the column. See github wiki for more details.*/
cellTemplate?: string | JQueryGenericPromise<string>;
/** Sets the pretty display name of the column. default is the field given */
displayName?: string;
/** The string name of the property in your data model you want that column to represent. Can also be a property path on your data model. 'foo.bar.myField', 'Name.First', etc.. */
field: string;
/** Sets the template for the column header cell. See github wiki for more details. */
headerCellTemplate?: string | JQueryGenericPromise<string>;
/** Appends a css class for the column header. */
headerClass?: string;
/**Sets the maximum width of the column.*/
maxWidth?: number;
/**Whether or not column is resizable. */
resizable?: boolean;
/**Whether or not column is sortable. */
sortable?: boolean;
/** Sets the sort function for the column. Useful when you have data that is formatted in an unusal way or if you want to sort on an underlying data type. Example: function(a,b){return a > b} */
sortFn?: ((a: any, b: any) => number);
/** Sets the width of the column. Can be a fixed width in pixels as an int (42), string px('42px'), percentage string ('42%'), weighted asterisks (width divided by total number of *'s is all column definition widths) See github wiki for more details. */
width?: string;
}
interface FilterOptions {
/** Variable to contain the current search filter */
filterText?: KnockoutObservable<string>;
/** Is the filtering internal or does it require a server visit. You should subscribe to filterText to refresh */
useExternalFilter?: boolean;
/** Number of seconds to throttle before reapplying search */
filterThrottle?: number;
}
interface PagingOptions {
/** pageSizes: list of available page sizes. */
pageSizes?: KnockoutObservableArray<number>;
/** pageSize: currently selected page size. */
pageSize?: KnockoutObservable<number>;
/** totalServerItems: Total items are on the server. */
totalServerItems?: KnockoutObservable<number>;
/** currentPage: the uhm... current page. */
currentPage?: KnockoutObservable<number>;
}
}
interface IKg {
domUtilityService: kg.DomUtilityService;
/** Default grid template */
defaultGridTemplate():string;
/** Default row template. Can be overriden in GridOptions.rowTemplate */
defaultRowTemplate(): string;
/** Default cell template. Can be overriden in GridOptions.cellTemplate */
defaultCellTemplate(): string;
/** Default aggregate template */
aggregateTemplate(): string;
/** Default headerrow template. Can be overriden in GridOptions.headerRowTemplate */
defaultHeaderRowTemplate(): string;
/** Default headercell template. Can be overriden in GridOptions.headerCellTemplate */
defaultHeaderCellTemplate():string;
}
declare var kg: IKg;
declare module "kg" {
export = kg;
}