我添加SfDataGrid
到我的网络应用程序在Flutter
每件事都很好,只有一个问题,我面临如下。
下面是我为SfDataGrid '设计的DataSourceMethod
class EmployeeDataSource extends DataGridSource {
EmployeeDataSource({required List<Employee> employees}) {
_employees = employees
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<int>(columnName: 'id', value: e.id),
DataGridCell<String>(columnName: 'status', value: e.status),
DataGridCell<String>(columnName: 'name', value: e.name),
DataGridCell<String>(columnName: 'heartbeat', value: e.heartbeat),
DataGridCell<String>(columnName: 'visibility', value: e.visibility),
DataGridCell<String>(columnName: 'location', value: e.location),
DataGridCell<String>(columnName: 'connectors', value: e.connectors),
DataGridCell<String>(columnName: 'actions', value: e.actions),
])).toList();
}
List<DataGridRow> _employees = [];
@override
List<DataGridRow> get rows => _employees;
@override
DataGridRowAdapter? buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((dataGridCell) {
return dataGridCell.columnName == "status" ?
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16.0),
child: Icon(
Icons.circle,
color:
colorFromCssString(
functions.getStatusColor(dataGridCell.value),
defaultColor:
Colors.black,
),
size:
24,
),
) : dataGridCell.columnName == "actions" ?
Row(
children: [
FlutterFlowIconButton(
borderColor: Colors.transparent,
borderRadius: 30,
borderWidth: 1,
buttonSize: 60,
icon: Icon(
Icons.edit,
color: Color(0xFF13345B),
size: 30,
),
onPressed: () {
print('IconButton pressed ...');
},
),
FlutterFlowIconButton(
borderColor: Colors.transparent,
borderRadius: 30,
borderWidth: 1,
buttonSize: 60,
icon: Icon(
Icons.remove_red_eye,
color: Color(0xFF13345B),
size: 30,
),
onPressed: () async {
//So When I Tap On This Button I need Entire Row Details.
},
),
],
) :
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16.0),
child: Text(
dataGridCell.value.toString(),
textAlign: TextAlign.start,
),
);
}).toList());
}
}
我无法获得索引时,我点击按钮。任何人都知道如何获得一个特定的行数据时,点击一个按钮。我搜索了很多,但我只得到数据onCellTap
方法不在按钮,我已经添加在DataGridRowAdapter
。
请帮助我,如果有人有任何想法。提前感谢
1条答案
按热度按时间vlju58qv1#
您可以从buildRow方法中的row属性获取相应行的全部详细信息。