flutter - Flutter Web 中带有粘性页眉和页脚的动态表格
问题描述
我在我的颤振网络应用程序中使用表格。我必须粘贴表格的页眉和页脚并动态创建表格。我正在使用 syncfusion_flutter_datagrid 库。使用这个库我可以粘贴页眉和页脚但不能动态创建表格。在同步融合示例中,列和行是硬编码的。我不想对列和行进行硬编码。我想让它动态完成。在使表动态化时,任何帮助都将不胜感激。下面是我提供的示例 json必须动态创建表。谢谢!!参考:https ://pub.dev/packages/syncfusion_flutter_datagrid
解决方案
Thanks for contacting Syncfusion support. Based on the provided information, we suspect that you are trying to add the column at runtime. You can maintain an instance in the type of List, add the columns to this instance and assign this instance to the columns property of SfDataGrid. You can add any column at run time to the instance and call setState() to rebuild the datagrid.
List<GridColumn> _columns;
@override
void initState() {
super.initState();
employees = getEmployeeData();
employeeDataSource = EmployeeDataSource(employeeData: employees);
_columns = _getColumns();
}
SfDataGrid _buildDataGrid() {
return SfDataGrid(
source: employeeDataSource,
footerFrozenRowsCount: 1,
columnWidthMode: ColumnWidthMode.fill,
columns: _columns);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter DataGrid Demo'),
),
body: Column(
children: [
Row(
children: [
SizedBox(
width: 60,
),
FlatButton(
color: Colors.red[100],
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
),
child: Center(
child: Text(
'Add Column',
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
onPressed: () {
setState(() {
_columns.add(
GridNumericColumn(mappingName: 'salary', headerText: 'Salary'));
});
},
),
SizedBox(
width: 20,
),
FlatButton(
color: Colors.red[100],
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
),
child: Center(
child: Text(
'Remove Column',
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
onPressed: () {
setState(() {
_columns.removeAt(1);
});
},
),
],
),
Expanded(child: _buildDataGrid())
],
),
);
}
SampleLink: https://www.syncfusion.com/downloads/support/directtrac/317477/ze/main424752137
Please provide more details in case we misunderstood your requirement.
推荐阅读
- javascript - 使用 .mjs 文件时解析节点中的路径
- c# - EF Core - 使用 Automapper 从 OData 返回映射的多对多关系
- r - 在 R Markdown 脚注中包含一个块
- c++ - 视差图后过滤
- php - Readfile 是下载外部文件的最佳解决方案?
- karate - 我们可以在 BlazeMeter 中执行空手道加特林测试吗?
- node.js - 将节点版本降级到 10.13.0
- android - 如何在android中的手势描述可访问性中使向下滑动手势(滚动)连续
- string - Julia 将符号转换为字符串
- node.js - Mongodb/Mongoose - 聚合以将同一集合中的所有匹配文档分组到一个数组中