@vii7/div-table-widget 1.0.1
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/LICENSE +190 -0
- package/README.md +431 -0
- package/dist/divtable.min.js +1 -0
- package/dist/editor.worker.js +1 -0
- package/dist/json.worker.js +1 -0
- package/dist/ts.worker.js +6 -0
- package/package.json +66 -0
- package/src/div-table.css +1331 -0
- package/src/div-table.js +5186 -0
- package/src/query.js +2107 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 DivTable Widget Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# DivTable Widget
|
|
2
|
+
|
|
3
|
+
A modern, flexible table widget built with CSS Grid and Flexbox instead of HTML tables, featuring Monaco Editor integration for advanced query capabilities.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Modern CSS-based Layout**: Uses CSS Grid and Flexbox for flexible, responsive design
|
|
10
|
+
- **Advanced Query Language**: Monaco Editor integration with intelligent autocomplete and syntax highlighting
|
|
11
|
+
- **Virtual Scrolling**: Efficiently handle large datasets with pagination support
|
|
12
|
+
- **Fixed (Frozen) Columns**: Keep important columns visible while scrolling horizontally
|
|
13
|
+
- **Auto-Fetch**: Automated pagination with play/pause/resume controls
|
|
14
|
+
- **Grouping & Sorting**: Multi-level grouping with 4-state sorting (alphabetical asc/desc, count asc/desc)
|
|
15
|
+
- **Selection Management**: Single and multi-row selection with checkbox support
|
|
16
|
+
- **Filter Selected Rows**: Toggle to show only selected rows
|
|
17
|
+
- **Loading States**: Configurable loading placeholders and progress indicators with visual feedback
|
|
18
|
+
- **Keyboard Navigation**: Full keyboard accessibility with arrow key navigation
|
|
19
|
+
- **Responsive Design**: Adaptive column sizing and mobile-friendly layout
|
|
20
|
+
- **Composite Columns**: Stack multiple fields in one column or create two-line headers
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install divtable-widget monaco-editor
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
### Basic Usage
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<!DOCTYPE html>
|
|
34
|
+
<html>
|
|
35
|
+
<head>
|
|
36
|
+
<link rel="stylesheet" href="node_modules/divtable-widget/src/div-table.css">
|
|
37
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/loader.min.js"></script>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
<div id="table-container"></div>
|
|
41
|
+
|
|
42
|
+
<script src="node_modules/divtable-widget/src/query.js"></script>
|
|
43
|
+
<script src="node_modules/divtable-widget/src/div-table.js"></script>
|
|
44
|
+
<script>
|
|
45
|
+
// Initialize Monaco Editor
|
|
46
|
+
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs' }});
|
|
47
|
+
require(['vs/editor/editor.main'], function() {
|
|
48
|
+
const divTable = new DivTable(monaco, {
|
|
49
|
+
tableWidgetElement: document.getElementById('table-container'),
|
|
50
|
+
columns: [
|
|
51
|
+
{ field: 'id', header: 'ID', primaryKey: true },
|
|
52
|
+
{ field: 'name', header: 'Name' },
|
|
53
|
+
{ field: 'email', header: 'Email' },
|
|
54
|
+
{ field: 'status', header: 'Status' }
|
|
55
|
+
],
|
|
56
|
+
data: [
|
|
57
|
+
{ id: 1, name: 'John Doe', email: 'john@example.com', status: 'active' },
|
|
58
|
+
{ id: 2, name: 'Jane Smith', email: 'jane@example.com', status: 'inactive' }
|
|
59
|
+
],
|
|
60
|
+
// New: Set initial grouping and sorting
|
|
61
|
+
group: 'status', // Group by 'status' field on load
|
|
62
|
+
sort: { field: 'name', direction: 'asc' }, // Sort by 'name' ascending on load
|
|
63
|
+
showCheckboxes: true,
|
|
64
|
+
multiSelect: true,
|
|
65
|
+
onSelectionChange: (selectedRows) => {
|
|
66
|
+
console.log('Selected:', selectedRows);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
</script>
|
|
71
|
+
</body>
|
|
72
|
+
</html>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### With Virtual Scrolling
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
const divTable = new DivTable(monaco, {
|
|
79
|
+
tableWidgetElement: document.getElementById('table-container'),
|
|
80
|
+
columns: [
|
|
81
|
+
{ field: 'id', header: 'ID', primaryKey: true },
|
|
82
|
+
{ field: 'name', header: 'Name' },
|
|
83
|
+
{ field: 'age', header: 'Age' }
|
|
84
|
+
],
|
|
85
|
+
virtualScrolling: true,
|
|
86
|
+
pageSize: 100,
|
|
87
|
+
totalRecords: 10000,
|
|
88
|
+
showAutoFetchButton: true,
|
|
89
|
+
autoFetchDelay: 500,
|
|
90
|
+
onNextPage: async () => {
|
|
91
|
+
const nextPage = await fetchDataFromServer(currentPage + 1);
|
|
92
|
+
divTable.appendData(nextPage);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Configuration Options
|
|
98
|
+
|
|
99
|
+
### Core Options
|
|
100
|
+
|
|
101
|
+
| Option | Type | Default | Description |
|
|
102
|
+
|--------|------|---------|-------------|
|
|
103
|
+
| `tableWidgetElement` | HTMLElement | **required** | Container element for the table |
|
|
104
|
+
| `columns` | Array | **required** | Column definitions (see Column Configuration) |
|
|
105
|
+
| `data` | Array | `[]` | Initial data array. If not provided and `onNextPage` is available, first page will be loaded automatically |
|
|
106
|
+
| `showCheckboxes` | Boolean | `true` | Show selection checkboxes |
|
|
107
|
+
| `multiSelect` | Boolean | `true` | Allow multiple row selection |
|
|
108
|
+
| `primaryKeyField` | String | `'id'` | Field to use as primary key (auto-detected from columns if not specified) |
|
|
109
|
+
| `group` | String | `null` | Field to group by initially (applies grouping on load) |
|
|
110
|
+
| `sort` | Object | `null` | Initial sort: `{ field: string, direction: 'asc'|'desc' }` |
|
|
111
|
+
| `fixedColumns` | Number | `0` | Number of columns to freeze on the left side when scrolling horizontally |
|
|
112
|
+
|
|
113
|
+
### Virtual Scrolling Options
|
|
114
|
+
|
|
115
|
+
| Option | Type | Default | Description |
|
|
116
|
+
|--------|------|---------|-------------|
|
|
117
|
+
| `virtualScrolling` | Boolean | `false` | Enable virtual scrolling mode for large datasets |
|
|
118
|
+
| `pageSize` | Number | `100` | Number of rows per page |
|
|
119
|
+
| `totalRecords` | Number | `pageSize * 10` | Total number of records available (for progress calculation) |
|
|
120
|
+
| `loadingThreshold` | Number | `pageSize * 0.8` | Trigger loading when this many rows from end |
|
|
121
|
+
| `scrollThreshold` | Number | `0.95` | Fallback percentage-based scroll threshold |
|
|
122
|
+
| `showAutoFetchButton` | Boolean | `true` | Show auto-fetch play/pause/resume button |
|
|
123
|
+
| `autoFetchDelay` | Number | `500` | Delay between auto-fetch requests (milliseconds) |
|
|
124
|
+
|
|
125
|
+
### UI Options
|
|
126
|
+
|
|
127
|
+
| Option | Type | Default | Description |
|
|
128
|
+
|--------|------|---------|-------------|
|
|
129
|
+
| `showLoadingPlaceholder` | Boolean | `true` | Show loading skeleton when no data is present |
|
|
130
|
+
| `showRefreshButton` | Boolean | `false` | Show refresh button in info section |
|
|
131
|
+
|
|
132
|
+
### Callbacks
|
|
133
|
+
|
|
134
|
+
| Option | Type | Parameters | Description |
|
|
135
|
+
|--------|------|------------|-------------|
|
|
136
|
+
| `onSelectionChange` | Function | `(selectedRows)` | Called when row selection changes. Receives array of selected data objects |
|
|
137
|
+
| `onRowFocus` | Function | `(rowData, groupInfo)` | Called when a row or group header receives focus |
|
|
138
|
+
| `onNextPage` | Function | `(page, pageSize)` | Called to load next page of data. Should return array of records or Promise |
|
|
139
|
+
| `onPreviousPage` | Function | `(page, pageSize)` | Called to load previous page (optional) |
|
|
140
|
+
| `onRefresh` | Function | `()` | Called when refresh button is clicked. Should reload data |
|
|
141
|
+
|
|
142
|
+
## Query Language
|
|
143
|
+
|
|
144
|
+
The widget includes a powerful query language with Monaco Editor integration:
|
|
145
|
+
|
|
146
|
+
### Syntax
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
field operator value [AND/OR field operator value]
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Operators
|
|
153
|
+
|
|
154
|
+
- `=` - Equals
|
|
155
|
+
- `!=` - Not equals
|
|
156
|
+
- `>` - Greater than
|
|
157
|
+
- `<` - Less than
|
|
158
|
+
- `>=` - Greater than or equal
|
|
159
|
+
- `<=` - Less than or equal
|
|
160
|
+
- `CONTAINS` - String contains (case-insensitive)
|
|
161
|
+
- `STARTS_WITH` - String starts with
|
|
162
|
+
- `ENDS_WITH` - String ends with
|
|
163
|
+
- `IN` - Value in list: `status IN (active, pending)`
|
|
164
|
+
- `BETWEEN` - Value in range: `age BETWEEN (18, 65)`
|
|
165
|
+
|
|
166
|
+
### Examples
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
status = "active"
|
|
170
|
+
age > 18 AND status = "active"
|
|
171
|
+
name CONTAINS "John"
|
|
172
|
+
created_at BETWEEN (2024-01-01, 2024-12-31)
|
|
173
|
+
status IN (active, pending, review)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Keyboard Navigation
|
|
177
|
+
|
|
178
|
+
The widget provides full keyboard accessibility:
|
|
179
|
+
|
|
180
|
+
### Navigation Keys
|
|
181
|
+
|
|
182
|
+
| Key | Action |
|
|
183
|
+
|-----|--------|
|
|
184
|
+
| `↑` / `↓` | Navigate between rows and group headers |
|
|
185
|
+
| `→` | Expand collapsed group (when focused on group header) |
|
|
186
|
+
| `←` | Collapse expanded group (when focused on group header) |
|
|
187
|
+
| `Space` / `Enter` | Toggle selection of focused row or group |
|
|
188
|
+
| `Tab` | Navigate between checkboxes (if enabled) |
|
|
189
|
+
|
|
190
|
+
### Focus Behavior
|
|
191
|
+
|
|
192
|
+
- When checkboxes are enabled, focus moves to the checkbox element
|
|
193
|
+
- When checkboxes are disabled, focus moves to the row element
|
|
194
|
+
- Group headers are always focusable and can be expanded/collapsed with arrow keys
|
|
195
|
+
- Selection changes trigger the `onSelectionChange` callback
|
|
196
|
+
- Focus changes trigger the `onRowFocus` callback
|
|
197
|
+
|
|
198
|
+
## API Methods
|
|
199
|
+
|
|
200
|
+
### Data Management
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
// Apply a query filter to the data
|
|
204
|
+
divTable.applyQuery('status = "active" AND age > 18');
|
|
205
|
+
|
|
206
|
+
// Add a single record (upsert - updates if exists, adds if new)
|
|
207
|
+
divTable.addRecord({ id: 1, name: 'John Doe', email: 'john@example.com' });
|
|
208
|
+
|
|
209
|
+
// Remove a record by ID
|
|
210
|
+
const removedRecord = divTable.removeRecord(1);
|
|
211
|
+
|
|
212
|
+
// Refresh the table data (reloads from onNextPage if virtual scrolling)
|
|
213
|
+
await divTable.refresh();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Selection
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
// Get selected rows (returns array of data objects)
|
|
220
|
+
const selected = divTable.getSelectedRows();
|
|
221
|
+
|
|
222
|
+
// Toggle filter to show only selected rows
|
|
223
|
+
divTable.toggleSelectedRowsFilter(true); // Show only selected
|
|
224
|
+
divTable.toggleSelectedRowsFilter(false); // Show all rows
|
|
225
|
+
divTable.toggleSelectedRowsFilter(); // Toggle current state
|
|
226
|
+
|
|
227
|
+
// Clear all selections
|
|
228
|
+
divTable.clearSelection();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Grouping and Sorting
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
// Group by a field
|
|
235
|
+
divTable.group('category');
|
|
236
|
+
|
|
237
|
+
// Clear grouping
|
|
238
|
+
divTable.clearGrouping();
|
|
239
|
+
|
|
240
|
+
// Sort by a field
|
|
241
|
+
divTable.sort('name', 'asc'); // 'asc' or 'desc'
|
|
242
|
+
divTable.sort('age'); // Toggles between asc/desc
|
|
243
|
+
|
|
244
|
+
// For grouped fields, sorting cycles through 4 states:
|
|
245
|
+
// 1. Sort groups alphabetically ascending (↑ₐ)
|
|
246
|
+
// 2. Sort groups alphabetically descending (↓z)
|
|
247
|
+
// 3. Sort groups by count ascending (↑₁)
|
|
248
|
+
// 4. Sort groups by count descending (↓₉)
|
|
249
|
+
// 5. Back to no sort
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Auto-Fetch Controls
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
// The auto-fetch feature automatically loads pages with play/pause/resume controls
|
|
256
|
+
// These methods are called internally by the UI buttons, but can also be called programmatically:
|
|
257
|
+
|
|
258
|
+
// Start auto-fetching all pages
|
|
259
|
+
divTable.startAutoFetch();
|
|
260
|
+
|
|
261
|
+
// Stop auto-fetching
|
|
262
|
+
divTable.stopAutoFetch();
|
|
263
|
+
|
|
264
|
+
// Note: Pause/resume is handled automatically by the UI button
|
|
265
|
+
// The isAutoFetching and autoFetchPaused properties track the state
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Fixed (Frozen) Columns
|
|
269
|
+
|
|
270
|
+
Keep the first N columns fixed (frozen) on the left side while scrolling horizontally:
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
const divTable = new DivTable(monaco, {
|
|
274
|
+
tableWidgetElement: document.getElementById('table-container'),
|
|
275
|
+
columns: [
|
|
276
|
+
{ field: 'id', header: 'ID', primaryKey: true },
|
|
277
|
+
{ field: 'name', header: 'Name' },
|
|
278
|
+
{ field: 'email', header: 'Email' },
|
|
279
|
+
{ field: 'department', header: 'Department' },
|
|
280
|
+
{ field: 'status', header: 'Status' }
|
|
281
|
+
],
|
|
282
|
+
data: myData,
|
|
283
|
+
fixedColumns: 2 // Freeze first 2 columns (ID and Name)
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**How it works:**
|
|
288
|
+
|
|
289
|
+
- The first N data columns stay fixed on the left side
|
|
290
|
+
- Remaining columns scroll horizontally
|
|
291
|
+
- Vertical scrolling is synchronized between fixed and scrollable sections
|
|
292
|
+
- Checkbox column (if enabled) is always part of the fixed section
|
|
293
|
+
- Works with composite columns - each composite group counts as one column
|
|
294
|
+
|
|
295
|
+
## Column Configuration
|
|
296
|
+
|
|
297
|
+
### Basic Column
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
{
|
|
301
|
+
field: 'name', // Data field name (required)
|
|
302
|
+
label: 'Full Name', // Display header (optional, defaults to field)
|
|
303
|
+
primaryKey: false, // Is this the primary key? (required for one column)
|
|
304
|
+
hidden: false, // Hide column (default: false)
|
|
305
|
+
groupable: true, // Allow grouping by this column (default: true)
|
|
306
|
+
render: (value, item) => `<strong>${value}</strong>` // Custom render function
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Advanced Column Features
|
|
311
|
+
|
|
312
|
+
#### Responsive Sizing
|
|
313
|
+
|
|
314
|
+
```javascript
|
|
315
|
+
{
|
|
316
|
+
field: 'description',
|
|
317
|
+
label: 'Description',
|
|
318
|
+
responsive: {
|
|
319
|
+
size: 'flexible-large' // 'fixed-narrow' (80px), 'fixed-medium' (120px),
|
|
320
|
+
// 'flexible-small' (1fr), 'flexible-medium' (2fr),
|
|
321
|
+
// 'flexible-large' (3fr)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### Composite Cells (Multiple Fields in One Column)
|
|
327
|
+
|
|
328
|
+
Use `fieldCompositeName` to stack multiple columns into a single visual cell:
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
// Stack name and age fields vertically in one column
|
|
332
|
+
{
|
|
333
|
+
field: 'name',
|
|
334
|
+
label: 'Name',
|
|
335
|
+
fieldCompositeName: 'person'
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
field: 'age',
|
|
339
|
+
label: 'Age',
|
|
340
|
+
render: (value) => value ? `${value} years old` : 'Age not specified',
|
|
341
|
+
fieldCompositeName: 'person'
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Each field in a composite cell:
|
|
346
|
+
|
|
347
|
+
- Has its own label in the header (stacked vertically)
|
|
348
|
+
- Can have its own render function
|
|
349
|
+
- Can be sorted independently by clicking on its label
|
|
350
|
+
- Can be grouped if `groupable: true`
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
### Column Render Function
|
|
355
|
+
|
|
356
|
+
Custom rendering for cell values:
|
|
357
|
+
|
|
358
|
+
```javascript
|
|
359
|
+
{
|
|
360
|
+
field: 'status',
|
|
361
|
+
label: 'Status',
|
|
362
|
+
render: (value, item) => {
|
|
363
|
+
const colors = { active: 'green', inactive: 'red', pending: 'orange' };
|
|
364
|
+
return `<span style="color: ${colors[value]}">${value}</span>`;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Column Types
|
|
370
|
+
|
|
371
|
+
The widget automatically detects and handles different data types based on the data:
|
|
372
|
+
|
|
373
|
+
- **Strings**: Text data with CONTAINS, STARTS_WITH, ENDS_WITH operators
|
|
374
|
+
- **Numbers**: Numeric data with comparison operators (>, <, >=, <=)
|
|
375
|
+
- **Dates**: Date/time values with BETWEEN operator
|
|
376
|
+
- **Booleans**: True/false values with = operator
|
|
377
|
+
- **Arrays**: Array values are joined with commas for display
|
|
378
|
+
|
|
379
|
+
## Styling
|
|
380
|
+
|
|
381
|
+
The widget uses CSS variables for easy customization:
|
|
382
|
+
|
|
383
|
+
```css
|
|
384
|
+
.div-table-widget {
|
|
385
|
+
--table-border-color: #e0e0e0;
|
|
386
|
+
--header-bg-color: #f5f5f5;
|
|
387
|
+
--row-hover-color: #f9f9f9;
|
|
388
|
+
--selected-row-color: #e3f2fd;
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Browser Support
|
|
393
|
+
|
|
394
|
+
- Chrome/Edge: Latest 2 versions
|
|
395
|
+
- Firefox: Latest 2 versions
|
|
396
|
+
- Safari: Latest 2 versions
|
|
397
|
+
|
|
398
|
+
## License
|
|
399
|
+
|
|
400
|
+
Apache License 2.0
|
|
401
|
+
|
|
402
|
+
Copyright 2025 DivTable Widget Contributors
|
|
403
|
+
|
|
404
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
405
|
+
you may not use this file except in compliance with the License.
|
|
406
|
+
You may obtain a copy of the License at
|
|
407
|
+
|
|
408
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
409
|
+
|
|
410
|
+
Unless required by applicable law or agreed to in writing, software
|
|
411
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
412
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
413
|
+
See the License for the specific language governing permissions and
|
|
414
|
+
limitations under the License.
|
|
415
|
+
|
|
416
|
+
## Contributing
|
|
417
|
+
|
|
418
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
419
|
+
|
|
420
|
+
## Changelog
|
|
421
|
+
|
|
422
|
+
### Version 1.0.0
|
|
423
|
+
|
|
424
|
+
- Initial release
|
|
425
|
+
- Core table functionality with CSS Grid/Flexbox layout
|
|
426
|
+
- Monaco Editor integration for query language
|
|
427
|
+
- Virtual scrolling support
|
|
428
|
+
- Auto-fetch pagination
|
|
429
|
+
- Grouping and sorting
|
|
430
|
+
- Selection management
|
|
431
|
+
- Keyboard navigation
|