how too create datatabel in flutter that look like that:
I create one datatable in that table data pass by API and I need to show the data in table forment
in this tabel first two and last two column cell merge size base on middle column data.
DataTable(
columns: const [
DataColumn(label: Text("Zone")),
DataColumn(label: Text("Point")),
DataColumn(label: Text("Designation")),
DataColumn(label: Text("Buckle Number")),
DataColumn(label: Text("Police Name")),
DataColumn(label: Text("District")),
DataColumn(label: Text("Police Station Name")),
DataColumn(label: Text("Age")),
DataColumn(label: Text("Gender")),
DataColumn(label: Text("Number")),
DataColumn(label: Text("Accessories")),
DataColumn(label: Text("Remarks"))
],
rows: controller.eventAssignmentModel.value?.pointAssignments![index]
.assignedPoliceList!
.asMap()
.map((index4, police) => MapEntry(
index4,
DataRow(cells: [
DataCell(Text(controller.eventAssignmentModel.value!.pointAssignments![index].zoneName!)),
DataCell(Text(controller.eventAssignmentModel.value!.pointAssignments![index].pointName!)),
DataCell(Text(police.designation ?? '')),
DataCell(Text(police.buckleNumber ?? '')),
DataCell(Text(police.policeName ?? '')),
DataCell(Text(police.district ?? '')),
DataCell(Text(police.policeStationName ?? '')),
DataCell(Text(police.age ?? '')),
DataCell(Text(police.gender ?? '')),
DataCell(Text(police.number ?? '')),
DataCell(Text(controller.eventAssignmentModel.value!.pointAssignments![index].pointAccessories!)),
DataCell(Text(controller.eventAssignmentModel.value!.pointAssignments![index].pointRemarks!)),
])))
.values
.toList() ??
const [],
),
2
Answers
Flutter doesn’t have rowspan and colspan capabilities as far as i know…
You can try this=> https://flutterawesome.com/flutter-table-but-columns-are-mergable/
You might want to think about in in the opposite way: not merging, but rather splitting cells.
Since
TableRow
accepts any widget in children, you can put a table inside a table, achieving basically the same result. Please check the following code, you can run it in Dartpad.