Hi
I need to include a row for editing at the top of the grid instead of the bottom. The other grids should scroll down as usual.
Any clue?
Thanks in advance
Regards
Can any
We suspect that your requirement is to show an additional row on top and add the new row when you have completed the editing on top of the row. Can you please confirm whether you want something like below?
Before entering into edit mode on top row
After entering into edit mode
Regards,
Tamilarasan
Tamilarasan
Thanks for your prompt response. Yes, this is what I need. Can you tell me also how to include the filter in the columns as shown in your example?
Regards
Tamilarasan
Thanks for the reply. Can you tell me how do I sort the rows based on a column (date) ?
I need also to show the column totals at the end of the screen ? Can you help me?
Regards
|
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Syncfusion Flutter DataGrid')),
body: SfDataGrid(
source: _employeeDataSource,
allowSorting: true,
columns: getColumns,
));
} |
|
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Syncfusion Flutter DataGrid')),
body: SfDataGrid(
source: _employeeDataSource,
allowSorting: true,
columns: getColumns,
tableSummaryRows: [
GridTableSummaryRow(
color: Colors.amber,
showSummaryInRow: false,
columns: [
const GridSummaryColumn(
name: 'Salary',
columnName: 'salary',
summaryType: GridSummaryType.sum),
const GridSummaryColumn(
name: 'ID',
columnName: 'id',
summaryType: GridSummaryType.count)
],
position: GridTableSummaryRowPosition.bottom)
],
));
}
In DataGrid Source Class:
@override
Widget? buildTableSummaryCellWidget(
GridTableSummaryRow summaryRow,
GridSummaryColumn? summaryColumn,
RowColumnIndex rowColumnIndex,
String summaryValue) {
return Container(
padding: const EdgeInsets.all(15.0),
alignment: Alignment.center,
child: Text(summaryValue),
);
} |
Hi Tamilarasan
Thanks for your help. Can you also tell me how to format the Cells with decimal digits (7,00, for example) and format the cell in Brasilian Currency (REAL)?
Regards
|
@override
DataGridRowAdapter? buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((dataGridCell) {
late dynamic value;
if (dataGridCell.columnName == 'id') {
final decimalformetter = NumberFormat.decimalPattern();
value = decimalFormetter.format(dataGridCell.value);
} else if (dataGridCell.columnName == 'salary') {
final currencyFormatter =
NumberFormat.currency(name: 'BRL', symbol: 'R\$', decimalDigits: 2);
value = formatter.format(dataGridCell.value);
} else {
value = dataGridCell.value;
}
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
value.toString(),
overflow: TextOverflow.ellipsis,
));
}).toList());
} |
Thanks, Tamilarasan!
It worked! Can you help me with three other issues?
1) I need to scroll the rows when the Summary row appears.
2) The last column is truncated even when the table scrolls horizontally. Is there a way to show the whole cell?
3) I managed to format the cells inside the table as you directed, but I can't do it in the summary row. Can you help me?
|
@override
Widget? buildTableSummaryCellWidget(
GridTableSummaryRow summaryRow,
GridSummaryColumn? summaryColumn,
RowColumnIndex rowColumnIndex,
String summaryValue) {
late dynamic value;
if (summaryColumn == null) {
dynamic firstValue;
dynamic secondValue;
String string = summaryValue;
final splitted = string.split(' ');
firstValue = double.parse(splitted.elementAt(2));
secondValue = double.parse(splitted.elementAt(7));
final decimalformetter = NumberFormat.decimalPattern();
firstValue = decimalformetter.format(firstValue);
secondValue = decimalformetter.format(secondValue);
splitted.removeAt(2);
splitted.replaceRange(2, 2, [firstValue]);
splitted.removeAt(7);
splitted.replaceRange(7, 7, [secondValue]);
value =
('${splitted.elementAt(0)} ${splitted.elementAt(1)} ${splitted.elementAt(2)} ${splitted.elementAt(3)} ${splitted.elementAt(4)} ${splitted.elementAt(5)} ${splitted.elementAt(6)} ${splitted.elementAt(7)}')
.toString();
} else {
value = summaryValue;
}
return Container(
padding: const EdgeInsets.all(15.0),
alignment: Alignment.center,
child: Text(value),
);
} |
Thanks, Tamilrasan !
Below is the screenshot of the Datagrid. The "Valor" column is truncated. Does not show the entire content. This is the last column. Is there a way to show the full content of this column?
Thanks in advance
Regards
|
final CustomColumnSizer _customColumnSizer = CustomColumnSizer();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter SfDataGrid'),
),
body: SfDataGrid(
source: _employeeDataSource,
columnSizer: _customColumnSizer,
columnWidthMode: ColumnWidthMode.fitByCellValue,
columns: getColumns(),
),
);
}
class CustomColumnSizer extends ColumnSizer {
@override
double computeCellWidth(GridColumn column, DataGridRow row, Object? cellValue,
TextStyle textStyle) {
if (column.columnName == 'salary') {
final formatter =
NumberFormat.currency(name: 'BRL', symbol: 'R\$', decimalDigits: 2);
cellValue = formatter.format(cellValue);
}
return super.computeCellWidth(column, row, cellValue, textStyle);
}
} |