how to combine static column with dynamic?

how to combine static column with dynamic?

example

The first 3 columns are static and the next column the column data fetch from json


8 Replies 1 reply marked as answer

RS Renugadevi Sadagoban Syncfusion Team September 3, 2021 11:02 AM UTC

Hi asep,  
Thanks for your interest in Syncfusion products. 
  
Based on your requirement, we have prepared the sample with JSON data. Here, the sample contains the six columns. We get the static data from the local productCollection for the first three columns e(id,contactName,companyName) alone. And for the remaining columns (city,country,designation)we have fetched the data from JSON file(product_data.json).  
 
factory _ProductFromJson.fromJson(Map<String, dynamic> json, int index) { 
    return _ProductFromJson( 
        id: productCollection[index].id, 
        contactName: productCollection[index].contactName, 
        companyName: productCollection[index].companyName, 
        city: json['city'], 
        country: json['country'], 
        designation: json['designation']); 
  } 
 
  
Prepared following sample for your reference, 
  
Please let us know if need any further assistance. 
 
Regards,   
Renugadevi 



AS asep replied to Renugadevi Sadagoban September 6, 2021 09:03 AM UTC

can you share the product_data json file?



RS Renugadevi Sadagoban Syncfusion Team September 6, 2021 11:04 AM UTC

Hi asep, 
Thanks for the update. 
 
Please find following Json file for your reference, 
 
 
 
 
Please let us know if need any further assistance. 
 
Regards, 
Renugadevi  



AS asep replied to Renugadevi Sadagoban September 7, 2021 02:26 AM UTC

thanks, I will try it first



AS asep replied to Renugadevi Sadagoban September 7, 2021 02:41 AM UTC

sorry, what I mean is that the dynamized column is the column header,

column headers can be incremented according to json data




RS Renugadevi Sadagoban Syncfusion Team September 7, 2021 08:43 AM UTC

Hi asep,

Thanks for your update.

We have prepared the sample as per your requirement. Here, the sample contains eleven columns. The first three columns (id ,salary ,designation) are static columns. And for the remaining columns are created from JSON file using keys (firstName,lastName,docNo,docDate,address,stateName,panNumber,adharNumber).

We get the data from local employeeCollection for static columns. And for remaining columns, we have fetched the data from employee_data.json file. Please note that we have maintained the columns collection in DataGridSource to fetch the data from JSON and local collection.

Refer the following code snippet for columns creation
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter DataGrid Demo'),
),
body: FutureBuilder>(
future: generateProductList(),
builder: (context, snapShot) {
if (snapShot.hasData) {
var jsonColumns = snapShot.data![0];
_employeeDataGridSource.columns = jsonColumns.keys.toList();
// create static columns
_employeeDataGridSource.columns.insert(0, 'id');
_employeeDataGridSource.columns.insert(1, 'designation');
_employeeDataGridSource.columns.insert(2, 'salary');
return SfDataGrid(
source: _employeeDataGridSource,
columns: _employeeDataGridSource.columns
.map((columnName) => GridColumn(
columnName: columnName,
label: Container(
padding: EdgeInsets.all(3),
alignment: Alignment.center,
child: Text(
columnName.toUpperCase(),
overflow: TextOverflow.ellipsis,
),
)))
.toList());
}
return Center(
child: CircularProgressIndicator(),
);
},
));
}


Please refer the above sample. And let us know if need any further assistance.

Regards,

Renugadevi


Marked as answer

AS asep replied to Renugadevi Sadagoban September 7, 2021 08:44 AM UTC

thank you very much, i will try



RS Renugadevi Sadagoban Syncfusion Team September 7, 2021 10:57 AM UTC

Hi asep,  
 
Thanks for the update.  

Please let us know if you require any further assistance on this.   
 
Regards, 
Renugadevi  


Loader.
Up arrow icon