@cdmx/wappler_ag_grid 0.1.2 → 0.1.4

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.
@@ -18,6 +18,11 @@
18
18
  "title": "Id",
19
19
  "type": "number"
20
20
  },
21
+ {
22
+ "name": "data",
23
+ "title": "Data",
24
+ "type": "object"
25
+ }
21
26
  {
22
27
  "name": "fields",
23
28
  "title": "Fields",
@@ -362,15 +367,15 @@
362
367
  {
363
368
  "name": "rowCheckboxEvent",
364
369
  "attribute": "dmx-bind:row_checkbox_event",
365
- "title": "Row Checkbox Events",
370
+ "title": "Enable Row Selection",
366
371
  "type": "boolean",
367
372
  "defaultValue": false,
368
- "help": "This enabled row checkbox events which can then be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked"
373
+ "help": "This enables row selection which can then be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked"
369
374
  },
370
375
  {
371
376
  "name": "rowStatusEvent",
372
377
  "attribute": "dmx-bind:row_status_event",
373
- "title": "Row Status Events",
378
+ "title": "Enable Row Status Toggle",
374
379
  "type": "boolean",
375
380
  "defaultValue": false,
376
381
  "help": "This enabled row status events which can then be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked"
@@ -486,7 +491,6 @@
486
491
  {
487
492
  "field": "field",
488
493
  "caption": "Field",
489
- "size": "10%",
490
494
  "editable": {
491
495
  "type": "text"
492
496
  }
@@ -494,7 +498,6 @@
494
498
  {
495
499
  "field": "value",
496
500
  "caption": "Value",
497
- "size": "10%",
498
501
  "editable": {
499
502
  "type": "text"
500
503
  }
@@ -502,7 +505,6 @@
502
505
  {
503
506
  field: "new_value",
504
507
  caption: "New Value",
505
- size: "10%",
506
508
  editable: {
507
509
  type: "text"
508
510
  }
package/dmx-ag-grid.js CHANGED
@@ -1,7 +1,8 @@
1
1
  dmx.Component('ag-grid', {
2
2
  initialData: {
3
3
  id: null,
4
- rowData: [],
4
+ data: {},
5
+ fields: {},
5
6
  column_defs: [],
6
7
  cstyles: null,
7
8
  cnames: null,
@@ -39,8 +40,7 @@ dmx.Component('ag-grid', {
39
40
  fixedHeaderOffset: 100,
40
41
  fixedTopOffset: 80,
41
42
  fixedHorizonatalScroll: false,
42
- timezone: null,
43
- fields: {}
43
+ timezone: null
44
44
  },
45
45
 
46
46
  attributes: {
@@ -85,6 +85,7 @@ dmx.Component('ag-grid', {
85
85
  fixedTopOffset: { type: Number, default: 80 },
86
86
  fixedHorizonatalScroll: { type: Boolean, default: false },
87
87
  timezone: {type: Text, default: '' },
88
+ cell_click_event: {type: Boolean, default: false },
88
89
  row_click_event: {type: Boolean, default: false },
89
90
  row_checkbox_event: {type: Boolean, default: false },
90
91
  row_status_event: {type: Boolean, default: false }
@@ -138,10 +139,10 @@ dmx.Component('ag-grid', {
138
139
  return blankOrNullValueFormatter(params);
139
140
  }
140
141
  }
141
- window.clickEvent = (columnName, value, idValue) => {
142
+ window.cellClickEvent = (columnName, value, idValue) => {
142
143
  this.set('fields', {"field": columnName, "data": value});
143
144
  this.set('id', idValue);
144
- this.dispatchEvent('row_clicked')
145
+ this.dispatchEvent('cell_clicked')
145
146
  };
146
147
  window.handleCheckboxClick = (event, columnName, value, idValue) => {
147
148
  const isChecked = event.target.checked;
@@ -176,22 +177,28 @@ dmx.Component('ag-grid', {
176
177
  const columnName = params.colDef.field;
177
178
  const dataType = detectDataType([params.value]);
178
179
  const value = formatValue(params.value, columnName, dataType, timezone);
179
- return `<div onclick="clickEvent('${columnName}', '${value}', '${idValue}')" style="cursor: pointer;">${value}</div>`;
180
+ return `<div onclick="cellClickEvent('${columnName}', '${value}', '${idValue}')" style="cursor: pointer;">${value}</div>`;
180
181
  }
181
- function checkboxCellRenderer(params) {
182
+ function idCheckboxCellRenderer(params) {
182
183
  const idValue = params.data.id;
183
184
  const columnName = params.colDef.field;
184
185
  const dataType = detectDataType([params.value]);
185
186
  const value = formatValue(params.value, columnName, dataType, timezone);
186
-
187
- if (columnName === "id") {
188
- return `
187
+ return `
189
188
  <input
190
189
  type="checkbox"
191
190
  onclick="handleCheckboxClick(event, '${columnName}', '${value}', '${idValue}')"
192
191
  />
193
192
  `;
194
- } else if (columnName == "status" && enableStatusToggle) {
193
+ }
194
+
195
+ function checkboxCellRenderer(params) {
196
+ const idValue = params.data.id;
197
+ const columnName = params.colDef.field;
198
+ const dataType = detectDataType([params.value]);
199
+ const value = formatValue(params.value, columnName, dataType, timezone);
200
+
201
+ if (columnName == "status" && enableStatusToggle) {
195
202
  // Assuming `value` is a boolean representing the status
196
203
  const checked = value==true ? "checked" : "";
197
204
  return `
@@ -389,24 +396,24 @@ dmx.Component('ag-grid', {
389
396
  return false;
390
397
  }
391
398
  }
392
- const cstyles = this.props.cstyles
393
- // Check if custom color exists for the current field and condition
394
- function applyCellStyle(params) {
395
- const field = params.colDef.field.toString();
396
- if (cstyles.hasOwnProperty(field)) {
397
- const condition = cstyles[field].condition;
398
- const customColor = cstyles[field].customColor;
399
- const [left, operator, right] = extractConditionParts(condition);
400
- // Check if the field exists and its value is true
401
- if (params.data.hasOwnProperty(field) && evaluateCondition(params.data[left], operator, right)) {
402
- return { color: customColor };
403
- }
404
- }
405
- return null;
406
- }
399
+ const cstyles = this.props.cstyles
400
+ // Check if custom color exists for the current field and condition
401
+ function applyCellStyle(params) {
402
+ const field = params.colDef.field.toString();
403
+ if (cstyles.hasOwnProperty(field)) {
404
+ const condition = cstyles[field].condition;
405
+ const customColor = cstyles[field].customColor;
406
+ const [left, operator, right] = extractConditionParts(condition);
407
+ if (params.data.hasOwnProperty(field) && evaluateCondition(params.data[left], operator, right)) {
408
+ return { color: customColor };
409
+ }
410
+ }
411
+ return null;
412
+ }
407
413
  cnames = this.props.cnames
408
414
  cwidths = this.props.cwidths
409
- enableClickEvent = this.props.row_click_event;
415
+ enableRowClickEvent = this.props.row_click_event;
416
+ enableCellClickEvent = this.props.cell_click_event;
410
417
  if (cnames.hasOwnProperty(key)) {
411
418
  console.log(key)
412
419
  const cname = cnames[key]
@@ -427,12 +434,61 @@ const cstyles = this.props.cstyles
427
434
  minWidth: parseInt(cwidths[key].min_width),
428
435
  maxWidth: parseInt(cwidths[key].max_width),
429
436
  }),
430
- cellRenderer: enableClickEvent ? 'clickCellRenderer' : (enableCheckboxEvent ? 'checkboxCellRenderer' : undefined)
437
+ cellRenderer: enableCellClickEvent ? 'clickCellRenderer' : (enableStatusToggle ? 'checkboxCellRenderer' : undefined)
431
438
  };
432
439
  });
433
440
  }
441
+ let checkboxColumn;
442
+ function headerCheckbox(params) {
443
+ const eHeaderCheckbox = document.createElement('input');
444
+ eHeaderCheckbox.type = 'checkbox';
445
+ eHeaderCheckbox.addEventListener('change', () => {
446
+ const columnName = params.colDef.field;
447
+ const value = params.value;
448
+
449
+ params.api.forEachNode((node) => {
450
+ if (node.rowPinned) return; // Skip pinned rows
451
+ if (node.visible) {
452
+ const idValue = node.data.id;
453
+ cellClickEvent(columnName, value, idValue);
454
+ node.setSelected(eHeaderCheckbox.checked);
455
+ }
456
+ });
457
+ });
458
+
459
+ const eLabel = document.createElement('label');
460
+ eLabel.appendChild(eHeaderCheckbox);
461
+ eLabel.appendChild(document.createTextNode('Select All'));
462
+
463
+ return eLabel;
464
+ }
465
+ if (enableCheckboxEvent) {
466
+ checkboxColumn = {
467
+ headerCheckboxSelection: true,
468
+ headerCheckboxSelectionFilteredOnly: false,
469
+ headerName: '',
470
+ field: 'id',
471
+ filter: '',
472
+ cellRenderer: 'idCheckboxCellRenderer',
473
+ resizable: false,
474
+ width: 50,
475
+ maxWidth: 50,
476
+ suppressMenu: true,
477
+ // headerComponent: 'headerCheckbox'
478
+ };
479
+ columnDefs.unshift(checkboxColumn);
480
+ }
481
+ window.onRowClicked = (event) => {
482
+ const rowData = event.data;
483
+ this.set('data', rowData);
484
+ this.set('id', rowData.id);
485
+ this.dispatchEvent('row_clicked')
486
+ }
487
+
434
488
  const gridOptions = {
435
489
  columnDefs: columnDefs,
490
+ onRowClicked: enableRowClickEvent ? onRowClicked : undefined,
491
+ rowStyle: enableRowClickEvent ? { cursor: 'pointer' } : undefined,
436
492
  defaultColDef: {
437
493
  flex: 1,
438
494
  minWidth: this.props.minWidth,
@@ -462,7 +518,9 @@ const cstyles = this.props.cstyles
462
518
  localeText: this.props.localeText,
463
519
  components: {
464
520
  clickCellRenderer: clickCellRenderer,
465
- checkboxCellRenderer: checkboxCellRenderer
521
+ checkboxCellRenderer: checkboxCellRenderer,
522
+ idCheckboxCellRenderer: idCheckboxCellRenderer,
523
+ headerCheckbox: headerCheckbox
466
524
  }
467
525
  };
468
526
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation",
6
6
  "license": "MIT",