how to make if the value is the same as 1 line only?

how to make if the value is the same as 1 line only?



16 Replies 1 reply marked as answer

SR Sangeetha Raju Syncfusion Team November 25, 2021 07:01 AM UTC

Hi Asep, 
 
Thank you for contacting Syncfusion support. 
 
We could not clearly understand your requirement. Can you please provide more details about your requirement?  
 
It will help us to understand and provide the prompt solution at earliest. 
 
Regards, 
Sangeetha Raju. 



AS asep November 25, 2021 09:05 AM UTC

ah ok
before, data show like this.


but i want data cloumn nominal and unit only show in 1 line (row), so i want table showing like this




SR Sangeetha Raju Syncfusion Team November 25, 2021 02:19 PM UTC

Hi Asep, 
 
Thanks for the update. 
 
SfDataGrid requires the list of DataGridRow. Based on your requirement, you should prepare the DataGridRow collection from the underlying collection. You can get the grouped items of your employee collection using groupBy top level function. This method will generate the group of items which has the same values. You can then prepare the DataGridRow collection by iterating the grouped rows.  
 
In the below example, we have created new collection based on the CaraBayar. Please refer the following code snippet. 
 
  List<Employee> getEmployeeData() { 
    return [ 
      Employee('ANGUSRAN', 2.00, 264000000.00, 0, 0), 
      Employee('KPR', 1.00, 132000000.00, 0, 0), 
      Employee('ANGUSRAN', 0.00, 0.00, 2.00, 42000000.00), 
      Employee('KPR', 0, 0, 1.00, 500000000.00), 
    ]; 
  } 
 
class EmployeeDataGridSource extends DataGridSource { 
  EmployeeDataGridSource({required List<Employee> employeeData}) { 
    var groupedRows = groupBy(employeeData, (Employee e) => e.caraBayar); 
 
    List<Employee> newCollection = []; 
    for (var v in groupedRows.values) { 
      String columnName = ''; 
      double column1 = 0; 
      double column2 = 0; 
      double column3 = 0; 
      double column4 = 0; 
      v.asMap().forEach((i, value) { 
        columnName = value.caraBayar; 
        column1 += value.augUnit; 
        column2 += value.augNominal; 
        column3 += value.sepUnit; 
        column4 += value.sepNominal; 
      }); 
      newCollection 
          .add(Employee(columnName, column1, column2, column3, column4)); 
    } 
    _dataGridRows = newCollection 
        .map<DataGridRow>((e) => DataGridRow(cells: [ 
              DataGridCell<String>(columnName: 'caraBayar', value: e.caraBayar), 
              DataGridCell<double>(columnName: 'augUnit', value: e.augUnit), 
              DataGridCell<double>( 
                  columnName: 'augNominal', value: e.augNominal), 
              DataGridCell<double>(columnName: 'sepUnit', value: e.sepUnit), 
              DataGridCell<double>( 
                  columnName: 'sepNominal', value: e.sepNominal), 
            ])) 
        .toList(); 
  } 
 
  List<DataGridRow> _dataGridRows = []; 
 
  @override 
  List<DataGridRow> get rows => _dataGridRows; 
 
  @override 
  DataGridRowAdapter buildRow(DataGridRow row) { 
    return DataGridRowAdapter( 
        cells: row.getCells().map<Widget>((e) { 
      return Container( 
        alignment: Alignment.center, 
        padding: const EdgeInsets.all(8.0), 
        child: Text(e.value.toString(), overflow: TextOverflow.ellipsis), 
      ); 
    }).toList()); 
  } 
} 
 
 
We have prepared a sample for your reference. Please find the sample from the following link. 
 
 
Please let us know if you would require any further assistance. 
 
Regards, 
Sangeetha Raju. 



AS asep replied to Sangeetha Raju November 26, 2021 02:39 AM UTC

how to handle if dynamic column based on selected number of months?

because it is not possible to add value in the class employess



SR Sangeetha Raju Syncfusion Team November 26, 2021 12:12 PM UTC

Hi Asep, 
 
Thanks for the update. 
 
The SfDataGrid will display the defined columns. If the columns are added dynamically, you should prepare the DataGridRows collection based on the dynamic columns. Can you please provide the details for the below queries? 
 
·                How are you getting the data for your given DataGrid UI? We suspect that you should have maintained the original collection to create the rows for DataGrid. 
·                How are you creating the columns for the DataGrid?  
·                If possible, can you please provide the sample?  
 
