@cdmx/wappler_ag_grid 0.4.0 → 0.4.2

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.
@@ -253,6 +253,14 @@
253
253
  ],
254
254
  "help": "Timezone for Date Fields"
255
255
  },
256
+ {
257
+ "name": "dateFormat",
258
+ "attribute": "date_format",
259
+ "title": "Date Format",
260
+ "type": "text",
261
+ "defaultValue": "dd/MM/yyyy HH:mm A",
262
+ "help": "Date Format"
263
+ },
256
264
  {
257
265
  "name": "fixedHeader",
258
266
  "attribute": "dmx-bind:fixed_header",
@@ -834,6 +842,7 @@
834
842
  "show": [
835
843
  "hideFields",
836
844
  "hideFilters",
845
+ "hideSort",
837
846
  ],
838
847
  "noChangeOnHide": true,
839
848
  "groupEnabler": true,
@@ -852,6 +861,13 @@
852
861
  "title": "Hide Filters",
853
862
  "type": "text",
854
863
  "initDisplay": "none"
864
+ },
865
+ {
866
+ "name": "hideSort",
867
+ "attribute": "hide_sort",
868
+ "title": "Hide Sort Filters",
869
+ "type": "text",
870
+ "initDisplay": "none"
855
871
  }
856
872
  ]
857
873
  }
@@ -878,7 +894,12 @@
878
894
  "viewActionTitle",
879
895
  "viewActionTooltip",
880
896
  "viewActionBtnClass",
881
- "viewActionIconClass"
897
+ "viewActionIconClass",
898
+ "deleteActionBtn",
899
+ "deleteActionTitle",
900
+ "deleteActionTooltip",
901
+ "deleteActionBtnClass",
902
+ "deleteActionIconClass"
882
903
  ],
883
904
  "noChangeOnHide": true,
884
905
  "groupEnabler": true,
@@ -923,7 +944,7 @@
923
944
  {
924
945
  "name": "editActionIconClass",
925
946
  "attribute": "edit_action_icon_class",
926
- "title": "Edit Action IconClass",
947
+ "title": "Edit Action Icon Class",
927
948
  "type": "text",
928
949
  "defaultValue": 'fas fa-pencil-alt'
929
950
  },
@@ -957,10 +978,45 @@
957
978
  },
958
979
  {
959
980
  "name": "viewActionIconClass",
960
- "attribute": "edit_action_icon_class",
981
+ "attribute": "view_action_icon_class",
961
982
  "title": "View Action IconClass",
962
983
  "type": "text",
963
984
  "defaultValue": 'fas fa-eye'
985
+ },
986
+ {
987
+ "name": "deleteActionBtn",
988
+ "attribute": "dmx-bind:delete_action_btn",
989
+ "title": "Delete Action Button",
990
+ "type": "boolean",
991
+ "defaultValue": ''
992
+ },
993
+ {
994
+ "name": "deleteActionTitle",
995
+ "attribute": "delete_action_title",
996
+ "title": "Delete Action Button Title",
997
+ "type": "text",
998
+ "defaultValue": ''
999
+ },
1000
+ {
1001
+ "name": "deleteActionTooltip",
1002
+ "attribute": "delete_action_tooltip",
1003
+ "title": "Delete Action Button Tooltip",
1004
+ "type": "text",
1005
+ "defaultValue": ''
1006
+ },
1007
+ {
1008
+ "name": "deleteActionBtnClass",
1009
+ "attribute": "delete_action_btn_class",
1010
+ "title": "Delete Action Button Class",
1011
+ "type": "text",
1012
+ "defaultValue": 'btn-danger btn-xs'
1013
+ },
1014
+ {
1015
+ "name": "deleteActionIconClass",
1016
+ "attribute": "delete_action_icon_class",
1017
+ "title": "Delete Action Icon Class",
1018
+ "type": "text",
1019
+ "defaultValue": 'fas fa-trash'
964
1020
  }
965
1021
  ]
966
1022
  }
@@ -1434,6 +1490,40 @@
1434
1490
  "allowedOn": {
1435
1491
  "dmx-ag-grid": true
1436
1492
  }
