@teipublisher/pb-components 3.1.0 → 3.2.0
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/CHANGELOG.md +8 -0
- package/dist/demo/pb-table-grid2.html +15 -0
- package/dist/pb-components-bundle.js +117 -114
- package/dist/pb-elements.json +11 -0
- package/package.json +1 -1
- package/pb-elements.json +11 -0
- package/src/pb-table-grid.js +101 -5
package/dist/pb-elements.json
CHANGED
|
@@ -10924,6 +10924,11 @@
|
|
|
10924
10924
|
"name": "height",
|
|
10925
10925
|
"type": "string"
|
|
10926
10926
|
},
|
|
10927
|
+
{
|
|
10928
|
+
"name": "visible-columns",
|
|
10929
|
+
"description": "Optional list of column ids/properties to show. If empty or undefined, all columns are visible.",
|
|
10930
|
+
"type": "array"
|
|
10931
|
+
},
|
|
10927
10932
|
{
|
|
10928
10933
|
"name": "subscribe",
|
|
10929
10934
|
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
@@ -11012,6 +11017,12 @@
|
|
|
11012
11017
|
"type": "boolean",
|
|
11013
11018
|
"default": "false"
|
|
11014
11019
|
},
|
|
11020
|
+
{
|
|
11021
|
+
"name": "visibleColumns",
|
|
11022
|
+
"attribute": "visible-columns",
|
|
11023
|
+
"description": "Optional list of column ids/properties to show. If empty or undefined, all columns are visible.",
|
|
11024
|
+
"type": "array"
|
|
11025
|
+
},
|
|
11015
11026
|
{
|
|
11016
11027
|
"name": "subscribe",
|
|
11017
11028
|
"attribute": "subscribe",
|
package/package.json
CHANGED
package/pb-elements.json
CHANGED
|
@@ -10924,6 +10924,11 @@
|
|
|
10924
10924
|
"name": "height",
|
|
10925
10925
|
"type": "string"
|
|
10926
10926
|
},
|
|
10927
|
+
{
|
|
10928
|
+
"name": "visible-columns",
|
|
10929
|
+
"description": "Optional list of column ids/properties to show. If empty or undefined, all columns are visible.",
|
|
10930
|
+
"type": "array"
|
|
10931
|
+
},
|
|
10927
10932
|
{
|
|
10928
10933
|
"name": "subscribe",
|
|
10929
10934
|
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
@@ -11012,6 +11017,12 @@
|
|
|
11012
11017
|
"type": "boolean",
|
|
11013
11018
|
"default": "false"
|
|
11014
11019
|
},
|
|
11020
|
+
{
|
|
11021
|
+
"name": "visibleColumns",
|
|
11022
|
+
"attribute": "visible-columns",
|
|
11023
|
+
"description": "Optional list of column ids/properties to show. If empty or undefined, all columns are visible.",
|
|
11024
|
+
"type": "array"
|
|
11025
|
+
},
|
|
11015
11026
|
{
|
|
11016
11027
|
"name": "subscribe",
|
|
11017
11028
|
"attribute": "subscribe",
|
package/src/pb-table-grid.js
CHANGED
|
@@ -86,6 +86,13 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
86
86
|
type: Boolean,
|
|
87
87
|
attribute: 'pagination-top',
|
|
88
88
|
},
|
|
89
|
+
/**
|
|
90
|
+
* Optional list of column ids/properties to show. If empty or undefined, all columns are visible.
|
|
91
|
+
*/
|
|
92
|
+
visibleColumns: {
|
|
93
|
+
type: Array,
|
|
94
|
+
attribute: 'visible-columns',
|
|
95
|
+
},
|
|
89
96
|
_params: {
|
|
90
97
|
type: Object,
|
|
91
98
|
},
|
|
@@ -103,10 +110,17 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
103
110
|
this.perPage = 10;
|
|
104
111
|
this.height = null;
|
|
105
112
|
this.fixedHeader = false;
|
|
113
|
+
this.visibleColumns = null;
|
|
114
|
+
this._pbColumns = [];
|
|
115
|
+
this._columns = [];
|
|
116
|
+
this._selectedRow = null;
|
|
117
|
+
this._onTableClick = this._onTableClick.bind(this);
|
|
118
|
+
this._onDocumentClick = this._onDocumentClick.bind(this);
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
async connectedCallback() {
|
|
109
122
|
super.connectedCallback();
|
|
123
|
+
document.addEventListener('click', this._onDocumentClick);
|
|
110
124
|
|
|
111
125
|
this.subscribeTo('pb-search-resubmit', ev => {
|
|
112
126
|
this._submit();
|
|
@@ -151,12 +165,17 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
151
165
|
this.shadowRoot.adoptedStyleSheets = sheets;
|
|
152
166
|
}
|
|
153
167
|
|
|
168
|
+
disconnectedCallback() {
|
|
169
|
+
document.removeEventListener('click', this._onDocumentClick);
|
|
170
|
+
super.disconnectedCallback();
|
|
171
|
+
}
|
|
172
|
+
|
|
154
173
|
firstUpdated() {
|
|
155
174
|
const table = this.shadowRoot.getElementById('table');
|
|
175
|
+
table.addEventListener('click', this._onTableClick);
|
|
156
176
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
pbColumns.forEach(column => columns.push(column.data()));
|
|
177
|
+
this._pbColumns = Array.from(this.querySelectorAll('pb-table-column'));
|
|
178
|
+
this._columns = this._getColumnsConfig();
|
|
160
179
|
waitOnce('pb-page-ready', data => {
|
|
161
180
|
if (data && data.language) {
|
|
162
181
|
this.language = data.language;
|
|
@@ -166,7 +185,7 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
166
185
|
const config = {
|
|
167
186
|
height: this.height,
|
|
168
187
|
fixedHeader: true,
|
|
169
|
-
columns,
|
|
188
|
+
columns: this._columns,
|
|
170
189
|
resizable: this.resizable,
|
|
171
190
|
server: {
|
|
172
191
|
url,
|
|
@@ -181,7 +200,7 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
181
200
|
if (!cols.length) return prev;
|
|
182
201
|
const col = cols[0];
|
|
183
202
|
return `${prev}${prev.indexOf('?') > -1 ? '&' : '?'}order=${
|
|
184
|
-
|
|
203
|
+
this._columns[col.index].id
|
|
185
204
|
}&dir=${col.direction === 1 ? 'asc' : 'desc'}`;
|
|
186
205
|
},
|
|
187
206
|
},
|
|
@@ -223,15 +242,89 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
223
242
|
this.grid.plugin.get('pagination').position = PluginPosition.Header;
|
|
224
243
|
}
|
|
225
244
|
this.grid.on('load', () => {
|
|
245
|
+
this._clearRowSelection();
|
|
226
246
|
this.emitTo('pb-results-received', {
|
|
227
247
|
params: this._params,
|
|
228
248
|
});
|
|
249
|
+
this._applyColumnVisibilityToDom();
|
|
229
250
|
});
|
|
230
251
|
|
|
231
252
|
this.grid.render(table);
|
|
232
253
|
});
|
|
233
254
|
}
|
|
234
255
|
|
|
256
|
+
updated(changedProperties) {
|
|
257
|
+
if (changedProperties.has('visibleColumns') && this.grid) {
|
|
258
|
+
this._columns = this._getColumnsConfig();
|
|
259
|
+
this._applyColumnVisibilityToDom();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_visibleColumnsAsSet() {
|
|
264
|
+
return Array.isArray(this.visibleColumns) ? new Set(this.visibleColumns) : null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
_columnId(pbColumn, config) {
|
|
268
|
+
return config.id || pbColumn.property || pbColumn.label;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
_getColumnsConfig() {
|
|
272
|
+
const visibleSet = this._visibleColumnsAsSet();
|
|
273
|
+
return this._pbColumns.map(pbColumn => {
|
|
274
|
+
const config = pbColumn.data();
|
|
275
|
+
const id = this._columnId(pbColumn, config);
|
|
276
|
+
return visibleSet ? { ...config, hidden: !visibleSet.has(id) } : config;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
_applyColumnVisibilityToDom() {
|
|
281
|
+
const visibleSet = this._visibleColumnsAsSet();
|
|
282
|
+
const table = this.shadowRoot.querySelector('.gridjs-table');
|
|
283
|
+
if (!table) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this._columns.forEach((column, index) => {
|
|
287
|
+
const id = column.id || this._pbColumns[index]?.property || this._pbColumns[index]?.label;
|
|
288
|
+
const hidden = visibleSet ? !visibleSet.has(id) : false;
|
|
289
|
+
const cells = table.querySelectorAll(`th:nth-child(${index + 1}), td:nth-child(${index + 1})`);
|
|
290
|
+
cells.forEach(cell => {
|
|
291
|
+
cell.style.display = hidden ? 'none' : '';
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
_onTableClick(event) {
|
|
297
|
+
const row = event.target.closest('tbody tr');
|
|
298
|
+
if (!row) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this._toggleRowSelection(row);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
_onDocumentClick(event) {
|
|
305
|
+
const path = event.composedPath();
|
|
306
|
+
if (!path.includes(this)) {
|
|
307
|
+
this._clearRowSelection();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
_toggleRowSelection(row) {
|
|
312
|
+
if (this._selectedRow === row) {
|
|
313
|
+
this._clearRowSelection();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
this._clearRowSelection();
|
|
317
|
+
this._selectedRow = row;
|
|
318
|
+
this._selectedRow.classList.add('grid-row-selected');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
_clearRowSelection() {
|
|
322
|
+
if (this._selectedRow) {
|
|
323
|
+
this._selectedRow.classList.remove('grid-row-selected');
|
|
324
|
+
this._selectedRow = null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
235
328
|
_submit() {
|
|
236
329
|
this.grid.forceRender();
|
|
237
330
|
}
|
|
@@ -279,6 +372,9 @@ export class PbTableGrid extends themableMixin(pbMixin(LitElement)) {
|
|
|
279
372
|
:host {
|
|
280
373
|
display: block;
|
|
281
374
|
}
|
|
375
|
+
.grid-row-selected td.gridjs-td {
|
|
376
|
+
background-color: var(--pb-table-grid-selected-row-background-color, #e8f0fe);
|
|
377
|
+
}
|
|
282
378
|
button {
|
|
283
379
|
border: 0;
|
|
284
380
|
}
|