@cdmx/wappler_ag_grid 0.1.9 → 0.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.
@@ -667,6 +667,104 @@
667
667
  ]
668
668
  }
669
669
  ]
670
+ },
671
+ {
672
+ "group": "📒 Configure Actions Column",
673
+ "variables": [
674
+ {
675
+ "name": "action_column",
676
+ "attributeStartsWith": "dmx-bind",
677
+ "attribute": "action_column",
678
+ "title": "Configure Actions",
679
+ "type": "boolean",
680
+ "display": "fieldset",
681
+ "show": [
682
+ "enableActions",
683
+ "editActionTitle",
684
+ "editActionTooltip",
685
+ "editActionBtnClass",
686
+ "editActionIconClass",
687
+ "viewActionTitle",
688
+ "viewActionTooltip",
689
+ "viewActionBtnClass",
690
+ "viewActionIconClass"
691
+ ],
692
+ "noChangeOnHide": true,
693
+ "groupEnabler": true,
694
+ "help": "Configure Actions for the buttons in Actions Column"
695
+ "children": [
696
+ {
697
+ "name": "help",
698
+ "type": "static",
699
+ "help": "Configure Actions for the buttons"
700
+ },
701
+ {
702
+ "name": "enableActions",
703
+ "attribute": "dmx-bind:enable_actions",
704
+ "title": "Enable Actions",
705
+ "type": "boolean",
706
+ "defaultValue": false,
707
+ "help": "Enable Actions"
708
+ },
709
+ {
710
+ "name": "editActionTitle",
711
+ "attribute": "edit_action_title",
712
+ "title": "Edit Action Button Title",
713
+ "type": "text",
714
+ "defaultValue": ''
715
+ },
716
+ {
717
+ "name": "editActionTooltip",
718
+ "attribute": "edit_action_tooltip",
719
+ "title": "Edit Action Button Tooltip",
720
+ "type": "text",
721
+ "defaultValue": ''
722
+ },
723
+ {
724
+ "name": "editActionBtnClass",
725
+ "attribute": "edit_action_btn_class",
726
+ "title": "Edit Action Button Class",
727
+ "type": "text",
728
+ "defaultValue": 'btn-primary btn-xs'
729
+ },
730
+ {
731
+ "name": "editActionIconClass",
732
+ "attribute": "edit_action_icon_class",
733
+ "title": "Edit Action IconClass",
734
+ "type": "text",
735
+ "defaultValue": 'fas fa-pencil-alt'
736
+ },
737
+ {
738
+ "name": "viewActionTitle",
739
+ "attribute": "view_action_title",
740
+ "title": "View Action Button Title",
741
+ "type": "text",
742
+ "defaultValue": ''
743
+ },
744
+ {
745
+ "name": "viewActionTooltip",
746
+ "attribute": "view_action_tooltip",
747
+ "title": "View Action Button Tooltip",
748
+ "type": "text",
749
+ "defaultValue": ''
750
+ },
751
+ {
752
+ "name": "viewActionBtnClass",
753
+ "attribute": "view_action_btn_class",
754
+ "title": "View Action Button Class",
755
+ "type": "text",
756
+ "defaultValue": 'btn-info btn-xs'
757
+ },
758
+ {
759
+ "name": "viewActionIconClass",
760
+ "attribute": "edit_action_icon_class",
761
+ "title": "View Action IconClass",
762
+ "type": "text",
763
+ "defaultValue": 'fas fa-eye'
764
+ }
765
+ ]
766
+ }
767
+ ]
670
768
  }
671
769
 
672
770
  ],
