syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.59k stars 776 forks source link

under sfDataGrid how to concatenate two or more value in single row #2059

Closed MukeshWrms closed 1 month ago

MukeshWrms commented 2 months ago

Use case

i have need the one column under two or more value show

country and department

how can do this

DataSourceDepartment({required List employeeData}) { _employeeData = employeeData .map((e) => DataGridRow(cells: [ DataGridCell( columnName: 'id', value: getReturnSr(employeeData.indexOf(e))), DataGridCell(columnName: 'project', value: e.projectName), DataGridCell(columnName: 'country', value: e.level1Name), DataGridCell( columnName: 'department', value: e.level2Name.toString()),

        ]))
    .toList();

}

Proposal

i have need the one column under two or more value show

country and department

how can do this

DataSourceDepartment({required List employeeData}) { _employeeData = employeeData .map((e) => DataGridRow(cells: [ DataGridCell( columnName: 'id', value: getReturnSr(employeeData.indexOf(e))), DataGridCell(columnName: 'project', value: e.projectName), DataGridCell(columnName: 'country', value: e.level1Name), DataGridCell( columnName: 'department', value: e.level2Name.toString()),

        ]))
    .toList();

}

abineshPalanisamy commented 1 month ago

Hi @MukeshWrms ,

You can build DataGrid rows in the DataSource by concatenating two or more values into a single row. In our example, the SfDataGrid widget defines a column named name_designation, where the concatenated values of the name and designation fields are displayed. In the DataSource class, the DataGridCell for the name_designation column is created by combining the name and designation fields. The expression value: '${e.name} - ${e.designation}' concatenates the name and designation values.

We have included a sample for your reference. Please review it for more details and adapt it to suit your specific requirements.

Regards, Abinesh P

MukeshWrms commented 1 month ago

this is working but, i have used user image url and name how can do this.

DataGridCell( columnName: 'asset', value: '${e.assetIconUrl} - ${e.assetName}'),

// Avatar cell if (dataGridCell.columnName == 'asset') { if (dataGridCell.value == null) return Container(); return Row( children: [ Padding( padding: const EdgeInsets.only(left: 4.0, right: 4), child: Container( alignment: Alignment.centerLeft, width: 35, height: 35, child: CustomImageWithType( url: dataGridCell.value.toString(), fit: BoxFit.cover, height: 35, width: 35, ), ), ), Text('Income'), ], ); }

with image execution given the error only image value is working but with concatenates other is not working.

abineshPalanisamy commented 1 month ago

Hi @MukeshWrms ,

Based on your requirements, we have prepared a sample to concatenate the image and name values. In our example, we use a Map<String, dynamic> in the DataGridCell to hold both the image and the name. This allows us to store and access these two different types of data together. The column named image_name will hold both the image and the name, with the value being a map that contains the image (e.image) and the name (e.name).

We have included a sample for your reference. Please review it for more details and adapt it to suit your specific requirements.

Regards, Abinesh P

MukeshWrms commented 1 month ago

Thanks its working .