@@ -176,6 +176,9 @@ export class AjfExpressionUtils {
176
176
SUM : { fn : SUM } ,
177
177
TODAY : { fn : TODAY } ,
178
178
CHART_TO_DATA : { fn : CHART_TO_DATA } ,
179
+ FORMAT_TABLE_ROWS : { fn : FORMAT_TABLE_ROWS } ,
180
+ FORMAT_TABLE_COLS : { fn : FORMAT_TABLE_COLS } ,
181
+ FORMAT_TABLE_FIELDS : { fn : FORMAT_TABLE_FIELDS } ,
179
182
} ;
180
183
}
181
184
@@ -2133,3 +2136,52 @@ export function CHART_TO_DATA(labels: string[], values: any[]): string {
2133
2136
labels . forEach ( ( lab : string , i : number ) => ( jsonObj [ lab ] = values [ i ] ) ) ;
2134
2137
return JSON . stringify ( jsonObj ) ;
2135
2138
}
2139
+
2140
+ /**
2141
+ * Formats the given table rows as an HTML table string.
2142
+ * @param rows
2143
+ * @returns
2144
+ */
2145
+ export function FORMAT_TABLE_ROWS ( rows : any [ ] [ ] ) : string {
2146
+ let html = '\n<table>' ;
2147
+ for ( const row of rows ) {
2148
+ html += '\n <tr>\n ' ;
2149
+ for ( const cell of row ) {
2150
+ html += `<td>${ cell } </td>` ;
2151
+ }
2152
+ html += '\n </tr>' ;
2153
+ }
2154
+ html += '\n</table>\n' ;
2155
+ return html ;
2156
+ }
2157
+
2158
+ /**
2159
+ * Formats the given table columns as an HTML table string.
2160
+ * @param columns
2161
+ * @returns
2162
+ */
2163
+ export function FORMAT_TABLE_COLS ( columns : any [ ] [ ] ) : string {
2164
+ const numRows = columns . length && columns [ 0 ] . length ;
2165
+ const rows = Array ( numRows ) . fill ( 1 ) . map ( _ => [ ] ) as any [ ] [ ] ;
2166
+ for ( const col of columns ) {
2167
+ for ( let i = 0 ; i < numRows ; i ++ ) {
2168
+ rows [ i ] . push ( col [ i ] ) ;
2169
+ }
2170
+ }
2171
+ return FORMAT_TABLE_ROWS ( rows ) ;
2172
+ }
2173
+
2174
+ /**
2175
+ * Extracts the fields' data from the specified forms and formats them as an HTML table string.
2176
+ * @param forms
2177
+ * @param fields
2178
+ * @returns
2179
+ */
2180
+ export function FORMAT_TABLE_FIELDS ( forms : MainForm [ ] , fields : string [ ] ) : string {
2181
+ forms = forms . filter ( f => f != null ) ;
2182
+ const rows = [ fields ] as any [ ] [ ] ;
2183
+ for ( const form of forms ) {
2184
+ rows . push ( fields . map ( field => form [ field ] ) ) ;
2185
+ }
2186
+ return FORMAT_TABLE_ROWS ( rows ) ;
2187
+ }
0 commit comments