package/dmx-ag-grid.js CHANGED
@@ -88,7 +88,17 @@ dmx.Component('ag-grid', {
88
88
  cell_click_event: {type: Boolean, default: false },
89
89
  row_click_event: {type: Boolean, default: false },
90
90
  row_checkbox_event: {type: Boolean, default: false },
91
- row_status_event: {type: Boolean, default: false }
91
+ row_status_event: {type: Boolean, default: false },
92
+ enable_actions: {type: Boolean, default: false },
93
+ pin_actions: {type: String, default: 'right' },
94
+ edit_action_title: {type: String, default: '' },
95
+ edit_action_tooltip: {type: String, default: 'Edit' },
96
+ view_action_title: {type: String, default: '' },
97
+ view_action_tooltip: {type: String, default: 'View' },
98
+ edit_action_icon_class: {type: String, default: 'fas fa-pencil-alt' },
99
+ edit_action_btn_class: {type: String, default: 'btn-primary btn-xs' },
100
+ view_action_icon_class: {type: String, default: 'fas fa-eye' },
101
+ view_action_btn_class: {type: String, default: 'btn-info btn-xs' },
92
102
 
93
103
  },
94
104
 
@@ -112,8 +122,20 @@ dmx.Component('ag-grid', {
112
122
  const grid_theme = this.props.grid_theme;
113
123
  const enableCheckboxEvent = this.props.row_checkbox_event;
114
124
  const enableStatusToggle = this.props.row_status_event;
125
+ const enableActions = this.props.enable_actions;
126
+ const pin_actions = this.props.pin_actions;
127
+ const edit_action_title = this.props.edit_action_title;
128
+ const edit_action_btn_class = this.props.edit_action_btn_class;
129
+ const edit_action_icon_class = this.props.edit_action_icon_class;
130
+ const view_action_title = this.props.view_action_title;
131
+ const view_action_btn_class = this.props.view_action_btn_class;
132
+ const view_action_icon_class = this.props.view_action_icon_class;
133
+ const edit_action_tooltip = this.props.edit_action_tooltip;
134
+ const view_action_tooltip = this.props.view_action_tooltip;
135
+
115
136
  let columnDefs = [];
116
137
  let exportToCSV = this.props.exportToCSV;
138
+ console.log(this.props)
117
139
 
118
140
  this.$node.innerHTML = `<div id=${gridId}-grid class="${grid_theme}"></div>`;
119
141
  if (!rowData || rowData.length === 0) {
@@ -171,6 +193,38 @@ dmx.Component('ag-grid', {
171
193
  </label>
172
194
  `;
173
195
  }
196
+ function actionsRenderer(params) {
197
+ // Default button configurations (Edit and View)
198
+ const defaultButtons = [
199
+ { action: 'Edit', classNames: 'btn-primary btn-xs', tooltip: 'Edit', icon: 'fas fa-pencil-alt' },
200
+ { action: 'View', classNames: 'btn-info btn-xs', tooltip: 'View', icon: 'fas fa-eye' },
201
+ ];
202
+ // User-defined button configurations (if any)
203
+ const buttons = params.buttons || defaultButtons;
204
+
205
+ // Create a new container element to hold the buttons
206
+ const container = document.createElement('div');
207
+
208
+ buttons.forEach((buttonConfig) => {
209
+ const button = document.createElement('button');
210
+ button.classList.add('btn');
211
+ const classNames = buttonConfig.classNames.split(' ');
212
+ classNames.forEach((className) => button.classList.add(className));
213
+ button.setAttribute('data-toggle', 'tooltip');
214
+ button.setAttribute('title', buttonConfig.tooltip);
215
+ button.innerHTML = `<i class="${buttonConfig.icon}"></i> ${buttonConfig.action}`;
216
+ container.appendChild(button);
217
+ });
218
+
219
+ // Add spacing between buttons (margin-right)
220
+ const buttonSpacing = '5px'; // You can adjust the spacing as needed
221
+ const buttonsInContainer = container.querySelectorAll('button');
222
+ for (let i = 0; i < buttonsInContainer.length - 1; i++) {
223
+ buttonsInContainer[i].style.marginRight = buttonSpacing;
224
+ }
225
+
226
+ return container;
227
+ }
174
228
 
175
229
 
176
230
  function humanize(str) {
@@ -397,6 +451,7 @@ dmx.Component('ag-grid', {
397
451
  }
398
452
  if (key =='status' && enableStatusToggle) {
399
453
  cellRenderer = 'checkboxCellRenderer';
454
+ filter = null;
400
455
  }
401
456
  else {
402
457
  cellRenderer = undefined;
@@ -443,7 +498,47 @@ dmx.Component('ag-grid', {
443
498
  };
444
499
  columnDefs.unshift(checkboxColumn);
445
500
  }
446
-
501
+ if (enableActions) {
502
+ actionsColumn = {
503
+ headerName: 'Actions',
504
+ field: 'action',
505
+ filter: null,
506
+ cellRenderer: actionsRenderer,
507
+ pinned: pin_actions,
508
+ cellRendererParams: {
509
+ // Custom button configurations
510
+ buttons: [
511
+ {
512
+ action: edit_action_title,
513
+ classNames: edit_action_btn_class,
514
+ tooltip: edit_action_tooltip,
515
+ icon: edit_action_icon_class,
516
+ onClick: (rowData) => {
517
+ this.set('data', rowData);
518
+ this.set('id', rowData.id);
519
+ this.dispatchEvent('action_edit');
520
+ console.log('Custom Action 1 clicked for row with ID:', rowData.id);
521
+ },
522
+ },
523
+ {
524
+ action: view_action_title,
525
+ classNames: view_action_btn_class,
526
+ tooltip: view_action_tooltip,
527
+ icon: view_action_icon_class,
528
+ onClick: (rowData) => {
529
+ this.set('data', rowData);
530
+ this.set('id', rowData.id);
531
+ this.dispatchEvent('action_view');
532
+ console.log('Custom Action 2 clicked for row with ID:', rowData.id);
533
+ },
534
+ },
535
+ // Add more custom buttons as needed
536
+ ],
537
+ },
538
+ }
539
+ columnDefs.push(actionsColumn);
540
+ }
541
+
447
542
  const gridOptions = {
448
543
  columnDefs: columnDefs,
449
544
  onRowClicked: enableRowClickEvent ? onRowClicked : undefined,
@@ -479,7 +574,8 @@ dmx.Component('ag-grid', {
479
574
  localeText: this.props.localeText,
480
575
  components: {
481
576
  clickCellRenderer: clickCellRenderer,
482
- checkboxCellRenderer: checkboxCellRenderer
577
+ checkboxCellRenderer: checkboxCellRenderer,
578
+ actionsRenderer: actionsRenderer
483
579
  }
484
580
  };
485
581
 
@@ -504,19 +600,21 @@ dmx.Component('ag-grid', {
504
600
  const gridElement = document.getElementById(gridId+'-grid');
505
601
  const gridContainer = gridElement.parentNode;
506
602
  // Add an event listener to the grid
507
- gridConfig.api.addEventListener('rowSelected', (event) => {
508
- if (event.node && event.node.isSelected()) {
509
- const rowData = event.node.data;
510
- this.set('data', rowData);
511
- this.set('id', rowData.id);
512
- this.dispatchEvent('row_checkbox_checked');
513
- } else {
514
- const rowData = event.node.data;
515
- this.set('data', rowData);
516
- this.set('id', rowData.id);
517
- this.dispatchEvent('row_checkbox_unchecked');
518
- }
519
- });
603
+ if (enableCheckboxEvent) {
604
+ gridConfig.api.addEventListener('rowSelected', (event) => {
605
+ if (event.node && event.node.isSelected()) {
606
+ const rowData = event.node.data;
607
+ this.set('data', rowData);
608
+ this.set('id', rowData.id);
609
+ this.dispatchEvent('row_checkbox_checked');
610
+ } else {
611
+ const rowData = event.node.data;
612
+ this.set('data', rowData);
613
+ this.set('id', rowData.id);
614
+ this.dispatchEvent('row_checkbox_unchecked');
615
+ }
616
+ });
617
+ }
520
618
  if (!gridContainer) {
521
619
  console.error('Grid container not found.');
522
620
  return;
@@ -577,6 +675,8 @@ dmx.Component('ag-grid', {
577
675
  row_checkbox_unchecked: Event,
578
676
  row_status_enabled: Event,
579
677
  row_status_disabled: Event,
678
+ action_edit: Event,
679
+ action_view: Event
580
680
  },
581
681
 
582
682
  render: function(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation",
6
6
  "license": "MIT",