1493
+ },
1494
+ {
1495
+ "name": "dmx-ag-grid-delete-clicked",
1496
+ "attributeStartsWith": "dmx-on",
1497
+ "attribute": "row_action_delete",
1498
+ "display": "fieldset",
1499
+ "title": "Delete Clicked",
1500
+ "icon": "fa fa-lg fa-chevron-right",
1501
+ "groupTitle": "Grid Events",
1502
+ "groupIcon": "fa fa-lg fa-cubes",
1503
+ "defaultValue": false,
1504
+ "show": [
1505
+ "rowActionDelete"
1506
+ ],
1507
+ "noChangeOnHide": true,
1508
+ "type": "boolean",
1509
+ "groupEnabler": true,
1510
+ "children": [
1511
+ {
1512
+ "name": "rowActionDelete",
1513
+ "attributeStartsWith": "dmx-on",
1514
+ "attribute": "row_action_delete",
1515
+ "isValue": true,
1516
+ "actionsPicker": true,
1517
+ "title": "Action:",
1518
+ "type": "text",
1519
+ "help": "Choose the action to execute.",
1520
+ "defaultValue": "",
1521
+ "initDisplay": "none"
1522
+ }
1523
+ ],
1524
+ "allowedOn": {
1525
+ "dmx-ag-grid": true
1526
+ }
1437
1527
  }
1438
1528
  ],
1439
1529
  "static_events": []
