@cdmx/wappler_ag_grid 1.6.2 → 1.6.3

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/README.md CHANGED
@@ -66,22 +66,21 @@ To use the "Custom" theme, copy "ag-theme-custom.css" to public/css/ag-theme-cus
66
66
  29. **Auto Height**: The height is automatically set based on the content of the cells. (Default: false)
67
67
  30. **Wrap Text**: This will cause long texts to wrap in the cells. (Default: false)
68
68
  31. **Center Align (V)**: Specifies if the cell data should be vertically centered. (Default: false)
69
- 32. **Center Align (H)**: Specifies if the cell data should be vertically centered. (Default: false)
70
- 33. **Suppress Row Click Selection**: Disables row selection on row click. (Default: false)
71
- 34. **Suppress Menu Hide**: Prevents hiding the column menu. (Default: false)
72
- 35. **Suppress Movable Columns**: Disables moving columns. (Default: false)
73
- 36. **Enable Cell Expressions**: Enables expressions in cell values. (Default: false)
74
- 37. **Animate Rows**: Enables row animation on data changes. (Default: false)
75
- 38. **Suppress Aggregation Function in Header**: Hides the aggregation function in column headers. (Default: false)
76
- 39. **Suppress Clipboard Paste**: Disables pasting data from the clipboard. (Default: false)
77
- 40. **Suppress Scroll on New Data**: Prevents scrolling to newly added data. (Default: false)
78
- 41. **Suppress Property Names Check**: Disables checking for duplicate property names. (Default: false)
79
- 42. **Hide ID Field**: Hides the ID Field in the Grid. (Default: false)
80
- 43. **Numeric Column Align**: Align numeric columns to the right. (Default: false)
81
- 44. **Row Click Events**: Enables row click events. This can be used in Dynamic events => Grid Events => Row Clicked. (Default: false)
82
- 45. **Row Double Click Events**: Enables row double click events. This can be used in Dynamic events => Grid Events => Row Double Clicked. (Default: false)
83
- 46. **Enable Row Selection**: Enables row selection. This can be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked. (Default: false)
84
- 47. **Enable Row Status Toggle**: Enables row status toggle events. This can be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked. (Default: false)
69
+ 32. **Suppress Row Click Selection**: Disables row selection on row click. (Default: false)
70
+ 33. **Suppress Menu Hide**: Prevents hiding the column menu. (Default: false)
71
+ 34. **Suppress Movable Columns**: Disables moving columns. (Default: false)
72
+ 35. **Enable Cell Expressions**: Enables expressions in cell values. (Default: false)
73
+ 36. **Animate Rows**: Enables row animation on data changes. (Default: false)
74
+ 37. **Suppress Aggregation Function in Header**: Hides the aggregation function in column headers. (Default: false)
75
+ 38. **Suppress Clipboard Paste**: Disables pasting data from the clipboard. (Default: false)
76
+ 39. **Suppress Scroll on New Data**: Prevents scrolling to newly added data. (Default: false)
77
+ 40. **Suppress Property Names Check**: Disables checking for duplicate property names. (Default: false)
78
+ 41. **Hide ID Field**: Hides the ID Field in the Grid. (Default: false)
79
+ 42. **Numeric Column Align**: Align numeric columns to the right. (Default: false)
80
+ 43. **Row Click Events**: Enables row click events. This can be used in Dynamic events => Grid Events => Row Clicked. (Default: false)
81
+ 44. **Row Double Click Events**: Enables row double click events. This can be used in Dynamic events => Grid Events => Row Double Clicked. (Default: false)
82
+ 45. **Enable Row Selection**: Enables row selection. This can be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked. (Default: false)
83
+ 46. **Enable Row Status Toggle**: Enables row status toggle events. This can be used in Dynamic events => Grid Events => Checkbox Checked || Checkbox Unchecked. (Default: false)
85
84
 
86
85
  # Data Type Overrides
87
86
 
@@ -95,16 +94,40 @@ This grid allows you to define custom type overrides for specific fields in the
95
94
 
96
95
  # Style Formatting
97
96
 
97
+ ## Text and Cell Colors
98
+
98
99
  The Style Formatting feature allows you to configure custom colors and fonts for column data based on certain conditions.
99
100
  This grid allows you to define custom color and font settings based on specific conditions. The grid has the following columns:
100
101
 
101
102
  1. **Field**: The field name for which you want to apply the custom color and font settings. (eg. first_name or status)
