ColumnConfig.fromJson constructor

ColumnConfig.fromJson(
  1. Map<String, dynamic> json
)

Parse from visualResponse JSON

Implementation

factory ColumnConfig.fromJson(Map<String, dynamic> json) {
  // Parse nested columns if present
  List<ColumnConfig>? nestedColumns;
  if (json['columns'] is List) {
    nestedColumns = (json['columns'] as List)
        .whereType<Map<String, dynamic>>()
        .map((colJson) => ColumnConfig.fromJson(colJson))
        .toList();
  }

  // Match Angular: column.field = column.field ? column.field : column.title
  // For chart columns, Angular falls back field to title when field is not provided
  final rawField = json['field']?.toString() ?? '';
  final rawTitle = json['title']?.toString() ?? '';
  final columnType = json['columnType']?.toString() ?? 'stringColumn';
  final field = (rawField.isNotEmpty) ? rawField
      : (columnType == 'chartColumn' ? rawTitle : rawField);
  // Parse optional headerStyle
  Color? headerBgColor;
  Color? headerTxtColor;
  if (json['headerStyle'] != null && json['headerStyle'] is Map<String, dynamic>) {
    final headerStyle = json['headerStyle'] as Map<String, dynamic>;
    if (headerStyle['backgroundColor'] != null) {
      headerBgColor = _parseColor(headerStyle['backgroundColor']);
    }
    if (headerStyle['color'] != null) {
      headerTxtColor = _parseColor(headerStyle['color']);
    }
  }

  return ColumnConfig(
    field: field,
    title: rawTitle,
    columnType: columnType,
    headerSort: _parseBooleanValue(json['headerSort'], defaultValue: true),
    resizable: _parseBooleanValue(json['resizable'], defaultValue: true),
    width: _parseWidth(json['fixedColumnWidth']),
    hozAlign: json['hozAlign']?.toString() ?? 'left',
    sorter: json['sorter']?.toString(),
    headerWordWrap: _parseBooleanValue(json['headerWordWrap'], defaultValue: true),
    formatterParams: _parseFormatterParams(json['formatterParams']),
    headerFilter: _parseHeaderFilter(json['headerFilter']),
    headerFilterPlaceholder: json['headerFilterPlaceholder']?.toString(),
    columns: nestedColumns,
    headerBackgroundColor: headerBgColor,
    headerTextColor: headerTxtColor,
    readOnly: _parseBooleanValue(json['readOnly'], defaultValue: false),
    variableHeight: _parseBooleanValue(json['variableHeight'], defaultValue: true),
  );
}