It is easier for us to understand your workflow and provide the solution. 
 
Regards, 
Sangeetha Raju. 



AS asep replied to Sangeetha Raju November 29, 2021 03:01 AM UTC

this is my code and response json same like this

 List getEmployeeData() { 
    return [ 
      Employee('ANGUSRAN', 2.00, 264000000.00, '2021-08'), 
      Employee('KPR', 1.00, 132000000.00, '2021-09'), 
      Employee('ANGUSRAN', 2.00, 42000000.00, '2021-09'), 
      Employee('KPR', 1.00, 500000000.00, '2021-09'), 
    ]; 
  } 


Attachment: data_grid_rekap_penjualan_58cf2709.zip



SR Sangeetha Raju Syncfusion Team November 29, 2021 02:03 PM UTC

Hi Asep, 
 
Sorry for the inconvenience. 
 
Currently, we are analyzing the reported scenarios. We need some more time to analyze this scenario at our end. We will check and update you the further details on or before December 1, 2021. 
 
Regards, 
Sangeetha Raju. 



AS asep replied to Sangeetha Raju November 30, 2021 02:37 AM UTC

thank you  I hope it can be resolved



SR Sangeetha Raju Syncfusion Team November 30, 2021 01:47 PM UTC

Hi Asep, 
 
Thanks for the update. 
 
As we said earlier, we will analyze the reported query and update you the further details on December 1, 2021. 
 
Regards, 
Sangeetha Raju. 



SR Sangeetha Raju Syncfusion Team December 1, 2021 03:46 PM UTC

Hi Asep, 
 
Thanks for your patience. 
 
We have referred the provided code snippets. We can understand the codes to add the columns based on the different months. You can handle dynamic columns by providing the corresponding column name and value in the collection. In the below example, we have added columns in the button click. Please refer the following code snippet. 
  @override 
  Widget build(BuildContext context) { 
     return Scaffold( 
        appBar: AppBar(title: const Text('Syncfusion Flutter DataGrid')), 
        body: Column(children: [ 
          TextButton( 
              child: const Align( 
                  alignment: Alignment.center, child: Text('Add-Column')), 
              onPressed: () { 
                months.add('Oct-2020'); 
                _stackedHeaderCell.add(StackedHeaderCell( 
                  columnNames: <String>[ 
                    'unit2', 
                    'nominal2', 
                  ], 
                  child: Container( 
                      padding: const EdgeInsets.all(4.0), 
                      alignment: Alignment.center, 
                      child: Text(months[2])), 
                )); 
                _gridColumns.add(GridColumn( 
                    columnName: 'unit2', 
                    label: Container( 
                        padding: const EdgeInsets.all(16.0), 
                        alignment: Alignment.center, 
                        child: const Text( 
                          'Unit', 
                          overflow: TextOverflow.ellipsis, 
                        )))); 
                _gridColumns.add(GridColumn( 
                    columnName: 'nominal2', 
                    label: Container( 
                        padding: const EdgeInsets.all(16.0), 
                        alignment: Alignment.center, 
                        child: const Text( 
                          'Nominal', 
                          overflow: TextOverflow.ellipsis, 
                        )))); 
                _employeeDataSource 
                    .buildDataGridRows(_employeeDataSource.newCollection); 
                _employeeDataSource.updateDataGrid(); 
              }), 
          Expanded( 
              child: SfDataGrid( 
                  source: _employeeDataSource, 
                  gridLinesVisibility: GridLinesVisibility.both, 
                  headerGridLinesVisibility: GridLinesVisibility.both, 
                  stackedHeaderRows: [ 
                    StackedHeaderRow(cells: _stackedHeaderCell) 
                  ], 
                  columns: _gridColumns)) 
        ])); 
  } 
 
 
 
 
We have prepared the sample by adding column for your reference. Please find the sample from the following link. 
 
 
Please let us know if you need any further assistance.  
 
Regards, 
Sangeetha Raju. 



AS asep replied to Sangeetha Raju December 2, 2021 06:57 AM UTC

thank you very much, i will try it first



SR Sangeetha Raju Syncfusion Team December 3, 2021 04:22 AM UTC

Hi Asep, 
 
Thanks for the update. We will wait to hear from you. Please test at your end once you find time. Also, please let us know if you require any further assistance on this.  we will be happy to assist you.  
 
Regards, 
Sangeetha Raju.


AS asep December 3, 2021 06:48 AM UTC

sorry I want to ask again in this section,