package/dmx-ag-grid.js CHANGED
@@ -37,7 +37,9 @@ dmx.Component('ag-grid', {
37
37
  suppress_property_names_check: { type: Boolean, default: false },
38
38
  hide_id_field: { type: Boolean, default: false },
39
39
  enable_rtl: { type: Boolean, default: false },
40
- locale_text: { type: Text, default: null },
40
+ locale_text: { type: String, default: null },
41
+ date_locale: { type: String, default: 'en-IN' },
42
+ date_format: { type: String, default: 'dd/MM/yyyy HH:mm A' },
41
43
  min_width: { type: Number, default: 150 },
42
44
  sortable: { type: Boolean, default: true },
43
45
  resizable: { type: Boolean, default: true },
@@ -60,16 +62,22 @@ dmx.Component('ag-grid', {
60
62
  edit_action_btn: { type: Boolean, default: false },
61
63
  edit_action_title: {type: String, default: '' },
62
64
  edit_action_tooltip: {type: String, default: 'Edit' },
65
+ edit_action_icon_class: {type: String, default: 'fas fa-pencil-alt' },
66
+ edit_action_btn_class: {type: String, default: 'btn-primary btn-xs' },
63
67
  view_action_btn: { type: Boolean, default: false },
64
68
  view_action_title: {type: String, default: '' },
65
69
  view_action_tooltip: {type: String, default: 'View' },
66
- edit_action_icon_class: {type: String, default: 'fas fa-pencil-alt' },
67
- edit_action_btn_class: {type: String, default: 'btn-primary btn-xs' },
68
70
  view_action_icon_class: {type: String, default: 'fas fa-eye' },
69
71
  view_action_btn_class: {type: String, default: 'btn-info btn-xs' },
72
+ delete_action_btn: { type: Boolean, default: false },
73
+ delete_action_title: {type: String, default: '' },
74
+ delete_action_tooltip: {type: String, default: 'Delete' },
75
+ delete_action_icon_class: {type: String, default: 'fas fa-trash' },
76
+ delete_action_btn_class: {type: String, default: 'btn-danger btn-xs' },
70
77
  data_binded_changes: {type: Array, default: [] },
71
78
  hide_fields: {type: Array, default: [] },
72
- hide_filters: {type: Array, default: [] }
79
+ hide_filters: {type: Array, default: [] },
80
+ hide_sort: {type: Array, default: [] }
73
81
  },
74
82
 
75
83
  methods: {
@@ -97,8 +105,8 @@ dmx.Component('ag-grid', {
97
105
  const cnames = this.props.cnames
98
106
  const cwidths = this.props.cwidths
99
107
  const ctypes = this.props.ctypes
100
- const enableRowClickEvent = this.props.row_click_event;
101
- const enableCellClickEvent = this.props.cell_click_event;
108
+ const enableRowClickEvent = this.props.row_click_event && !this.props.row_action_edit && !this.props.row_action_view && !this.props.row_checkbox_event;
109
+ const enableCellClickEvent = this.props.row_click_event && (this.props.row_action_edit || this.props.row_action_view || this.props.row_checkbox_event);
102
110
  let localeText;
103
111
  let columnDefs = [];
104
112
  let exportToCSV = this.props.export_to_csv;
@@ -133,6 +141,17 @@ dmx.Component('ag-grid', {
133
141
  const value = params.value
134
142
  return `<div onclick="cellClickEvent('${columnName}', '${value}', '${idValue}')" style="cursor: pointer;">${value}</div>`;
135
143
  }
144
+ onCellClicked = (event) => {
145
+ const rowData = event.data;
146
+ const columnId = event.column.colId
147
+ const excludedColIds = ['checkboxColumn', 'actionsColumn', 'statusColumn'];
148
+ if (excludedColIds.includes(columnId)) {
149
+ return;
150
+ }
151
+ this.set('data', rowData);
152
+ this.set('id', rowData.id);
153
+ this.dispatchEvent('row_clicked')
154
+ }
136
155
 
137
156
  function checkboxCellRenderer(params) {
138
157
  const idValue = params.data.id;
@@ -163,8 +182,9 @@ dmx.Component('ag-grid', {
163
182
  function actionsRenderer(params) {
164
183
  // Default button configurations (Edit and View)
165
184
  const defaultButtons = [
166
- { action: 'Edit', classNames: 'btn-primary btn-xs', tooltip: 'Edit', icon: 'fas fa-pencil-alt' },
167
- { action: 'View', classNames: 'btn-info btn-xs', tooltip: 'View', icon: 'fas fa-eye' },
185
+ { action: 'Edit', classNames: 'btn-primary btn-xs', tooltip: 'Edit', icon: 'fas fa-pencil-alt' },
186
+ { action: 'View', classNames: 'btn-info btn-xs', tooltip: 'View', icon: 'fas fa-eye' },
187
+ { action: 'Delete', classNames: 'btn-danger btn-xs', tooltip: 'Delete', icon: 'fas fa-trash' },
168
188
  ];
169
189
  // User-defined button configurations (if any)
170
190
  const buttons = params.buttons || defaultButtons;
@@ -209,8 +229,10 @@ dmx.Component('ag-grid', {
209
229
  .replace(/_id$/, '')
210
230
  .replace(/_/g, ' ')
211
231
  .trim();
232
+ let words = str.split(' ');
233
+ words = words.map(word => word.charAt(0).toUpperCase() + word.substr(1));
212
234
 
213
- return str.charAt(0).toUpperCase() + str.substr(1);
235
+ return words.join(' ');
214
236
  }
215
237
 
216
238
  function blankOrNullValueFormatter(params) {
@@ -224,35 +246,92 @@ dmx.Component('ag-grid', {
224
246
 
225
247
  return params.value;
226
248
  }
227
-
228
- function formatTime(params, timezone) {
229
- if (params.value == null) {
230
- return '-';
231
- } else {
232
- const date = new Date(params.value);
233
- if (timezone) {
234
- const options = {
235
- day: '2-digit',
236
- month: '2-digit',
237
- year: 'numeric',
238
- hour: 'numeric',
239
- minute: 'numeric',
240
- hour12: true,
241
- timeZone: timezone
242
- };
243
- return date.toLocaleString('en-IN', options).toUpperCase();
244
- } else {
245
- const options = {
246
- day: '2-digit',
247
- month: '2-digit',
248
- year: 'numeric',
249
- hour: 'numeric',
250
- minute: 'numeric',
251
- hour12: true
252
- };
253
- return date.toLocaleString('en-IN', options).toUpperCase();
249
+ function formatDate(timestamp) {
250
+ const format = options.date_format
251
+ const localDate = new Date(timestamp);
252
+
253
+ const y = localDate.getFullYear();
254
+ const n = localDate.getMonth();
255
+ const d = localDate.getDate();
256
+ const w = localDate.getDay();
257
+ const h = localDate.getHours();
258
+ const m = localDate.getMinutes();
259
+ const s = localDate.getSeconds();
260
+
261
+ function pad(num, length) {
262
+ return ('0000' + num).slice(-length);
263
+ }
264
+
265
+ return format.replace(/([yMdHhmsaAv])(\1+)?/g, part => {
266
+ switch (part) {
267
+ case 'yyyy':
268
+ return pad(y, 4);
269
+ case 'yy':
270
+ return pad(y, 2);
271
+ case 'y':
272
+ return y;
273
+ case 'MMMM':
274
+ return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][n];
275
+ case 'MMM':
276
+ return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][n];
277
+ case 'MM':
278
+ return pad(n + 1, 2);
279
+ case 'M':
280
+ return n + 1;
281
+ case 'dddd':
282
+ return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][w];
283
+ case 'ddd':
284
+ return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][w];
285
+ case 'dd':
286
+ return pad(d, 2);
287
+ case 'd':
288
+ return d;
289
+ case 'HH':
290
+ return pad(h, 2);
291
+ case 'H':
292
+ return h;
293
+ case 'hh':
294
+ return pad((h % 12) || 12, 2);
295
+ case 'h':
296
+ return (h % 12) || 12;
297
+ case 'mm':
298
+ return pad(m, 2);
299
+ case 'm':
300
+ return m;
301
+ case 'ss':
302
+ return pad(s, 2);
303
+ case 's':
304
+ return s;
305
+ case 'a':
306
+ return h < 12 ? 'am' : 'pm';
307
+ case 'A':
308
+ return h < 12 ? 'AM' : 'PM';
309
+ default:
310
+ return part; // Return unchanged for unknown format parts
254
311
  }
312
+ });
313
+ }
314
+
315
+ function formatTime(params, timezone) {
316
+ const date = new Date(params.value);
317
+ if (!timezone) {
318
+ timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
255
319
  }
320
+ const options = {
321
+ timeZone: timezone,
322
+ year: 'numeric',
323
+ month: '2-digit',
324
+ day: '2-digit',
325
+ hour: 'numeric',
326
+ minute: 'numeric',
327
+ second: 'numeric',
328
+ hour12: false,
329
+ };
330
+
331
+ const formatter = new Intl.DateTimeFormat(undefined, options);
332
+ const formattedDateTime = formatter.format(date);
333
+ return formatDate(formattedDateTime)
334
+
256
335
  }
257
336
  dateFilterParams = {
258
337
  comparator: function (filterLocalDateAtMidnight, cellValue) {
@@ -398,6 +477,7 @@ dmx.Component('ag-grid', {
398
477
  let filterParams;
399
478
  let minWidth;
400
479
  let hide;
480
+ let colId;
401
481
 
402
482
  if (dataType === 'number') {
403
483
  filter = 'agNumberColumnFilter';
@@ -436,7 +516,6 @@ dmx.Component('ag-grid', {
436
516
  }
437
517
  }
438
518
  else {
439
- // valueGetter = getValueGetter(key, dataChanges);
440
519
  valueGetter = createCombinedValueGetter(key, options.data_changes, options.data_binded_changes);
441
520
  filterValueGetter = createCombinedFilterValueGetter(key, options.data_changes, options.data_binded_changes);
442
521
  }
@@ -499,6 +578,7 @@ dmx.Component('ag-grid', {
499
578
  }
500
579
  if (key =='status' && options.row_status_event) {
501
580
  cellRenderer = 'checkboxCellRenderer';
581
+ colId = 'statusColumn';
502
582
  filter = null;
503
583
  }
504
584
  else if (options.hide_filters && options.hide_filters.includes(key)) {
@@ -506,6 +586,13 @@ dmx.Component('ag-grid', {
506
586
  }
507
587
  else {
508
588
  cellRenderer = undefined;
589
+ colId = undefined;
590
+ }
591
+ if (options.hide_sort && options.hide_sort.includes(key)) {
592
+ sortable = false;
593
+ }
594
+ else {
595
+ sortable = true;
509
596
  }
510
597
  if (options.hide_id_field && key == 'id') {
511
598
  hide = true;
@@ -525,6 +612,7 @@ dmx.Component('ag-grid', {
525
612
  valueGetter: valueGetter,
526
613
  minWidth: minWidth,
527
614
  hide: hide,
615
+ sortable: sortable,
528
616
  filterValueGetter: filterValueGetter,
529
617
  filterParams: filterParams,
530
618
  cellStyle: applyCellStyle,
@@ -548,6 +636,7 @@ dmx.Component('ag-grid', {
548
636
  headerCheckboxSelection: true,
549
637
  headerCheckboxSelectionFilteredOnly: false,
550
638
  headerName: '',
639
+ colId: 'checkboxColumn',
551
640
  field: 'id',
552
641
  filter: '',
553
642
  checkboxSelection: true,
@@ -563,6 +652,7 @@ dmx.Component('ag-grid', {
563
652
  actionsColumn = {
564
653
  headerName: 'Actions',
565
654
  field: 'action',
655
+ colId: 'actionsColumn',
566
656
  filter: null,
567
657
  cellRenderer: actionsRenderer,
568
658
  pinned: options.pin_actions,
@@ -598,6 +688,19 @@ dmx.Component('ag-grid', {
598
688
  },
599
689
  });
600
690
  }
691
+ if (options.delete_action_btn) {
692
+ actionsColumn.cellRendererParams.buttons.push({
693
+ action: options.delete_action_title,
694
+ classNames: options.delete_action_btn_class,
695
+ tooltip: options.delete_action_tooltip,
696
+ icon: options.delete_action_icon_class,
697
+ onClick: (rowData) => {
698
+ this.set('data', rowData);
699
+ this.set('id', rowData.id);
700
+ this.dispatchEvent('row_action_delete');
701
+ },
702
+ });
703
+ }
601
704
 
602
705
  columnDefs.push(actionsColumn);
603
706
  }
@@ -610,7 +713,8 @@ dmx.Component('ag-grid', {
610
713
  enableRtl: options.enable_rtl,
611
714
  noRowsOverlayComponent: '<div>No Records Found.</div>',
612
715
  onRowClicked: enableRowClickEvent ? onRowClicked : undefined,
613
- rowStyle: enableRowClickEvent ? { cursor: 'pointer' } : undefined,
716
+ onCellClicked: enableCellClickEvent ? onCellClicked : undefined,
717
+ rowStyle: enableRowClickEvent || enableCellClickEvent ? { cursor: 'pointer' } : undefined,
614
718
  defaultColDef: {
615
719
  flex: 1,
616
720
  minWidth: this.props.min_width,
@@ -738,9 +842,20 @@ dmx.Component('ag-grid', {
738
842
  exportButton.style.marginBottom = '10px';
739
843
 
740
844
  exportButton.addEventListener('click', () => {
845
+ const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
846
+ // Extracting fields and colIds from columnDefs
847
+ const fieldsAndColIds = gridConfig.columnDefs.map((column) => ({
848
+ field: column.field,
849
+ colId: column.colId,
850
+ }));
851
+ // Filtering out fields based on excludedColumnIds
852
+ const fieldsToExport = fieldsAndColIds.filter(
853
+ (column) => !excludedColumnIds.includes(column.colId)
854
+ ).map((column) => column.field);
741
855
  const params = {
742
856
  fileName: 'export.csv', // Set the desired file name here
743
857
  allColumns: true,
858
+ columnKeys: fieldsToExport,
744
859
  processCellCallback: function (params) {
745
860
  const columnDef = params.column.getColDef();
746
861
  const valueFormatter = columnDef.valueFormatter;
@@ -772,7 +887,8 @@ dmx.Component('ag-grid', {
772
887
  row_status_enabled: Event,
773
888
  row_status_disabled: Event,
774
889
  row_action_edit: Event,
775
- row_action_view: Event
890
+ row_action_view: Event,
891
+ row_action_delete: Event
776
892
  },
777
893
 
778
894
  render: function(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation",
6
6
  "license": "MIT",