|
|
|
@ -104,12 +104,16 @@ class _DataGridViewState extends State<DataGridView> {
@@ -104,12 +104,16 @@ class _DataGridViewState extends State<DataGridView> {
|
|
|
|
|
).convert(content, fieldDelimiter: _delimiter); |
|
|
|
|
|
|
|
|
|
// 清理数据并添加序号列 |
|
|
|
|
final cleanedData = csvTable |
|
|
|
|
.where((row) => row.isNotEmpty && row.any((cell) => cell.toString().trim().isNotEmpty)) |
|
|
|
|
final cleanedData = |
|
|
|
|
csvTable |
|
|
|
|
.where( |
|
|
|
|
(row) => row.isNotEmpty && row.any((cell) => cell.toString().trim().isNotEmpty), |
|
|
|
|
) |
|
|
|
|
.toList(); // 先转换为List |
|
|
|
|
|
|
|
|
|
// 添加序号列 |
|
|
|
|
final dataWithIndex = cleanedData.asMap().entries.map((entry) { |
|
|
|
|
final dataWithIndex = |
|
|
|
|
cleanedData.asMap().entries.map((entry) { |
|
|
|
|
final index = entry.key; |
|
|
|
|
final row = entry.value; |
|
|
|
|
// 如果是标题行(第一行),添加"序号"列标题 |
|
|
|
@ -153,7 +157,7 @@ class _DataGridViewState extends State<DataGridView> {
@@ -153,7 +157,7 @@ class _DataGridViewState extends State<DataGridView> {
|
|
|
|
|
...headers.sublist(1).map<GridColumn>((header) { |
|
|
|
|
return GridColumn( |
|
|
|
|
columnName: header.toString(), |
|
|
|
|
width: 150, // 固定列宽 |
|
|
|
|
minimumWidth: 150, // 固定列宽 |
|
|
|
|
label: Container( |
|
|
|
|
padding: const EdgeInsets.all(8.0), |
|
|
|
|
color: Colors.grey[200], |
|
|
|
@ -171,7 +175,9 @@ class _DataGridViewState extends State<DataGridView> {
@@ -171,7 +175,9 @@ class _DataGridViewState extends State<DataGridView> {
|
|
|
|
|
columns: columns, |
|
|
|
|
gridLinesVisibility: GridLinesVisibility.both, |
|
|
|
|
headerGridLinesVisibility: GridLinesVisibility.both, |
|
|
|
|
columnWidthMode: ColumnWidthMode.fitByCellValue, |
|
|
|
|
allowColumnsResizing: true, |
|
|
|
|
columnResizeMode: ColumnResizeMode.onResizeEnd, |
|
|
|
|
columnWidthMode: ColumnWidthMode.none, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|