102
- 2. **Condition**: The condition to check for applying the custom color and font settings. (eg. status=false or name=K den)
103
+ 2. **Condition**: The condition to check for applying the custom color and font settings. (eg. status=false or name=K den).
104
+ You can also supply a function here to return true or false based on the input.
105
+ eg: input jsTest() in the condition field and define it as below:
106
+ ```javascript
107
+ <script>
108
+ function jsTest(data) {
109
+ return (data.status == 'success');
110
+ }
111
+ </script>
103
112
  3. **Color**: The custom color to apply when the condition is met. Enter the color in HEX format (e.g., "#FF0000") or use named colors (e.g., "red").
104
113
  4. **Area**: Choose where to apply the color: "text" (cell text) or "cell" (cell background).
105
114
  5. **Font**: Choose the font style: "normal," "italic," or "bold."
106
115
  ---
107
116
 
117
+ ## Configure Row Colors
118
+
119
+ 1. **Condition**: The condition to check for applying the custom color to rows. (eg. status=false or name=K den).
120
+ You can also supply a function here to return true or false based on the input.
121
+ eg: input jsTest() in the condition field and define it as below:
122
+ ```javascript
123
+ <script>
124
+ function jsTest(data) {
125
+ return (data.status == 'success');
126
+ }
127
+ </script>
128
+ </script>
129
+ 2. **Color**: The custom color to apply to row when the condition is met. Enter the color in HEX format (e.g., "#FF0000") or use named colors (e.g., "red").
130
+
108
131
  # Tooltip Settings
109
132
 
110
133
  The Tooltip Settings feature allows you to configure custom tooltips for specific fields in the data.
@@ -176,7 +176,7 @@
176
176
  "defaultValue": true,
177
177
  "help": "Specifies if the column has a floating filter"
178
178
  },
179
- {
179
+ {
180
180
  "name": "cellEditable",
181
181
  "attribute": "dmx-bind:cell_editable",
182
182
  "title": "Editable Cells",
@@ -340,7 +340,7 @@
340
340
  "defaultValue": "dd/MM/yyyy hh:mm A",
341
341
  "help": "Date Format"
342
342
  },
343
- {
343
+ {
344
344
  "name": "quickFilterField",
345
345
  "attribute": "quick_filter_field",
346
346
  "title": "Filter Field ID",
@@ -475,7 +475,7 @@
475
475
  "defaultValue": false,
476
476
  "help": "This will cause long texts to wrap in the cells."
477
477
  },
478
- {
478
+ {
479
479
  "name": "vCenterCellData",
480
480
  "attribute": "dmx-bind:vert_center_cell_data",
481
481
  "title": "Center Align (V)",
@@ -697,7 +697,7 @@
697
697
  {
698
698
  "name": "listColors",
699
699
  "attribute": "dmx-bind:cstyles",
700
- "title": "Colors",
700
+ "title": "Text and Cell Colors",
701
701
  "type": "grid",
702
702
  "dataBindings": true,
703
703
  "jsonFormat": true,
@@ -760,6 +760,64 @@
760
760
  }
761
761
  }
762
762
  ]
763
+ },
764
+ {
765
+ "name": "rstyles",
766
+ "title": "Configure Row Colors",
767
+ "attributeStartsWith": "dmx-bind",
768
+ "attribute": "rstyles",
769
+ "type": "boolean",
770
+ "defaultValue": false,
771
+ "display": "fieldset",
772
+ "show": [
773
+ "listRowColors"
774
+ ],
775
+ "noChangeOnHide": true,
776
+ "groupEnabler": true,
777
+ "help": "Add custom Colors function that will return true or false. Add the fucntion name in the Function column."
778
+ "children": [
779
+ {
780
+ "name": "listRowColors",
781
+ "attribute": "dmx-bind:rstyles",
782
+ "title": "Row Colors",
783
+ "type": "grid",
784
+ "key": "field",
785
+ "dataBindings": true,
786
+ "jsonFormat": true,
787
+ "encloseBT": true,
788
+ "jsonBT": true,
789
+ "initDisplay": "none",
790
+ "columns": [
791
+ {
792
+ "field": "field",
793
+ "caption": "Field",
794
+ "editable": {
795
+ "type": "text"
796
+ }
797
+ },
798
+ {
799
+ "field": "condition",
800
+ "caption": "Function",
801
+ "editable": {
802
+ "type": "text"
803
+ }
804
+ },
805
+ {
806
+ "field": "customColor",
807
+ "caption": "Color",
808
+ "editable": {
809
+ "type": "text"
810
+ },
811
+ help: "Example: '#FF0000' or 'red'"
812
+ }
813
+ ],
814
+ "newRecord": {
815
+ "field": "",
816
+ "condition": "",
817
+ "customColor": ""
818
+ }
819
+ }
820
+ ]
763
821
  }
764
822
  ]
