@cellaware/utils 8.1.11 → 8.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.
- package/dist/chatwms/datagrid.d.ts +4 -1
- package/dist/chatwms/datagrid.js +37 -20
- package/package.json +1 -1
|
@@ -124,5 +124,8 @@ export declare function codifyCondition(condition: DatagridCondition): string;
|
|
|
124
124
|
*/
|
|
125
125
|
export declare function stripNumericValueFormat(value: string | number | undefined): any;
|
|
126
126
|
export declare function transformDatagrid(rows: any[], datagridState: DatagridStateBase, locale: string, condition?: DatagridCondition): DatagridState;
|
|
127
|
-
export declare function
|
|
127
|
+
export declare function datagridToString(datagridState: DatagridState): {
|
|
128
|
+
html: string;
|
|
129
|
+
markdown: string;
|
|
130
|
+
};
|
|
128
131
|
export {};
|
package/dist/chatwms/datagrid.js
CHANGED
|
@@ -723,10 +723,9 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
723
723
|
rows = filterRows(rows, filterModel);
|
|
724
724
|
const chartRowData = [];
|
|
725
725
|
// IMPORTANT: we evaluate the datagrid condition AFTER we are done with all transformations.
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
if (isPivotMode && pivotCols.length > 0 && valueCols.length > 0) {
|
|
726
|
+
// NOTE: we do not need any pivot columns for pivot mode to be valid.
|
|
727
|
+
// https://chatwms.io/user-manual/chatwms/faq#q-do-i-have-to-have-a-group-column-to-just-display-a-count-in-the-datagrid
|
|
728
|
+
if (isPivotMode && valueCols.length > 0) {
|
|
730
729
|
const pivotOutput = pivotData(rows, rowGroupCols, pivotCols, valueCols);
|
|
731
730
|
rows = pivotOutput.rows;
|
|
732
731
|
rows = sortModel.length > 0 ? sortRows(rows, sortModel) : rows;
|
|
@@ -809,32 +808,45 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
809
808
|
}
|
|
810
809
|
return { ...datagridState, adjRowData: rows, chartRowData };
|
|
811
810
|
}
|
|
812
|
-
export function
|
|
813
|
-
let
|
|
811
|
+
export function datagridToString(datagridState) {
|
|
812
|
+
let htmlBuf = '';
|
|
813
|
+
let markdownBuf = '';
|
|
814
814
|
if (datagridState.adjRowData.length === 0) {
|
|
815
|
-
return
|
|
815
|
+
return {
|
|
816
|
+
html: htmlBuf,
|
|
817
|
+
markdown: markdownBuf
|
|
818
|
+
};
|
|
816
819
|
}
|
|
817
820
|
const columnFormats = datagridState.columnFormats ?? [];
|
|
818
821
|
if (columnFormats.length === 0) {
|
|
819
|
-
return
|
|
822
|
+
return {
|
|
823
|
+
html: htmlBuf,
|
|
824
|
+
markdown: markdownBuf
|
|
825
|
+
};
|
|
820
826
|
}
|
|
821
827
|
// Header:
|
|
822
|
-
|
|
828
|
+
htmlBuf += '<table>\n\t<thead>\n\t\t<tr>';
|
|
823
829
|
let columns = [];
|
|
824
830
|
for (const key in datagridState.adjRowData[0]) {
|
|
825
831
|
columns.push(key);
|
|
826
|
-
|
|
832
|
+
htmlBuf += `\n\t\t\t<th>${key}</th>`;
|
|
833
|
+
markdownBuf += `| ${key} `;
|
|
834
|
+
}
|
|
835
|
+
markdownBuf += '|\n';
|
|
836
|
+
for (const _ of columns) {
|
|
837
|
+
markdownBuf += `| ----- `;
|
|
827
838
|
}
|
|
828
|
-
|
|
839
|
+
markdownBuf += '|\n';
|
|
840
|
+
htmlBuf += '\n\t\t</tr>\n\t</thead>';
|
|
829
841
|
// Rows:
|
|
830
|
-
|
|
842
|
+
htmlBuf += '\n\t<tbody>';
|
|
831
843
|
let rowIdx = 0;
|
|
832
844
|
for (const row of datagridState.adjRowData) {
|
|
833
845
|
let colIdx = 0;
|
|
834
846
|
const rowStyles = [];
|
|
835
847
|
const colStyles = [];
|
|
836
848
|
let cellValues = [];
|
|
837
|
-
// Extract cell values and row/column styles first, then write to html.
|
|
849
|
+
// Extract cell values and row/column styles first, then write to html & markdown.
|
|
838
850
|
for (const key in row) {
|
|
839
851
|
let val = row[key];
|
|
840
852
|
if (val instanceof Date) {
|
|
@@ -867,25 +879,30 @@ export function datagridToHtml(datagridState) {
|
|
|
867
879
|
}
|
|
868
880
|
// Apply row styles.
|
|
869
881
|
if (rowStyles.length > 0) {
|
|
870
|
-
|
|
882
|
+
htmlBuf += `\n\t\t<tr class="${rowStyles.join(' ')}">`;
|
|
871
883
|
}
|
|
872
884
|
else {
|
|
873
|
-
|
|
885
|
+
htmlBuf += '\n\t\t<tr>';
|
|
874
886
|
}
|
|
875
887
|
// Write cell values with styles.
|
|
876
888
|
colIdx = 0;
|
|
877
889
|
for (const rowValue of cellValues) {
|
|
878
890
|
if (colStyles[colIdx].styles.length > 0) {
|
|
879
|
-
|
|
891
|
+
htmlBuf += `\n\t\t\t<td class="${colStyles[colIdx].styles.join(' ')}">${rowValue}</td>`;
|
|
880
892
|
}
|
|
881
893
|
else {
|
|
882
|
-
|
|
894
|
+
htmlBuf += `\n\t\t\t<td>${rowValue}</td>`;
|
|
883
895
|
}
|
|
896
|
+
markdownBuf += `| ${rowValue} `;
|
|
884
897
|
colIdx++;
|
|
885
898
|
}
|
|
886
|
-
|
|
899
|
+
htmlBuf += '\n\t\t</tr>';
|
|
900
|
+
markdownBuf += '|\n';
|
|
887
901
|
rowIdx++;
|
|
888
902
|
}
|
|
889
|
-
|
|
890
|
-
return
|
|
903
|
+
htmlBuf += '\n\t</tbody>\n</table>';
|
|
904
|
+
return {
|
|
905
|
+
html: htmlBuf,
|
|
906
|
+
markdown: markdownBuf
|
|
907
|
+
};
|
|
891
908
|
}
|