@guiexpert/table 1.1.79 → 1.1.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1605 -54
- package/lib/table/data/tablemodel/areamodel/area-model-object-array-with-columndefs.d.ts +106 -2
- package/lib/table/data/tablemodel/areamodel/area-model-object-array.d.ts +489 -4
- package/lib/table/data/tablemodel/areamodel/area-model.d.ts +660 -1
- package/lib/table/data/tablemodel/areamodel/area-model.if.d.ts +782 -69
- package/lib/table/table-api.d.ts +1019 -42
- package/package.json +4 -2
|
@@ -2,14 +2,118 @@ import { AreaModelObjectArray } from "./area-model-object-array";
|
|
|
2
2
|
import { ColumnDefIf } from "../column/column-def.if";
|
|
3
3
|
import { AreaIdent } from "../area-ident.type";
|
|
4
4
|
/**
|
|
5
|
-
* Represents an
|
|
5
|
+
* Represents an area model defined by an object array with column definitions.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
7
|
+
* @class AreaModelObjectArrayWithColumndefs
|
|
8
|
+
* @description
|
|
9
|
+
* The `AreaModelObjectArrayWithColumndefs` class extends {@link AreaModelObjectArray} to provide
|
|
10
|
+
* a specialized implementation where column definitions are a primary constructor parameter.
|
|
11
|
+
*
|
|
12
|
+
* This class is particularly useful when working with table models where column definitions
|
|
13
|
+
* are essential for defining the structure of the table, especially in CRUD operations
|
|
14
|
+
* and other scenarios where column definitions need to be explicitly provided.
|
|
15
|
+
*
|
|
16
|
+
* The main distinction from its parent class is the constructor parameter order, which
|
|
17
|
+
* prioritizes column definitions as a required parameter rather than an optional one.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of objects in the array. Each object represents a row in the table.
|
|
20
|
+
*
|
|
21
|
+
* @extends {AreaModelObjectArray<T>}
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Basic usage with an array of objects and explicit column definitions
|
|
25
|
+
* const rows = [
|
|
26
|
+
* { id: 1, name: 'John', age: 30 },
|
|
27
|
+
* { id: 2, name: 'Jane', age: 25 },
|
|
28
|
+
* { id: 3, name: 'Bob', age: 40 }
|
|
29
|
+
* ];
|
|
30
|
+
*
|
|
31
|
+
* const columnDefs = [
|
|
32
|
+
* { property: 'id', headerLabel: 'ID', width: new Size(50, 'px') },
|
|
33
|
+
* { property: 'name', headerLabel: 'Name', width: new Size(150, 'px') },
|
|
34
|
+
* { property: 'age', headerLabel: 'Age', width: new Size(100, 'px') }
|
|
35
|
+
* ];
|
|
36
|
+
*
|
|
37
|
+
* const bodyAreaModel = new AreaModelObjectArrayWithColumndefs<any>(
|
|
38
|
+
* 'body',
|
|
39
|
+
* rows,
|
|
40
|
+
* columnDefs,
|
|
41
|
+
* 30 // default row height
|
|
42
|
+
* );
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Using with CrudTableModelFactory
|
|
46
|
+
* function createTableModel() {
|
|
47
|
+
* const rows = fetchDataFromServer();
|
|
48
|
+
* const columnDefs = [
|
|
49
|
+
* { property: 'id', headerLabel: 'ID', width: new Size(50, 'px') },
|
|
50
|
+
* { property: 'name', headerLabel: 'Name', width: new Size(150, 'px') },
|
|
51
|
+
* { property: 'age', headerLabel: 'Age', width: new Size(100, 'px') }
|
|
52
|
+
* ];
|
|
53
|
+
*
|
|
54
|
+
* const tableModel = TableFactory.buildByTypedRowsParam({
|
|
55
|
+
* rows,
|
|
56
|
+
* columnDefs,
|
|
57
|
+
* tableOptions: new TableOptions(),
|
|
58
|
+
* fixedLeftColumnCount: 0,
|
|
59
|
+
* fixedRightColumnCount: 1
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // The body model is an instance of AreaModelObjectArrayWithColumndefs
|
|
63
|
+
* const bodyModel = tableModel.getBodyModel() as AreaModelObjectArrayWithColumndefs<any>;
|
|
64
|
+
*
|
|
65
|
+
* // Now you can work with the body model
|
|
66
|
+
* return bodyModel;
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Using custom row classes for selection and focus
|
|
71
|
+
* const bodyAreaModel = new AreaModelObjectArrayWithColumndefs<any>(
|
|
72
|
+
* 'body',
|
|
73
|
+
* rows,
|
|
74
|
+
* columnDefs,
|
|
75
|
+
* 30, // default row height
|
|
76
|
+
* 'my-custom-selected-row', // custom selected row class
|
|
77
|
+
* 'my-custom-focused-row' // custom focused row class
|
|
78
|
+
* );
|
|
79
|
+
*
|
|
80
|
+
* @see {@link AreaModelObjectArray} - The parent class that provides the core functionality
|
|
81
|
+
* @see {@link ColumnDefIf} - The interface that defines the structure of column definitions
|
|
82
|
+
* @see {@link CrudTableModelFactory} - A factory class that uses this class for CRUD operations
|
|
8
83
|
*/
|
|
9
84
|
export declare class AreaModelObjectArrayWithColumndefs<T> extends AreaModelObjectArray<T> {
|
|
10
85
|
areaIdent: AreaIdent;
|
|
11
86
|
protected rows: T[];
|
|
12
87
|
protected readonly columnDefs: ColumnDefIf[];
|
|
13
88
|
defaultRowHeight: number;
|
|
89
|
+
/**
|
|
90
|
+
* Creates an instance of AreaModelObjectArrayWithColumndefs.
|
|
91
|
+
*
|
|
92
|
+
* @param {AreaIdent} areaIdent - Identifies which area of the table this model represents ('header', 'body', or 'footer')
|
|
93
|
+
* @param {T[]} rows - The array of objects that represent the rows in this area
|
|
94
|
+
* @param {ColumnDefIf[]} columnDefs - Definitions for the columns in this area (required parameter)
|
|
95
|
+
* @param {number} defaultRowHeight - The default height for rows in this area (in pixels)
|
|
96
|
+
* @param {string} [selectedRowClass='ge-selected-row'] - CSS class to apply to selected rows
|
|
97
|
+
* @param {string} [focusedRowClass='ge-focused-row'] - CSS class to apply to the focused row
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const rows = [
|
|
101
|
+
* { id: 1, name: 'John', age: 30 },
|
|
102
|
+
* { id: 2, name: 'Jane', age: 25 }
|
|
103
|
+
* ];
|
|
104
|
+
*
|
|
105
|
+
* const columnDefs = [
|
|
106
|
+
* { property: 'id', headerLabel: 'ID', width: new Size(50, 'px') },
|
|
107
|
+
* { property: 'name', headerLabel: 'Name', width: new Size(150, 'px') },
|
|
108
|
+
* { property: 'age', headerLabel: 'Age', width: new Size(100, 'px') }
|
|
109
|
+
* ];
|
|
110
|
+
*
|
|
111
|
+
* const bodyAreaModel = new AreaModelObjectArrayWithColumndefs(
|
|
112
|
+
* 'body',
|
|
113
|
+
* rows,
|
|
114
|
+
* columnDefs,
|
|
115
|
+
* 30
|
|
116
|
+
* );
|
|
117
|
+
*/
|
|
14
118
|
constructor(areaIdent: AreaIdent, rows: T[], columnDefs: ColumnDefIf[], defaultRowHeight: number, selectedRowClass?: string, focusedRowClass?: string);
|
|
15
119
|
}
|
|
@@ -6,8 +6,138 @@ import { SorterService } from '../../../service/sorter.service';
|
|
|
6
6
|
import { SortItem } from '../../common/sort-item';
|
|
7
7
|
import { ObjectArrayHolderIf } from './object-array-holder.if';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
9
|
+
* @class AreaModelObjectArray
|
|
10
|
+
* @description
|
|
11
|
+
* The `AreaModelObjectArray` class is a fundamental component of the GuiExpert Table library that
|
|
12
|
+
* represents a data model for a specific area of a table (header, body, or footer) where the data
|
|
13
|
+
* is stored as an array of objects.
|
|
14
|
+
*
|
|
15
|
+
* This class extends {@link AbstractAreaModel} and implements {@link ObjectArrayHolderIf}, providing
|
|
16
|
+
* a robust implementation for handling tabular data where each row is represented as an object in an array.
|
|
17
|
+
*
|
|
18
|
+
* The class provides functionality for:
|
|
19
|
+
* - Managing row data (setting, filtering, sorting)
|
|
20
|
+
* - Retrieving values from specific cells
|
|
21
|
+
* - Handling row selection and focus
|
|
22
|
+
* - Supporting custom sorting and filtering
|
|
23
|
+
* - Accessing nested properties within objects
|
|
24
|
+
* - Managing column order changes
|
|
25
|
+
* - Applying custom CSS classes to rows
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of objects in the array. Each object represents a row in the table.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Basic usage with an array of simple objects
|
|
31
|
+
* const rows = [
|
|
32
|
+
* { id: 1, name: 'John', age: 30 },
|
|
33
|
+
* { id: 2, name: 'Jane', age: 25 },
|
|
34
|
+
* { id: 3, name: 'Bob', age: 40 }
|
|
35
|
+
* ];
|
|
36
|
+
*
|
|
37
|
+
* const columnDefs = [
|
|
38
|
+
* { property: 'id', headerLabel: 'ID', width: 50 },
|
|
39
|
+
* { property: 'name', headerLabel: 'Name', width: 150 },
|
|
40
|
+
* { property: 'age', headerLabel: 'Age', width: 100 }
|
|
41
|
+
* ];
|
|
42
|
+
*
|
|
43
|
+
* const bodyAreaModel = new AreaModelObjectArray<any>(
|
|
44
|
+
* 'body',
|
|
45
|
+
* rows,
|
|
46
|
+
* 30, // default row height
|
|
47
|
+
* columnDefs
|
|
48
|
+
* );
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Using with TableFactory to create a complete table model
|
|
52
|
+
* import { TableFactory } from '../../../factory/table-factory';
|
|
53
|
+
*
|
|
54
|
+
* const rows = [
|
|
55
|
+
* { id: 1, name: 'John', age: 30 },
|
|
56
|
+
* { id: 2, name: 'Jane', age: 25 },
|
|
57
|
+
* { id: 3, name: 'Bob', age: 40 }
|
|
58
|
+
* ];
|
|
59
|
+
*
|
|
60
|
+
* const columnDefs = [
|
|
61
|
+
* { property: 'id', headerLabel: 'ID', width: 50 },
|
|
62
|
+
* { property: 'name', headerLabel: 'Name', width: 150 },
|
|
63
|
+
* { property: 'age', headerLabel: 'Age', width: 100 }
|
|
64
|
+
* ];
|
|
65
|
+
*
|
|
66
|
+
* const tableModel = TableFactory.createByObjectArray(
|
|
67
|
+
* rows,
|
|
68
|
+
* [['ID', 'Name', 'Age']], // header
|
|
69
|
+
* [], // footer
|
|
70
|
+
* 0, // fixedLeftColumnCount
|
|
71
|
+
* 0, // fixedRightColumnCount
|
|
72
|
+
* false, // rowCheckboxVisible
|
|
73
|
+
* undefined, // defaultRowHeights
|
|
74
|
+
* columnDefs
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Working with nested properties
|
|
79
|
+
* const rows = [
|
|
80
|
+
* { id: 1, person: { name: 'John', contact: { email: 'john@example.com', phone: '123-456-7890' } } },
|
|
81
|
+
* { id: 2, person: { name: 'Jane', contact: { email: 'jane@example.com', phone: '098-765-4321' } } }
|
|
82
|
+
* ];
|
|
83
|
+
*
|
|
84
|
+
* const columnDefs = [
|
|
85
|
+
* { property: 'id', headerLabel: 'ID', width: 50 },
|
|
86
|
+
* { property: 'person.name', headerLabel: 'Name', width: 150 },
|
|
87
|
+
* { property: 'person.contact.email', headerLabel: 'Email', width: 200 },
|
|
88
|
+
* { property: 'person.contact.phone', headerLabel: 'Phone', width: 150 }
|
|
89
|
+
* ];
|
|
90
|
+
*
|
|
91
|
+
* const bodyAreaModel = new AreaModelObjectArray<any>(
|
|
92
|
+
* 'body',
|
|
93
|
+
* rows,
|
|
94
|
+
* 30, // default row height
|
|
95
|
+
* columnDefs
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // Filtering rows
|
|
100
|
+
* const bodyAreaModel = new AreaModelObjectArray<any>('body', rows, 30, columnDefs);
|
|
101
|
+
*
|
|
102
|
+
* // Filter rows where age > 30
|
|
103
|
+
* bodyAreaModel.externalFilterChanged(row => row.age > 30);
|
|
104
|
+
*
|
|
105
|
+
* // Get the filtered rows
|
|
106
|
+
* const filteredRows = bodyAreaModel.getFilteredRows();
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Sorting rows
|
|
110
|
+
* const bodyAreaModel = new AreaModelObjectArray<any>('body', rows, 30, columnDefs);
|
|
111
|
+
*
|
|
112
|
+
* // Sort by age in ascending order
|
|
113
|
+
* bodyAreaModel.doSort([{ columnIndex: 2, sortState: 'asc' }]);
|
|
114
|
+
*
|
|
115
|
+
* // Sort by name in descending order
|
|
116
|
+
* bodyAreaModel.doSort([{ columnIndex: 1, sortState: 'desc' }]);
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* // Custom sorting with a comparator function
|
|
120
|
+
* const bodyAreaModel = new AreaModelObjectArray<any>('body', rows, 30, columnDefs);
|
|
121
|
+
*
|
|
122
|
+
* // Sort by name length
|
|
123
|
+
* bodyAreaModel.sort((a, b) => a.name.length - b.name.length);
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // Working with row selection and focus
|
|
127
|
+
* const bodyAreaModel = new AreaModelObjectArray<any>('body', rows, 30, columnDefs);
|
|
128
|
+
*
|
|
129
|
+
* // Set focus on the second row
|
|
130
|
+
* bodyAreaModel.setFocusedRowIndex(1);
|
|
131
|
+
*
|
|
132
|
+
* // Get the focused row index
|
|
133
|
+
* const focusedRowIndex = bodyAreaModel.getFocusedRowIndex();
|
|
134
|
+
*
|
|
135
|
+
* // Get custom classes for a cell (includes selection and focus classes)
|
|
136
|
+
* const classes = bodyAreaModel.getCustomClassesAt(1, 0);
|
|
137
|
+
*
|
|
138
|
+
* @see {@link AbstractAreaModel} - The parent class that provides the base implementation
|
|
139
|
+
* @see {@link ObjectArrayHolderIf} - The interface that defines methods for accessing rows
|
|
140
|
+
* @see {@link AreaModelObjectArrayWithColumndefs} - A subclass that changes the constructor parameter order
|
|
11
141
|
*/
|
|
12
142
|
export declare class AreaModelObjectArray<T> extends AbstractAreaModel<T> implements ObjectArrayHolderIf<T> {
|
|
13
143
|
areaIdent: AreaIdent;
|
|
@@ -16,54 +146,409 @@ export declare class AreaModelObjectArray<T> extends AbstractAreaModel<T> implem
|
|
|
16
146
|
protected columnDefs: ColumnDefIf[];
|
|
17
147
|
selectedRowClass: string;
|
|
18
148
|
focusedRowClass: string;
|
|
149
|
+
/**
|
|
150
|
+
* An array of property names extracted from the column definitions.
|
|
151
|
+
* These properties are used to access values from the row objects.
|
|
152
|
+
* @protected
|
|
153
|
+
* @readonly
|
|
154
|
+
* @type {string[]}
|
|
155
|
+
*/
|
|
19
156
|
protected readonly properties: string[];
|
|
157
|
+
/**
|
|
158
|
+
* A copy of the rows array that can be filtered and sorted without affecting the original data.
|
|
159
|
+
* This array is used for rendering the table and is updated when filtering or sorting is applied.
|
|
160
|
+
* @protected
|
|
161
|
+
* @type {T[]}
|
|
162
|
+
*/
|
|
20
163
|
protected filteredRows: T[];
|
|
164
|
+
/**
|
|
165
|
+
* Service for handling sorting operations.
|
|
166
|
+
* @protected
|
|
167
|
+
* @type {SorterService}
|
|
168
|
+
*/
|
|
21
169
|
protected sorterService: SorterService;
|
|
170
|
+
/**
|
|
171
|
+
* Creates an instance of AreaModelObjectArray.
|
|
172
|
+
*
|
|
173
|
+
* @param {AreaIdent} areaIdent - Identifies which area of the table this model represents ('header', 'body', or 'footer')
|
|
174
|
+
* @param {T[]} rows - The array of objects that represent the rows in this area
|
|
175
|
+
* @param {number} defaultRowHeight - The default height for rows in this area (in pixels)
|
|
176
|
+
* @param {ColumnDefIf[]} [columnDefs=[]] - Definitions for the columns in this area
|
|
177
|
+
* @param {string} [selectedRowClass='ge-selected-row'] - CSS class to apply to selected rows
|
|
178
|
+
* @param {string} [focusedRowClass='ge-focused-row'] - CSS class to apply to the focused row
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const rows = [
|
|
182
|
+
* { id: 1, name: 'John', age: 30 },
|
|
183
|
+
* { id: 2, name: 'Jane', age: 25 }
|
|
184
|
+
* ];
|
|
185
|
+
*
|
|
186
|
+
* const columnDefs = [
|
|
187
|
+
* { property: 'id', headerLabel: 'ID', width: 50 },
|
|
188
|
+
* { property: 'name', headerLabel: 'Name', width: 150 },
|
|
189
|
+
* { property: 'age', headerLabel: 'Age', width: 100 }
|
|
190
|
+
* ];
|
|
191
|
+
*
|
|
192
|
+
* const bodyAreaModel = new AreaModelObjectArray(
|
|
193
|
+
* 'body',
|
|
194
|
+
* rows,
|
|
195
|
+
* 30,
|
|
196
|
+
* columnDefs
|
|
197
|
+
* );
|
|
198
|
+
*/
|
|
22
199
|
constructor(areaIdent: AreaIdent, rows: T[], defaultRowHeight: number, columnDefs?: ColumnDefIf[], selectedRowClass?: string, focusedRowClass?: string);
|
|
200
|
+
/**
|
|
201
|
+
* The index of the currently focused row.
|
|
202
|
+
* This is used to apply the focused row styling.
|
|
203
|
+
* @public
|
|
204
|
+
* @type {number}
|
|
205
|
+
* @default 0
|
|
206
|
+
*/
|
|
23
207
|
_focusedRowIndex: number;
|
|
208
|
+
/**
|
|
209
|
+
* Gets the index of the currently focused row.
|
|
210
|
+
*
|
|
211
|
+
* @returns {number} The index of the focused row
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* const focusedRowIndex = bodyAreaModel.getFocusedRowIndex();
|
|
215
|
+
* console.log(`The focused row is at index ${focusedRowIndex}`);
|
|
216
|
+
*/
|
|
24
217
|
getFocusedRowIndex(): number;
|
|
218
|
+
/**
|
|
219
|
+
* Sets the index of the focused row.
|
|
220
|
+
* This will apply the focused row styling to the specified row.
|
|
221
|
+
*
|
|
222
|
+
* @param {number} value - The index of the row to focus
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* // Focus the second row (index 1)
|
|
226
|
+
* bodyAreaModel.setFocusedRowIndex(1);
|
|
227
|
+
*/
|
|
25
228
|
setFocusedRowIndex(value: number): void;
|
|
229
|
+
/**
|
|
230
|
+
* Replaces the current rows array with a new one.
|
|
231
|
+
* This also resets the filtered rows to match the new rows array.
|
|
232
|
+
*
|
|
233
|
+
* @param {T[]} rows - The new array of row objects
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* // Replace the current rows with new data
|
|
237
|
+
* const newRows = [
|
|
238
|
+
* { id: 4, name: 'Alice', age: 35 },
|
|
239
|
+
* { id: 5, name: 'Charlie', age: 45 }
|
|
240
|
+
* ];
|
|
241
|
+
* bodyAreaModel.setRows(newRows);
|
|
242
|
+
*/
|
|
26
243
|
setRows(rows: T[]): void;
|
|
244
|
+
/**
|
|
245
|
+
* Filters both the original rows and filtered rows arrays using the provided predicate function.
|
|
246
|
+
* Unlike `externalFilterChanged`, this method permanently modifies the original rows array.
|
|
247
|
+
*
|
|
248
|
+
* @param {(row: T) => boolean} predict - A function that returns true for rows to keep and false for rows to filter out
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* // Remove all rows where age is less than 30
|
|
252
|
+
* bodyAreaModel.filterRowsByPredict(row => row.age >= 30);
|
|
253
|
+
*/
|
|
27
254
|
filterRowsByPredict(predict: (row: T) => boolean): void;
|
|
28
255
|
/**
|
|
29
|
-
*
|
|
256
|
+
* Returns the number of rows in the filtered rows array.
|
|
257
|
+
* This is used to determine how many rows should be rendered in the table.
|
|
258
|
+
*
|
|
259
|
+
* @returns {number} The number of rows in the filtered rows array
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* const rowCount = bodyAreaModel.getRowCount();
|
|
263
|
+
* console.log(`The table has ${rowCount} rows`);
|
|
30
264
|
*/
|
|
31
265
|
getRowCount(): number;
|
|
266
|
+
/**
|
|
267
|
+
* Gets the value at the specified row and column indices.
|
|
268
|
+
* This method handles tree rows and nested properties.
|
|
269
|
+
*
|
|
270
|
+
* @param {number} rowIndex - The index of the row
|
|
271
|
+
* @param {number} columnIndex - The index of the column
|
|
272
|
+
* @returns {any} The value at the specified cell, or an empty string if not found
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* // Get the value in the first row, second column
|
|
276
|
+
* const value = bodyAreaModel.getValueAt(0, 1);
|
|
277
|
+
* console.log(`The value is: ${value}`);
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* // Iterate through all cells in a row
|
|
281
|
+
* const rowIndex = 0;
|
|
282
|
+
* for (let colIndex = 0; colIndex < columnDefs.length; colIndex++) {
|
|
283
|
+
* const value = bodyAreaModel.getValueAt(rowIndex, colIndex);
|
|
284
|
+
* console.log(`Cell (${rowIndex}, ${colIndex}): ${value}`);
|
|
285
|
+
* }
|
|
286
|
+
*/
|
|
32
287
|
getValueAt(rowIndex: number, columnIndex: number): any;
|
|
33
288
|
/**
|
|
34
289
|
* Retrieves the filtered and sorted rows from the dataset.
|
|
35
290
|
* These rows are used for rendering the table.
|
|
291
|
+
* Unlike `getAllRows()`, this method returns only the rows that match any applied filters.
|
|
292
|
+
*
|
|
293
|
+
* @returns {T[]} An array containing the filtered (and sorted) rows
|
|
36
294
|
*
|
|
37
|
-
* @
|
|
295
|
+
* @example
|
|
296
|
+
* // Get all filtered rows
|
|
297
|
+
* const filteredRows = bodyAreaModel.getFilteredRows();
|
|
298
|
+
*
|
|
299
|
+
* // Count rows that match a certain condition
|
|
300
|
+
* const adultsCount = filteredRows.filter(row => row.age >= 18).length;
|
|
38
301
|
*/
|
|
39
302
|
getFilteredRows(): T[];
|
|
303
|
+
/**
|
|
304
|
+
* Returns the original, unfiltered array of rows.
|
|
305
|
+
* This can be useful when you need to access all data regardless of any applied filters.
|
|
306
|
+
*
|
|
307
|
+
* @returns {T[]} The original array of row objects
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* // Get all rows, including those filtered out
|
|
311
|
+
* const allRows = bodyAreaModel.getAllRows();
|
|
312
|
+
*
|
|
313
|
+
* // Calculate average age across all rows
|
|
314
|
+
* const totalAge = allRows.reduce((sum, row) => sum + row.age, 0);
|
|
315
|
+
* const averageAge = totalAge / allRows.length;
|
|
316
|
+
*/
|
|
40
317
|
getAllRows(): T[];
|
|
41
318
|
/**
|
|
42
319
|
* Returns the first row from the filtered rows that matches the given criteria based on the provided predicate function.
|
|
320
|
+
* This method only searches within the filtered rows, not the original rows array.
|
|
43
321
|
*
|
|
44
322
|
* @param {Partial<T>} criteria - A partial object containing the search criteria
|
|
45
323
|
* @param {(criteria: Partial<T>, row: T) => boolean} predicate - A function that takes the search criteria and a row,
|
|
46
324
|
* and returns true if the row matches the criteria
|
|
47
325
|
* @returns {T | undefined} The first matching row, or undefined if no match is found
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* // Find a user by name in the filtered rows
|
|
329
|
+
* const criteria = { name: 'John' };
|
|
330
|
+
* const user = bodyAreaModel.findRowFromFilteredRowsByAllCriteria(
|
|
331
|
+
* criteria,
|
|
332
|
+
* (criteria, row) => row.name === criteria.name
|
|
333
|
+
* );
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* // Find a user by age range in the filtered rows
|
|
337
|
+
* const criteria = { minAge: 25, maxAge: 35 };
|
|
338
|
+
* const user = bodyAreaModel.findRowFromFilteredRowsByAllCriteria(
|
|
339
|
+
* criteria,
|
|
340
|
+
* (criteria, row) => row.age >= criteria.minAge && row.age <= criteria.maxAge
|
|
341
|
+
* );
|
|
48
342
|
*/
|
|
49
343
|
findRowFromFilteredRowsByAllCriteria(criteria: Partial<T>, predicate: (criteria: Partial<T>, row: T) => boolean): T | undefined;
|
|
50
344
|
/**
|
|
51
345
|
* Searches through all rows to find a row that matches the given criteria based on the predicate function.
|
|
346
|
+
* This method searches within the original rows array, including rows that may have been filtered out.
|
|
52
347
|
*
|
|
53
348
|
* @param {Partial<T>} criteria - A partial object containing the search criteria
|
|
54
349
|
* @param {(criteria: Partial<T>, row: T) => boolean} predicate - A function that takes the search criteria and a row,
|
|
55
350
|
* and returns true if the row matches the criteria
|
|
56
351
|
* @returns {T | undefined} The first matching row from all rows, or undefined if no match is found
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* // Find a user by ID in all rows
|
|
355
|
+
* const criteria = { id: 42 };
|
|
356
|
+
* const user = bodyAreaModel.findRowFromAllRowsByAllCriteria(
|
|
357
|
+
* criteria,
|
|
358
|
+
* (criteria, row) => row.id === criteria.id
|
|
359
|
+
* );
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* // Find a user with a specific property value in all rows
|
|
363
|
+
* const criteria = { department: 'Engineering', role: 'Manager' };
|
|
364
|
+
* const user = bodyAreaModel.findRowFromAllRowsByAllCriteria(
|
|
365
|
+
* criteria,
|
|
366
|
+
* (criteria, row) => row.department === criteria.department && row.role === criteria.role
|
|
367
|
+
* );
|
|
57
368
|
*/
|
|
58
369
|
findRowFromAllRowsByAllCriteria(criteria: Partial<T>, predicate: (criteria: Partial<T>, row: T) => boolean): T | undefined;
|
|
370
|
+
/**
|
|
371
|
+
* Returns the height of the row at the specified index.
|
|
372
|
+
* This implementation always returns the default row height.
|
|
373
|
+
* Override this method in subclasses to support variable row heights.
|
|
374
|
+
*
|
|
375
|
+
* @param {number} _rowIndex - The index of the row (unused in this implementation)
|
|
376
|
+
* @returns {number} The height of the row in pixels
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* const rowHeight = bodyAreaModel.getRowHeight(0);
|
|
380
|
+
* console.log(`The first row has a height of ${rowHeight}px`);
|
|
381
|
+
*/
|
|
59
382
|
getRowHeight(_rowIndex: number): number;
|
|
383
|
+
/**
|
|
384
|
+
* Returns the row object at the specified index from the filtered rows array.
|
|
385
|
+
* This method overrides the parent class implementation.
|
|
386
|
+
*
|
|
387
|
+
* @param {number} rowIndex - The index of the row to retrieve
|
|
388
|
+
* @returns {any} The row object at the specified index, or undefined if the index is out of bounds
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* // Get the first row object
|
|
392
|
+
* const row = bodyAreaModel.getRowByIndex(0);
|
|
393
|
+
* console.log('First row:', row);
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* // Iterate through all rows
|
|
397
|
+
* for (let i = 0; i < bodyAreaModel.getRowCount(); i++) {
|
|
398
|
+
* const row = bodyAreaModel.getRowByIndex(i);
|
|
399
|
+
* console.log(`Row ${i}:`, row);
|
|
400
|
+
* }
|
|
401
|
+
*/
|
|
60
402
|
getRowByIndex(rowIndex: number): any;
|
|
403
|
+
/**
|
|
404
|
+
* Applies an external filter function to the rows array.
|
|
405
|
+
* This method updates the filtered rows array without modifying the original rows array.
|
|
406
|
+
*
|
|
407
|
+
* @param {FilterFunction<any>} predictFn - A function that returns true for rows to keep and false for rows to filter out
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* // Filter rows where age is greater than 30
|
|
411
|
+
* bodyAreaModel.externalFilterChanged(row => row.age > 30);
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* // Filter rows based on a search term
|
|
415
|
+
* const searchTerm = 'john';
|
|
416
|
+
* bodyAreaModel.externalFilterChanged(row =>
|
|
417
|
+
* row.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
418
|
+
* );
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* // Clear all filters
|
|
422
|
+
* bodyAreaModel.externalFilterChanged(() => true);
|
|
423
|
+
*/
|
|
61
424
|
externalFilterChanged(predictFn: FilterFunction<any>): void;
|
|
425
|
+
/**
|
|
426
|
+
* Sorts the filtered rows based on the provided sort items.
|
|
427
|
+
* This method supports sorting by multiple columns with different sort directions.
|
|
428
|
+
*
|
|
429
|
+
* @param {SortItem[]} sortItems - An array of sort items, each containing a column index and sort state
|
|
430
|
+
* @returns {boolean} Always returns true to indicate sorting was performed
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* // Sort by age in ascending order
|
|
434
|
+
* bodyAreaModel.doSort([{ columnIndex: 2, sortState: 'asc' }]);
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* // Sort by name in descending order, then by age in ascending order
|
|
438
|
+
* bodyAreaModel.doSort([
|
|
439
|
+
* { columnIndex: 1, sortState: 'desc' },
|
|
440
|
+
* { columnIndex: 2, sortState: 'asc' }
|
|
441
|
+
* ]);
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* // Clear sorting
|
|
445
|
+
* bodyAreaModel.doSort([{ columnIndex: 0, sortState: 'none' }]);
|
|
446
|
+
*/
|
|
62
447
|
doSort(sortItems: SortItem[]): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Sorts the filtered rows using a custom comparator function.
|
|
450
|
+
* This method provides more flexibility than `doSort()` for complex sorting logic.
|
|
451
|
+
*
|
|
452
|
+
* @param {(a: T, b: T) => number} compareFn - A function that compares two rows and returns a number:
|
|
453
|
+
* - Negative if a should come before b
|
|
454
|
+
* - Positive if a should come after b
|
|
455
|
+
* - Zero if they are equivalent for sorting purposes
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* // Sort by name length
|
|
459
|
+
* bodyAreaModel.sort((a, b) => a.name.length - b.name.length);
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* // Sort by a computed value
|
|
463
|
+
* bodyAreaModel.sort((a, b) => {
|
|
464
|
+
* const scoreA = a.wins * 3 + a.draws;
|
|
465
|
+
* const scoreB = b.wins * 3 + b.draws;
|
|
466
|
+
* return scoreB - scoreA; // Descending order
|
|
467
|
+
* });
|
|
468
|
+
*/
|
|
63
469
|
sort(compareFn: (a: T, b: T) => number): void;
|
|
470
|
+
/**
|
|
471
|
+
* Gets a value from an object using a property path.
|
|
472
|
+
* This method supports accessing nested properties using dot notation (e.g., 'person.name').
|
|
473
|
+
*
|
|
474
|
+
* @param {T} t - The object to get the value from
|
|
475
|
+
* @param {string} property - The property path to access (e.g., 'name' or 'person.contact.email')
|
|
476
|
+
* @returns {any} The value at the specified property path, or undefined if not found
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* const user = { id: 1, name: 'John', contact: { email: 'john@example.com' } };
|
|
480
|
+
*
|
|
481
|
+
* // Access simple property
|
|
482
|
+
* const name = bodyAreaModel.getValueByT(user, 'name');
|
|
483
|
+
* console.log(name); // 'John'
|
|
484
|
+
*
|
|
485
|
+
* // Access nested property
|
|
486
|
+
* const email = bodyAreaModel.getValueByT(user, 'contact.email');
|
|
487
|
+
* console.log(email); // 'john@example.com'
|
|
488
|
+
*/
|
|
64
489
|
getValueByT(t: T, property: string): any;
|
|
490
|
+
/**
|
|
491
|
+
* Changes the order of columns by moving a column from one position to another.
|
|
492
|
+
* This method updates both the properties array and calls the parent class implementation.
|
|
493
|
+
*
|
|
494
|
+
* @param {number} sourceColumnIndex - The index of the column to move
|
|
495
|
+
* @param {number} targetColumnIndex - The index where the column should be moved to
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* // Move the second column (index 1) to the fourth position (index 3)
|
|
499
|
+
* bodyAreaModel.changeColumnOrder(1, 3);
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* // Move the last column to the first position
|
|
503
|
+
* const lastIndex = bodyAreaModel.columnDefs.length - 1;
|
|
504
|
+
* bodyAreaModel.changeColumnOrder(lastIndex, 0);
|
|
505
|
+
*/
|
|
65
506
|
changeColumnOrder(sourceColumnIndex: number, targetColumnIndex: number): void;
|
|
507
|
+
/**
|
|
508
|
+
* Gets the custom CSS classes that should be applied to a cell.
|
|
509
|
+
* This method extends the parent class implementation to add selection and focus classes.
|
|
510
|
+
*
|
|
511
|
+
* @param {number} rowIndex - The index of the row
|
|
512
|
+
* @param {number} _columnIndex - The index of the column (unused in this implementation)
|
|
513
|
+
* @returns {string[]} An array of CSS class names to apply to the cell
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* // Get the CSS classes for a cell
|
|
517
|
+
* const classes = bodyAreaModel.getCustomClassesAt(1, 2);
|
|
518
|
+
* console.log('CSS classes:', classes);
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* // Apply the classes to a cell element
|
|
522
|
+
* const cellElement = document.createElement('div');
|
|
523
|
+
* const classes = bodyAreaModel.getCustomClassesAt(rowIndex, columnIndex);
|
|
524
|
+
* cellElement.classList.add(...classes);
|
|
525
|
+
*/
|
|
66
526
|
getCustomClassesAt(rowIndex: number, _columnIndex: number): string[];
|
|
527
|
+
/**
|
|
528
|
+
* Creates a comparator function for sorting rows based on a property and sort direction.
|
|
529
|
+
* This method supports custom sort comparators defined in column definitions.
|
|
530
|
+
*
|
|
531
|
+
* @param {string} property - The property to sort by
|
|
532
|
+
* @param {number} f - The sort direction factor: 1 for ascending, -1 for descending, 0 for no sorting
|
|
533
|
+
* @returns {(a: T, b: T) => number} A comparator function that compares two rows
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* // Create a comparator for sorting by name in ascending order
|
|
537
|
+
* const comparator = bodyAreaModel.genericFlatTableSortComparator('name', 1);
|
|
538
|
+
*
|
|
539
|
+
* // Sort the rows using the comparator
|
|
540
|
+
* const sortedRows = [...bodyAreaModel.getFilteredRows()].sort(comparator);
|
|
541
|
+
*/
|
|
67
542
|
protected genericFlatTableSortComparator(property: string, f: number): (a: T, b: T) => number;
|
|
543
|
+
/**
|
|
544
|
+
* Recursively gets a value from an object using an array of property names.
|
|
545
|
+
* This is a helper method used by `getValueByT` to access nested properties.
|
|
546
|
+
*
|
|
547
|
+
* @param {any} o - The object to get the value from
|
|
548
|
+
* @param {string[]} props - An array of property names representing the path to the value
|
|
549
|
+
* @returns {any} The value at the specified property path, or undefined if not found
|
|
550
|
+
*
|
|
551
|
+
* @private
|
|
552
|
+
*/
|
|
68
553
|
private getPropertyValue;
|
|
69
554
|
}
|