getting closer to full port of web app starter
This commit is contained in:
@@ -139,7 +139,7 @@ COMPONENT:TIMESERIES_CHART(Request& context)
|
||||
yAxisLeftFormat: <?: json_encode(y_axis_left_format) ?>,
|
||||
yAxisRightFormat: <?: json_encode(y_axis_right_format) ?>
|
||||
});
|
||||
chart.setData(<?= json_encode(context.call["series"]) ?>, <?= json_encode(context.call["x_labels"]) ?>);
|
||||
chart.setData(<?: json_encode(context.call["series"]) ?>, <?: json_encode(context.call["x_labels"]) ?>);
|
||||
window[<?: json_encode("chart_" + chart_id) ?>] = chart;
|
||||
}());
|
||||
</script>
|
||||
@@ -205,7 +205,7 @@ COMPONENT:SORTABLE_TABLE(Request& context)
|
||||
<script>
|
||||
(function () {
|
||||
if (typeof USortableTable === 'undefined') return;
|
||||
USortableTable.init(<?: json_encode(table_id) ?>, <?= json_encode(init_options) ?>);
|
||||
USortableTable.init(<?: json_encode(table_id) ?>, <?: json_encode(init_options) ?>);
|
||||
}());
|
||||
</script>
|
||||
</>
|
||||
@@ -219,8 +219,13 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
starter_register_css("js/ag-grid/ag-theme-alpine.css", context);
|
||||
|
||||
DTree columns = context.call["columns"];
|
||||
if((columns.get_type_name() != "array" || columns["0"]["field"].to_string() == "") &&
|
||||
context.call["items"]["0"].get_type_name() == "array")
|
||||
if(columns.get_type_name() != "array")
|
||||
columns.set_array();
|
||||
bool has_explicit_columns = columns.is_list() &&
|
||||
columns._map.size() > 0 &&
|
||||
columns._map.find("0") != columns._map.end() &&
|
||||
columns["0"]["field"].to_string() != "";
|
||||
if(!has_explicit_columns && context.call["items"]["0"].get_type_name() == "array")
|
||||
{
|
||||
context.call["items"]["0"].each([&](DTree value, String key) {
|
||||
DTree col;
|
||||
@@ -232,14 +237,39 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
columns.push(col);
|
||||
});
|
||||
}
|
||||
if(!columns.is_list())
|
||||
{
|
||||
DTree normalized_columns;
|
||||
normalized_columns.set_array();
|
||||
columns.each([&](DTree column, String key) {
|
||||
if(column.get_type_name() == "array")
|
||||
normalized_columns.push(column);
|
||||
});
|
||||
columns = normalized_columns;
|
||||
}
|
||||
|
||||
DTree row_data = context.call["items"];
|
||||
if(row_data.get_type_name() != "array")
|
||||
row_data.set_array();
|
||||
if(!row_data.is_list())
|
||||
{
|
||||
DTree normalized_rows;
|
||||
normalized_rows.set_array();
|
||||
row_data.each([&](DTree row, String key) {
|
||||
if(row.get_type_name() == "array")
|
||||
normalized_rows.push(row);
|
||||
});
|
||||
row_data = normalized_rows;
|
||||
}
|
||||
|
||||
DTree grid_options;
|
||||
grid_options["pagination"].set_bool(true);
|
||||
grid_options["paginationPageSize"] = first(context.call["options"]["paginationPageSize"].to_string(), "20");
|
||||
grid_options["paginationPageSizeSelector"].set_bool(false);
|
||||
grid_options["suppressMenuHide"].set_bool(true);
|
||||
grid_options["animateRows"].set_bool(true);
|
||||
grid_options["columnDefs"] = columns;
|
||||
grid_options["rowData"] = context.call["items"];
|
||||
grid_options["rowData"] = row_data;
|
||||
|
||||
<>
|
||||
<div class="ag-grid-container" style="margin: 1rem 0;">
|
||||
@@ -258,17 +288,19 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
<script>
|
||||
(function () {
|
||||
if (typeof agGrid === 'undefined') return;
|
||||
const gridOptions = <?= json_encode(grid_options) ?>;
|
||||
new agGrid.Grid(document.getElementById(<?: json_encode(table_id) ?>), gridOptions);
|
||||
const gridOptions = <?: json_encode(grid_options) ?>;
|
||||
const gridElement = document.getElementById(<?: json_encode(table_id) ?>);
|
||||
if (!gridElement) return;
|
||||
const gridApi = agGrid.createGrid(gridElement, gridOptions);
|
||||
document.getElementById(<?: json_encode(table_id + "-search") ?>)?.addEventListener('input', function () {
|
||||
gridOptions.api.setQuickFilter(this.value);
|
||||
gridApi.setQuickFilter(this.value);
|
||||
});
|
||||
document.getElementById(<?: json_encode(table_id + "-clear-filters") ?>)?.addEventListener('click', function () {
|
||||
gridOptions.api.setFilterModel(null);
|
||||
gridOptions.api.setQuickFilter('');
|
||||
gridApi.setFilterModel(null);
|
||||
gridApi.setQuickFilter('');
|
||||
});
|
||||
document.getElementById(<?: json_encode(table_id + "-export-csv") ?>)?.addEventListener('click', function () {
|
||||
gridOptions.api.exportDataAsCsv();
|
||||
gridApi.exportDataAsCsv();
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user