how to sum double column if dynamic?

because the data may appear as many as 12 or more columns

because it is not possible if I have to add double column1 to 12 columns or more

for (var v in groupedRows.values) {
String columnName = '';
Map<String, double> unitCol = {};
Map<String, double> nominalCol = {};
double column1 = 0;
double column2 = 0;
double column3 = 0;
double column4 = 0;
double column5 = 0;
double column6 = 0;
DateTime column7 = DateTime.now();
v.asMap().forEach((key, value) {
columnName = value.caraBayar;
column1 += value.unit['unit0']!;
unitCol['unit0'] = column1;
column2 += value.nominal['nominal0']!;
nominalCol['nominal0'] = column2;
column3 += value.unit['unit1']!;
unitCol['unit1'] = column3;
column4 += value.nominal['nominal1']!;
nominalCol['nominal1'] = column4;
column5 += value.unit['unit2']!;
unitCol['unit2'] = column5;
column6 += value.nominal['nominal2']!;
nominalCol['nominal2'] = column6;
column7 = value.date;
});
newCollection.add(Employee(columnName, unitCol, nominalCol, column7));
}


SR Sangeetha Raju Syncfusion Team December 3, 2021 11:46 AM UTC

Hi Asep, 
 
Thanks for the update.  
 
You can create columns dynamically based on the data. Also, you should create the column as a collection to add more columns. In the below example, we have created columns dynamically. Please refer the following code snippet.   
 
EmployeeDataGridSource({required List<Employee> employeeData}) { 
    late int length; 
    var groupedRows = groupBy(employeeData, (Employee e) { 
      length= e.unit.length; 
      return e.caraBayar; 
    }); 
 
    for (var v in groupedRows.values) { 
      String columnName = ''; 
      Map<String, double> unitCol = {}; 
      Map<String, double> nominalCol = {}; 
      List<double> unitColumn = List<double>.filled(length, 0.0); 
      List<double> nominalColumn = List<double>.filled(length, 0.0);  
      DateTime column7 = DateTime.now(); 
      v.asMap().forEach((key, value) { 
        columnName = value.caraBayar; 
        for (int i = 0; i < length; i++) { 
          unitColumn[i] += value.unit['unit$i']!; 
          unitCol['unit$i'] = unitColumn[i]; 
          nominalColumn[i] += value.nominal['nominal$i']!; 
          nominalCol['nominal$i'] = nominalColumn[i]; 
        } 
        column7 = value.date; 
      }); 
 
      newCollection.add(Employee(columnName, unitCol, nominalCol, column7)); 
    } 
    buildDataGridRows(newCollection); 
  } 
  List<Employee> newCollection = []; 
  buildDataGridRows(List<Employee> newCollection) { 
    _dataGridRows = newCollection.map<DataGridRow>((e) { 
      dynamic dtcell = [ 
        DataGridCell<dynamic>(columnName: 'carabayar', value: e.caraBayar) 
      ]; 
 
      for (int i = 0; i < months.length; i++) { 
        dtcell.add(DataGridCell<dynamic>( 
            columnName: 'unit$i', value: e.unit['unit$i'])); 
        dtcell.add(DataGridCell<dynamic>( 
            columnName: 'nominal$i', value: e.nominal['nominal$i'])); 
      } 
      return DataGridRow(cells: dtcell); 
    }).toList(); 
  } 
 
  List<DataGridRow> _dataGridRows = []; 
 
  @override 
  List<DataGridRow> get rows => _dataGridRows; 
 
  @override 
  DataGridRowAdapter buildRow(DataGridRow row) { 
    return DataGridRowAdapter( 
        cells: row.getCells().map<Widget>((e) { 
      return Container( 
        alignment: Alignment.center, 
        padding: const EdgeInsets.all(8.0), 
        child: Text(e.value.toString(), overflow: TextOverflow.ellipsis), 
      ); 
    }).toList()); 
  } 
 
  void updateDataGrid() { 
    notifyListeners(); 
  } 
} 
 
Please let us know if you require any further assistance.  
 
Regards, 
Sangeetha Raju. 


Marked as answer

AS asep replied to Sangeetha Raju December 4, 2021 03:16 AM UTC

thank you very much this is very helpful



SR Sangeetha Raju Syncfusion Team December 4, 2021 04:38 AM UTC

Hi Asep, 
 
Thank you for the update. 
 
We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 
 
Regards, 
Sangeetha Raju. 


Loader.
Up arrow icon