765
823
  },
@@ -1392,7 +1450,7 @@
1392
1450
  "columnsToSum",
1393
1451
  "enableFixedFooter",
1394
1452
  "fixedFooterBottomPadding",
1395
- "columnsToCountNonUnique"
1453
+ "columnsToCountNonUnique"
1396
1454
  ],
1397
1455
  "noChangeOnHide": true,
1398
1456
  "groupEnabler": true,
@@ -1428,7 +1486,7 @@
1428
1486
  "unique_values": ""
1429
1487
  }
1430
1488
  },
1431
- {
1489
+ {
1432
1490
  "name": "columnsToCountNonUnique",
1433
1491
  "attribute": "dmx-bind:columns_to_count_nonunique",
1434
1492
  "title": "Count Non-Unique",
@@ -2364,7 +2422,7 @@
2364
2422
  state: 'opened',
2365
2423
  help: 'Get Selected Rows',
2366
2424
  properties: []
2367
- },
2425
+ },
2368
2426
  {
2369
2427
  addTitle: 'quickFilter',
2370
2428
  title: 'Quick Filter',
@@ -2828,7 +2886,7 @@
2828
2886
  "dmx-ag-grid": true
2829
2887
  }
2830
2888
  },
2831
- {
2889
+ {
2832
2890
  "name": "dmx-ag-grid-cell-edited",
2833
2891
  "attributeStartsWith": "dmx-on",
2834
2892
  "attribute": "cell_data_edited",
package/dmx-ag-grid.js CHANGED
@@ -22,6 +22,7 @@ dmx.Component('ag-grid', {
22
22
  tooltip_config: { type: Array, default: [] },
23
23
  custom_tooltip: { type: String, default: null },
24
24
  cstyles: { type: Array, default: [] },
25
+ rstyles: { type: Array, default: {} },
25
26
  cnames: { type: Object, default: {} },
26
27
  cwidths: { type: Object, default: {} },
27
28
  ctypes: { type: Array, default: [] },
@@ -728,7 +729,6 @@ dmx.Component('ag-grid', {
728
729
  const options = {
729
730
  timeZone: timezone,
730
731
  };
731
-
732
732
  const convertedTimestamp = date.toLocaleString(options.date_locale, options);
733
733
  const [datePart, timePart] = convertedTimestamp.split(', ');
734
734
  const [day, month, year] = datePart.split('/');
@@ -755,6 +755,32 @@ dmx.Component('ag-grid', {
755
755
 
756
756
  return valueA.toLowerCase().localeCompare(valueB.toLowerCase());
757
757
  };
758
+ //Custom Row Styles
759
+ function createRowStyleFunction(rstyles) {
760
+ return function(params) {
761
+ if (!rstyles || !Array.isArray(rstyles) || rstyles.length === 0) {
762
+ return; // No styles to apply
763
+ }
764
+ const rowStyle = {};
765
+ for (const style of rstyles) {
766
+ const condition = style.condition.replace(/\(\)$/, ''); // Remove () if present at the end
767
+ const customColor = style.customColor;
768
+ let conditionResult;
769
+ if (typeof window[condition] === 'function') {
770
+ const result = window[condition](params.data);
771
+ if (typeof result !== 'boolean') {
772
+ console.error('Row condition function must return a boolean value.');
773
+ return;
774
+ }
775
+ conditionResult = result;
776
+ }
777
+ if (conditionResult) {
778
+ rowStyle.background = customColor;
779
+ }
780
+ }
781
+ return rowStyle;
782
+ };
783
+ }
758
784
  dateFilterParams = {
759
785
  comparator: function (filterLocalDateAtMidnight, cellValue) {
760
786
  var cellDate = new Date(cellValue);
@@ -843,7 +869,6 @@ dmx.Component('ag-grid', {
843
869
  if (matchingChange && matchingChange.area === 'cell' ) {
844
870
  return matchingChange.new_value;
845
871
  }
846
-
847
872
  // Check if there's a matching change in dataBindedChanges
848
873
  const matchingKeyData = keyLookup[key];
849
874
  if (matchingKeyData) {
@@ -883,14 +908,11 @@ dmx.Component('ag-grid', {
883
908
 
884
909
  return function (params) {
885
910
  const value = params.data[key];
886
-
887
-
888
911
  // Check if there's a matching change in dataChanges
889
912
  const matchingChange = dataChanges.find(change => change.field === key && change.value === String(value));
890
913
  if (matchingChange && matchingChange.area === 'tooltip' ) {
891
914
  return matchingChange.new_value;
892
915
  }
893
-
894
916
  // Check if there's a matching change in dataBindedChanges
895
917
  const matchingKeyData = keyLookup[key];
896
918
  if (matchingKeyData) {
@@ -933,7 +955,6 @@ dmx.Component('ag-grid', {
933
955
 
934
956
  return function (params) {
935
957
  const value = params.data[key];
936
-
937
958
  // Check if there's a matching change in dataChanges
938
959
  const matchingChange = dataChanges.find(change => change.field === key && change.value === String(value));
939
960
  if (matchingChange) {
@@ -1036,22 +1057,43 @@ dmx.Component('ag-grid', {
1036
1057
  function applyCellStyle(params) {
1037
1058
  const field = params.colDef.field.toString();
1038
1059
  const styles = cstyles.filter((cs) => cs.field === field);
1039
- const whiteSpace = options.wrap_text ? 'normal' : 'nowrap'
1060
+ const whiteSpace = options.wrap_text ? 'normal' : 'nowrap';
1040
1061
 
1041
1062
  for (const style of styles) {
1042
1063
  const condition = style.condition;
1043
1064
  const customColor = style.customColor;
1044
1065
  const font = style.font || 'normal';
1045
- const area = style.area || 'text';
1046
- const [left, operator, right] = extractConditionParts(condition);
1047
- if (
1048
- params.data.hasOwnProperty(left) &&
1049
- (params.data[left] !== null ? evaluateCondition(params.data[left], operator, right) : false)
1050
- ) {
1066
+ const area = style.area || 'text';
1067
+ let conditionResult = false;
1068
+ if (condition.endsWith('()') && typeof window[condition.replace(/\(\)$/, '')] === 'function') {
1069
+ const result = window[condition.replace(/\(\)$/, '')](params.data);
1070
+ if (typeof result !== 'boolean') {
1071
+ console.error('Custom condition function must return a boolean value.');
1072
+ return;
1073
+ }
1074
+ conditionResult = result;
1075
+ } else {
1076
+ const [left, operator, right] = extractConditionParts(condition);
1077
+ if (params.data.hasOwnProperty(left) &&
1078
+ (params.data[left] !== null ? evaluateCondition(params.data[left], operator, right) : false)
1079
+ ) {
1080
+ conditionResult = true;
1081
+ }
1082
+ }
1083
+ if (conditionResult) {
1051
1084
  if (area === 'text') {
1052
- return { color: customColor, fontStyle: font, fontWeight: (font==='bold'?'bold':null), whiteSpace: whiteSpace };
1085
+ return {
1086
+ color: customColor,
1087
+ fontStyle: font,
1088
+ fontWeight: (font === 'bold' ? 'bold' : null),
1089
+ whiteSpace: whiteSpace
1090
+ };
1053
1091
  } else if (area === 'cell') {
1054
- return { backgroundColor: customColor, fontStyle: font, whiteSpace: whiteSpace };
1092
+ return {
1093
+ backgroundColor: customColor,
1094
+ fontStyle: font,
1095
+ whiteSpace: whiteSpace
1096
+ };
1055
1097
  }
1056
1098
  }
1057
1099
  }
@@ -1060,7 +1102,6 @@ dmx.Component('ag-grid', {
1060
1102
  }
1061
1103
  return null;
1062
1104
  }
1063
-
1064
1105
  if (cnames.hasOwnProperty(key)) {
1065
1106
  const cname = cnames[key]
1066
1107
  headerName = cname ? cname.custom_name : humanize(key);
@@ -1302,6 +1343,7 @@ dmx.Component('ag-grid', {
1302
1343
  const gridOptions = {
1303
1344
  ...(idFieldPresent ? { getRowId: params => params.data.id } : {}),
1304
1345
  columnDefs: (groupedColumnDefs && groupedColumnDefs.length > 0) ? groupedColumnDefs : columnDefs,
1346
+ getRowStyle: options.rstyles ? createRowStyleFunction(options.rstyles): undefined,
1305
1347
  localeText: localeText,
1306
1348
  enableRtl: options.enable_rtl,
1307
1349
  onRowClicked: enableRowClickEvent ? onRowClicked : undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid Table Generation.",
6
6
  "license": "MIT",