@cdmx/wappler_ag_grid 0.4.1 → 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",
package/dmx-ag-grid.js CHANGED
@@ -37,8 +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 },
41
- date_locale: { type: Text, default: 'en-IN' },
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' },
42
43
  min_width: { type: Number, default: 150 },
43
44
  sortable: { type: Boolean, default: true },
44
45
  resizable: { type: Boolean, default: true },
@@ -245,35 +246,92 @@ dmx.Component('ag-grid', {
245
246
 
246
247
  return params.value;
247
248
  }
248
-
249
- function formatTime(params, timezone) {
250
- if (params.value == null) {
251
- return '-';
252
- } else {
253
- const date = new Date(params.value);
254
- if (timezone) {
255
- const options = {
256
- day: '2-digit',
257
- month: '2-digit',
258
- year: 'numeric',
259
- hour: 'numeric',
260
- minute: 'numeric',
261
- hour12: true,
262
- timeZone: timezone
263
- };
264
- return date.toLocaleString(options.date_locale, options).toUpperCase();
265
- } else {
266
- const options = {
267
- day: '2-digit',
268
- month: '2-digit',
269
- year: 'numeric',
270
- hour: 'numeric',
271
- minute: 'numeric',
272
- hour12: true
273
- };
274
- return date.toLocaleString(options.date_locale, 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
275
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;
276
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
+
277
335
  }
278
336
  dateFilterParams = {
279
337
  comparator: function (filterLocalDateAtMidnight, cellValue) {
@@ -567,7 +625,6 @@ dmx.Component('ag-grid', {
567
625
  });
568
626
  }
569
627
  window.onRowClicked = (event) => {
570
- console.log(event)
571
628
  const rowData = event.data;
572
629
  this.set('data', rowData);
573
630
  this.set('id', rowData.id);
@@ -785,9 +842,20 @@ dmx.Component('ag-grid', {
785
842
  exportButton.style.marginBottom = '10px';
786
843
 
787
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);
788
855
  const params = {
789
856
  fileName: 'export.csv', // Set the desired file name here
790
857
  allColumns: true,
858
+ columnKeys: fieldsToExport,
791
859
  processCellCallback: function (params) {
792
860
  const columnDef = params.column.getColDef();
793
861
  const valueFormatter = columnDef.valueFormatter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation",
6
6
  "license": "MIT",