Latest source merged from Syncfusion
This commit is contained in:
Родитель
8a270776ae
Коммит
12e6cc03e8
|
@ -42,58 +42,45 @@ import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MediaQuery(
|
||||
data: MediaQueryData(textScaleFactor: 1.5),
|
||||
child: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
data: MediaQueryData(textScaleFactor: 1.5),
|
||||
child: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
visible: false,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -110,63 +97,51 @@ The row heights in `SfDataGrid` will be automatically adjusted based on the [vis
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Theme(
|
||||
data: ThemeData(visualDensity: VisualDensity.compact),
|
||||
child: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
data: ThemeData(visualDensity: VisualDensity.compact),
|
||||
child: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
visible: false,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
|
|
@ -25,56 +25,44 @@ Column can be bound to a property in data object using [GridColumn.columnName](h
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
body: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -93,57 +81,45 @@ Widget build(BuildContext context) {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
body: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
visible: false,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
visible: false,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -162,57 +138,45 @@ Widget build(BuildContext context) {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
body: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
width: 100.0,
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
width: 100.0,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
|
|
@ -31,68 +31,56 @@ The following example shows how to set the width equally for column based on the
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'city',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'city',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'city',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'city',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -113,56 +101,47 @@ By default, the autofit calculation is performed for only visible rows. You can
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
columnWidthCalculationRange: ColumnWidthCalculationRange.allRows,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
columnWidthCalculationRange: ColumnWidthCalculationRange.allRows,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
softWrap: false,
|
||||
)))
|
||||
]);
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -181,59 +160,50 @@ By default, the EdgeInsets.all(16.0) is added with the auto width or height valu
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Designation',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
autoFitPadding: EdgeInsets.all(10.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
softWrap: false,
|
||||
)))
|
||||
]);
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
@ -260,7 +230,7 @@ class EmployeeDataSource extends DataGridSource {
|
|||
cells: row.getCells().map<Widget>((cell) {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
// The autoFitPadding and the cell padding value should be same.
|
||||
// The autoFitPadding and the cell padding value should be same.
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: Text(cell.value.toString()),
|
||||
);
|
||||
|
@ -285,52 +255,50 @@ final CustomColumnSizer _customColumnSizer = CustomColumnSizer();
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnSizer: _customColumnSizer,
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name',
|
||||
source: _employeeDataSource,
|
||||
columnSizer: _customColumnSizer,
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Name',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.italic)))),
|
||||
GridColumn(
|
||||
columnName: 'Designation',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
);
|
||||
fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Designation',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
autoFitPadding: EdgeInsets.all(12.0),
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
]);
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
@ -356,14 +324,13 @@ class EmployeeDataSource extends DataGridSource {
|
|||
return DataGridRowAdapter(
|
||||
cells: row.getCells().map<Widget>((e) {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: Text(e.value.toString(),
|
||||
style: (e.columnName == 'Name' || e.columnName == 'Designation')
|
||||
? TextStyle(
|
||||
fontWeight: FontWeight.bold, fontStyle: FontStyle.italic)
|
||||
: null),
|
||||
);
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: Text(e.value.toString(),
|
||||
style: (e.columnName == 'Name' || e.columnName == 'Designation')
|
||||
? TextStyle(
|
||||
fontWeight: FontWeight.bold, fontStyle: FontStyle.italic)
|
||||
: null));
|
||||
}).toList());
|
||||
}
|
||||
}
|
||||
|
@ -402,63 +369,56 @@ class CustomColumnSizer extends ColumnSizer {
|
|||
By default, the cell width is calculated based on the `DataGridCell.value` property. To autofit the cell width based on the displayed formatted value (i.e, DateFormat and NumberFormat), simply override the `computeCellWidth` method and return the super method with the required `cellValue`.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
{% highlight Dart %}
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
final CustomColumnSizer _customColumnSizer = CustomColumnSizer();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnSizer: _customColumnSizer,
|
||||
columnWidthMode: ColumnWidthMode.fitByCellValue,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'DOB',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'DOB',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
source: _employeeDataSource,
|
||||
columnSizer: _customColumnSizer,
|
||||
columnWidthMode: ColumnWidthMode.fitByCellValue,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'ID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'DOB',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'DOB',
|
||||
softWrap: false,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'Salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
softWrap: false,
|
||||
)))
|
||||
]);
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
@ -486,7 +446,8 @@ class EmployeeDataSource extends DataGridSource {
|
|||
if (e.columnName == 'DOB') {
|
||||
cellValue = DateFormat.yMMMMd('en_US').format(e.value);
|
||||
} else if (e.columnName == 'Salary') {
|
||||
cellValue = NumberFormat.simpleCurrency(decimalDigits: 0).format(e.value);
|
||||
cellValue =
|
||||
NumberFormat.simpleCurrency(decimalDigits: 0).format(e.value);
|
||||
} else {
|
||||
cellValue = e.value.toString();
|
||||
}
|
||||
|
@ -507,7 +468,8 @@ class CustomColumnSizer extends ColumnSizer {
|
|||
if (column.columnName == 'DOB') {
|
||||
cellValue = DateFormat.yMMMMd('en_US').format(cellValue as DateTime);
|
||||
} else if (column.columnName == 'Salary') {
|
||||
cellValue = NumberFormat.simpleCurrency(decimalDigits: 0).format(cellValue);
|
||||
cellValue =
|
||||
NumberFormat.simpleCurrency(decimalDigits: 0).format(cellValue);
|
||||
}
|
||||
|
||||
return super.computeCellWidth(column, row, cellValue, textStyle);
|
||||
|
@ -532,57 +494,47 @@ While setting `SfDataGrid.columnWidthMode` as `lastColumnFill` remaining width i
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
columns: <GridColumn>[
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -598,57 +550,47 @@ The below example shows Name column is set as `lastColumnFill` mode.
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -666,15 +608,15 @@ Returning true may impact performance as the column widths are recalculated agai
|
|||
{% highlight Dart %}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
EmployeeDataSource(List<Employee> employees) {
|
||||
EmployeeDataSource({required List<Employee> employees}) {
|
||||
dataGridRows = employees
|
||||
.map<DataGridRow>((dataGridRow) => DataGridRow(cells: [
|
||||
DataGridCell<int>(columnName: 'id', value: dataGridRow.id),
|
||||
DataGridCell<String>(columnName: 'name', value: dataGridRow.name),
|
||||
DataGridCell<int>(
|
||||
columnName: 'salary', value: dataGridRow.salary),
|
||||
DataGridCell<String>(
|
||||
columnName: 'designation', value: dataGridRow.designation),
|
||||
DataGridCell<int>(
|
||||
columnName: 'salary', value: dataGridRow.salary),
|
||||
]))
|
||||
.toList();
|
||||
}
|
||||
|
@ -688,16 +630,16 @@ class EmployeeDataSource extends DataGridSource {
|
|||
DataGridRowAdapter? buildRow(DataGridRow row) {
|
||||
return DataGridRowAdapter(
|
||||
cells: row.getCells().map<Widget>((dataGridCell) {
|
||||
return Container(
|
||||
alignment: (dataGridCell.columnName == 'id' ||
|
||||
return Container(
|
||||
alignment: (dataGridCell.columnName == 'id' ||
|
||||
dataGridCell.columnName == 'salary')
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Text(
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Text(
|
||||
dataGridCell.value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
));
|
||||
));
|
||||
}).toList());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,57 +25,47 @@ import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
columns: <GridColumn>[
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
|
|
@ -261,11 +261,10 @@ final EmployeeDataSource _employeeDataSource = EmployeeDataSource();
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Syncfusion Flutter DataGrid'),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
appBar: AppBar(
|
||||
title: const Text('Syncfusion Flutter DataGrid'),
|
||||
),
|
||||
body: Column(children: [
|
||||
TextButton(
|
||||
child: const Text('Update cell value'),
|
||||
onPressed: () {
|
||||
|
@ -282,58 +281,45 @@ Widget build(BuildContext context) {
|
|||
_employeeDataSource.updateDataGridSource(
|
||||
rowColumnIndex: RowColumnIndex(0, 3));
|
||||
}),
|
||||
SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
])
|
||||
]));
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
|
|
@ -30,59 +30,49 @@ The following example show how to enable editing in datagrid and committing the
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
columns: [
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]));
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
@ -144,24 +134,22 @@ class EmployeeDataSource extends DataGridSource {
|
|||
// The new cell value must be reset.
|
||||
// To avoid committing the [DataGridCell] value that was previously edited
|
||||
// into the current non-modified [DataGridCell].
|
||||
newCellValue = null;
|
||||
newCellValue = null;
|
||||
|
||||
final bool isNumericType =
|
||||
column.columnName == 'id' || column.columnName == 'salary';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
alignment:
|
||||
isNumericType ? Alignment.centerRight : Alignment.centerLeft,
|
||||
alignment: isNumericType ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: TextField(
|
||||
autofocus: true,
|
||||
controller: editingController..text = displayText,
|
||||
textAlign: isNumericType ? TextAlign.right : TextAlign.left,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0),
|
||||
contentPadding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0),
|
||||
),
|
||||
keyboardType:
|
||||
isNumericType ? TextInputType.number : TextInputType.text,
|
||||
keyboardType: isNumericType ? TextInputType.number : TextInputType.text,
|
||||
onChanged: (String value) {
|
||||
if (value.isNotEmpty) {
|
||||
if (isNumericType) {
|
||||
|
@ -200,60 +188,50 @@ To disable the editing for a particular column, set the [GridColumn.allowEditing
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
columns: [
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
allowEditing: false,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
allowEditing: false,
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -269,60 +247,50 @@ By default, cell will be moved to edit mode when you double tap the cells. You c
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
editingGestureType: EditingGestureType.tap,
|
||||
columns: [
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
editingGestureType: EditingGestureType.tap,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -343,12 +311,12 @@ The [DataGridSource.onCellBeginEdit](https://pub.dev/documentation/syncfusion_fl
|
|||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
@override
|
||||
bool onCellBeginEdit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
|
||||
GridColumn column) {
|
||||
if(column.columnName == 'id'){
|
||||
bool onCellBeginEdit(
|
||||
DataGridRow dataGridRow, RowColumnIndex rowColumnIndex, GridColumn column) {
|
||||
if (column.columnName == 'id') {
|
||||
// Return false, to restrict entering into the editing.
|
||||
return false;
|
||||
}else{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +337,7 @@ The [DataGridSource.canSubmitCell](https://pub.dev/documentation/syncfusion_flut
|
|||
{% highlight dart %}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
@override
|
||||
@override
|
||||
bool canSubmitCell(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
|
||||
GridColumn column) {
|
||||
if (column.columnName == 'id' && newCellValue == null) {
|
||||
|
@ -396,7 +364,6 @@ The [DataGridSource.onCellSubmit](https://pub.dev/documentation/syncfusion_flutt
|
|||
{% highlight dart %}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
|
||||
@override
|
||||
void onCellSubmit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
|
||||
GridColumn column) {
|
||||
|
@ -448,7 +415,8 @@ The [DataGridSource.onCellCancelEdit](https://pub.dev/documentation/syncfusion_f
|
|||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
@override
|
||||
void onCellCancelEdit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex, GridColumn column) {
|
||||
void onCellCancelEdit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
|
||||
GridColumn column) {
|
||||
// handle the cancel editing code here
|
||||
}
|
||||
}
|
||||
|
@ -470,72 +438,58 @@ final DataGridController _dataGridController = DataGridController();
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
TextButton(
|
||||
child: Text("Begin Edit"),
|
||||
onPressed: () {
|
||||
_dataGridController.beginEdit(RowColumnIndex(2, 3));
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
body: Column(children: [
|
||||
TextButton(
|
||||
child: Text("Begin Edit"),
|
||||
onPressed: () {
|
||||
_dataGridController.beginEdit(RowColumnIndex(2, 3));
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
controller: _dataGridController,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
)))
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -548,77 +502,63 @@ The [SfDataGrid.endEdit](https://pub.dev/documentation/syncfusion_flutter_datagr
|
|||
{% tabs %}
|
||||
{% highlight dart %}
|
||||
|
||||
final DataGridController _dataGridControlle r = DataGridController();
|
||||
final DataGridController _dataGridController = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
TextButton(
|
||||
child: Text("End Edit"),
|
||||
onPressed: () {
|
||||
_dataGridController.endEdit();
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
body: Column(children: [
|
||||
TextButton(
|
||||
child: Text("End Edit"),
|
||||
onPressed: () {
|
||||
_dataGridController.endEdit();
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
allowEditing: true,
|
||||
selectionMode: SelectionMode.single,
|
||||
navigationMode: GridNavigationMode.cell,
|
||||
controller: _dataGridController,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
)))
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -636,11 +576,11 @@ class EmployeeDataSource extends DataGridSource {
|
|||
bool onCellBeginEdit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
|
||||
GridColumn column) {
|
||||
|
||||
// Editing prevented for the cell at RowColumnIndex(2,2).
|
||||
// Editing prevented for the cell at RowColumnIndex(2,2).
|
||||
if (rowColumnIndex.equals(RowColumnIndex(2, 2))) {
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,53 +12,50 @@ documentation: ug
|
|||
Creates an additional row that can be displayed below to the last row. Widgets can be displayed to the additional row by setting the [SfDataGrid.footer](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/footer.html) property.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
footer: Container(
|
||||
color: Colors.grey[400],
|
||||
child: Center(
|
||||
child: Text(
|
||||
'FOOTER VIEW',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
source: _employeeDataSource,
|
||||
footer: Container(
|
||||
color: Colors.grey[400],
|
||||
child: Center(
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
);
|
||||
'FOOTER VIEW',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
))),
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
]);
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -71,54 +68,51 @@ Widget build(BuildContext context) {
|
|||
An additional row height can be personalized by using the [SfDataGrid.footerHeight](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/footerHeight.html) property. The default value of the additional row is 49.0.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
footerHeight: 60.0,
|
||||
footer: Container(
|
||||
color: Colors.grey[400],
|
||||
child: Center(
|
||||
child: Text(
|
||||
'FOOTER VIEW',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
source: _employeeDataSource,
|
||||
footerHeight: 60.0,
|
||||
footer: Container(
|
||||
color: Colors.grey[400],
|
||||
child: Center(
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
);
|
||||
'FOOTER VIEW',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
))),
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
]);
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -131,53 +125,51 @@ Widget build(BuildContext context) {
|
|||
By default, the additional row will be displayed below the last row. To show the additional row always on the view bottom, simply set the [SfDataGrid.footerFrozenRowsCount](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/footerFrozenRowsCount.html) property to 1.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
footerFrozenRowsCount: 1,
|
||||
footer: Container(
|
||||
child: Center(
|
||||
child: Text(
|
||||
'FOOTER VIEW',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
source: _employeeDataSource,
|
||||
footerFrozenRowsCount: 1,
|
||||
footer: Container(
|
||||
color: Colors.grey[400],
|
||||
child: Center(
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
);
|
||||
'FOOTER VIEW',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
))),
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
]);
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -61,7 +61,6 @@ Add the SfDataGrid widget as a child of any widget. [SfDataGrid](https://pub.dev
|
|||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -241,8 +240,6 @@ Widget build(BuildContext context) {
|
|||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -297,9 +294,7 @@ Widget build(BuildContext context) {
|
|||
`SfDataGrid` allows you to select one or more rows. The [selectionMode](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/selectionMode.html) property can be set to specify whether a user can select single row, or multiple rows.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -360,8 +355,6 @@ The information about the rows that are selected can be retrieved using [selecte
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
|
|
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 450 KiB После Ширина: | Высота: | Размер: 318 KiB |
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 394 KiB После Ширина: | Высота: | Размер: 309 KiB |
|
@ -24,8 +24,6 @@ The following example demonstrates infinite scrolling by showing the circular pr
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
EmployeeDataSource _employeeDataSource = EmployeeDataSource();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
|
@ -210,8 +208,6 @@ The following example demonstrates how to show the button when vertical scrollin
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
EmployeeDataSource _employeeDataSource = EmployeeDataSource();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
|
|
|
@ -35,93 +35,76 @@ final int rowsPerPage = 15;
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: [
|
||||
const Locale('zh'),
|
||||
const Locale('ar'),
|
||||
const Locale('ja'),
|
||||
],
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('DataPager'),
|
||||
),
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Column(
|
||||
children: [
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: [
|
||||
const Locale('zh'),
|
||||
const Locale('ar'),
|
||||
const Locale('ja'),
|
||||
],
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('DataPager'),
|
||||
),
|
||||
body: LayoutBuilder(builder: (context, constraints) {
|
||||
return Column(children: [
|
||||
SizedBox(
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
])),
|
||||
Container(
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
delegate: _employeeDataSource,
|
||||
pageCount: employees.length / rowsPerPage,
|
||||
visibleItemsCount: 5,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
delegate: _employeeDataSource,
|
||||
pageCount: _employees.length / rowsPerPage,
|
||||
visibleItemsCount: 5,
|
||||
direction: Axis.horizontal,
|
||||
))
|
||||
]);
|
||||
})));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -158,94 +141,77 @@ final int rowsPerPage = 15;
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
SfGlobalLocalizations.delegate
|
||||
],
|
||||
supportedLocales: [
|
||||
const Locale('zh'),
|
||||
const Locale('ar'),
|
||||
const Locale('ja'),
|
||||
],
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('DataPager'),
|
||||
),
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Column(
|
||||
children: [
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
SfGlobalLocalizations.delegate
|
||||
],
|
||||
supportedLocales: [
|
||||
const Locale('zh'),
|
||||
const Locale('ar'),
|
||||
const Locale('ja'),
|
||||
],
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('DataPager'),
|
||||
),
|
||||
body: LayoutBuilder(builder: (context, constraints) {
|
||||
return Column(children: [
|
||||
SizedBox(
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
])),
|
||||
Container(
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
delegate: _employeeDataSource,
|
||||
pageCount: employees.length / rowsPerPage,
|
||||
visibleItemsCount: 5,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
delegate: _employeeDataSource,
|
||||
pageCount: _employees.length / rowsPerPage,
|
||||
visibleItemsCount: 5,
|
||||
direction: Axis.horizontal,
|
||||
))
|
||||
]);
|
||||
})));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
|
|
@ -25,6 +25,8 @@ The following code example illustrates using `SfDataPager` with the datagrid con
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
final int rowsPerPage = 15;
|
||||
|
||||
final double dataPagerHeight = 60.0;
|
||||
|
@ -38,261 +40,68 @@ final OrderInfoDataSource _orderInfoDataSource = OrderInfoDataSource();
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - dataPagerHeight,
|
||||
return Column(children: [
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - _dataPagerHeight,
|
||||
width: constraint.maxWidth,
|
||||
child: SfDataGrid(
|
||||
source: _orderInfoDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'orderID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'customerID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Customer Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'orderDate',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order Date',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'freight',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Freight',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: dataPagerHeight,
|
||||
child: _buildDataGrid(constraint)),
|
||||
Container(
|
||||
height: _dataPagerHeight,
|
||||
child: SfDataPager(
|
||||
delegate: _orderInfoDataSource,
|
||||
pageCount: orders.length / rowsPerPage,
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
))
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
class OrderInfoDataSource extends DataGridSource{
|
||||
OrderInfoDataSource() {
|
||||
paginatedOrders = orders.getRange(0, 19).toList(growable: false);
|
||||
buildPaginateDataGridRows();
|
||||
}
|
||||
|
||||
List<DataGridRow> dataGridRows = [];
|
||||
|
||||
@override
|
||||
List<DataGridRow> get rows => dataGridRows;
|
||||
|
||||
@override
|
||||
DataGridRowAdapter? buildRow(DataGridRow row) {
|
||||
return DataGridRowAdapter(
|
||||
cells: row.getCells().map<Widget>((dataGridCell) {
|
||||
if (dataGridCell.columnName == 'orderID') {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
dataGridCell.value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
} else if (dataGridCell.columnName == 'customerID') {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
dataGridCell.value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
));
|
||||
} else if (dataGridCell.columnName == 'orderDate') {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
DateFormat.yMd().format(dataGridCell.value).toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
));
|
||||
} else {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
NumberFormat.currency(locale: 'en_US', symbol: '\$')
|
||||
.format(dataGridCell.value)
|
||||
.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
));
|
||||
}
|
||||
}).toList());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> handlePageChange(int oldPageIndex, int newPageIndex) async {
|
||||
int startIndex = newPageIndex * rowsPerPage;
|
||||
int endIndex = startIndex + rowsPerPage;
|
||||
if(startIndex < orders.length && endIndex <= orders.length){
|
||||
paginatedOrders = orders.getRange(startIndex, endIndex).toList(growable: false);
|
||||
buildPaginatedDataGridRows();
|
||||
notifyListeners();
|
||||
}else{
|
||||
paginatedOrders = [];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void buildPaginatedDataGridRows() {
|
||||
dataGridRows = paginatedOrders.map<DataGridRow>((dataGridRow) {
|
||||
return DataGridRow(cells: [
|
||||
DataGridCell(columnName: 'orderID', value: dataGridRow.orderID),
|
||||
DataGridCell(columnName: 'customerID', value: dataGridRow.customerID),
|
||||
DataGridCell(columnName: 'orderDate', value: dataGridRow.orderData),
|
||||
DataGridCell(columnName: 'freight', value: dataGridRow.freight),
|
||||
]);
|
||||
}).toList(growable: false);
|
||||
}
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
![flutter datapager with datagrid](images/paging/flutter-datapager.png)
|
||||
|
||||
## Callbacks
|
||||
|
||||
The SfDataPager provides [onPageNavigationStart](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataPager/onPageNavigationStart.html) and [onPageNavigationEnd](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataPager/onPageNavigationEnd.html) callbacks to listen the page navigation in widget level.
|
||||
|
||||
Typically, these callbacks are used to show and hide loading indicator.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
final OrderInfoDataSource _orderInfoDataSource = OrderInfoDataSource();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Row(children: [
|
||||
Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: buildDataGrid(constraints)),
|
||||
Container(
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
pageCount: orders.length / rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
onPageNavigationStart: (int pageIndex) {
|
||||
//You can do your customization
|
||||
},
|
||||
delegate: _orderInfoDataSource,
|
||||
onPageNavigationEnd: (int pageIndex) {
|
||||
//You can do your customization
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
]);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildDataGrid(BoxConstraints constraint) {
|
||||
Widget _buildDataGrid(BoxConstraints constraint) {
|
||||
return SfDataGrid(
|
||||
source: _orderInfoDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'orderID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'orderID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'customerID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Customer Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Customer Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'orderDate',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order Date',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
columnName: 'orderDate',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order Date',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'freight',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Freight',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
columnName: 'freight',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Freight',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)))
|
||||
]);
|
||||
}
|
||||
|
||||
class OrderInfoDataSource extends DataGridSource{
|
||||
class OrderInfoDataSource extends DataGridSource {
|
||||
OrderInfoDataSource() {
|
||||
paginatedOrders = orders.getRange(0, 19).toList(growable: false);
|
||||
_paginatedOrders = _orders.getRange(0, 19).toList(growable: false);
|
||||
buildPaginatedDataGridRows();
|
||||
}
|
||||
|
||||
|
@ -343,28 +152,29 @@ class OrderInfoDataSource extends DataGridSource{
|
|||
}
|
||||
}).toList());
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future<bool> handlePageChange(int oldPageIndex, int newPageIndex) async {
|
||||
int startIndex = newPageIndex * rowsPerPage;
|
||||
int endIndex = startIndex + rowsPerPage;
|
||||
if(startIndex < orders.length && endIndex <= orders.length){
|
||||
paginatedOrders = orders.getRange(startIndex, endIndex).toList(growable: false);
|
||||
int startIndex = newPageIndex * _rowsPerPage;
|
||||
int endIndex = startIndex + _rowsPerPage;
|
||||
if (startIndex < _orders.length && endIndex <= _orders.length) {
|
||||
_paginatedOrders =
|
||||
_orders.getRange(startIndex, endIndex).toList(growable: false);
|
||||
buildPaginatedDataGridRows();
|
||||
notifyListeners();
|
||||
}else{
|
||||
paginatedOrders = [];
|
||||
} else {
|
||||
_paginatedOrders = [];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void buildPaginatedDataGridRows() {
|
||||
dataGridRows = paginatedOrders.map<DataGridRow>((dataGridRow) {
|
||||
dataGridRows = _paginatedOrders.map<DataGridRow>((dataGridRow) {
|
||||
return DataGridRow(cells: [
|
||||
DataGridCell(columnName: 'orderID', value: dataGridRow.orderID),
|
||||
DataGridCell(columnName: 'customerID', value: dataGridRow.customerID),
|
||||
DataGridCell(columnName: 'orderDate', value: dataGridRow.orderData),
|
||||
DataGridCell(columnName: 'orderDate', value: dataGridRow.orderDate),
|
||||
DataGridCell(columnName: 'freight', value: dataGridRow.freight),
|
||||
]);
|
||||
}).toList(growable: false);
|
||||
|
@ -374,6 +184,47 @@ class OrderInfoDataSource extends DataGridSource{
|
|||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
![flutter datapager with datagrid](images/paging/flutter-datapager.png)
|
||||
|
||||
## Callbacks
|
||||
|
||||
The SfDataPager provides [onPageNavigationStart](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataPager/onPageNavigationStart.html) and [onPageNavigationEnd](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataPager/onPageNavigationEnd.html) callbacks to listen the page navigation in widget level.
|
||||
|
||||
Typically, these callbacks are used to show and hide loading indicator.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(body: LayoutBuilder(builder: (context, constraints) {
|
||||
return Row(children: [
|
||||
Column(children: [
|
||||
SizedBox(
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: _buildDataGrid(constraints)),
|
||||
Container(
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
onPageNavigationStart: (int pageIndex) {
|
||||
//You can do your customization
|
||||
},
|
||||
delegate: _orderInfoDataSource,
|
||||
onPageNavigationEnd: (int pageIndex) {
|
||||
//You can do your customization
|
||||
}))
|
||||
])
|
||||
]);
|
||||
}));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
## Asynchronous data loading
|
||||
|
||||
You can load the data asynchronously to the `SfDataPager` by overriding the `handlePageChange` method and await the method while loading the data.
|
||||
|
@ -385,119 +236,56 @@ In the below example, we have set await for 2000ms and displayed the loading ind
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
final OrderInfoDataSource _orderInfoDataSource = OrderInfoDataSource();
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
bool showLoadingIndicator = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Row(children: [
|
||||
Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: buildStack(constraints)),
|
||||
Container(
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
pageCount:
|
||||
orders.length / rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
onPageNavigationStart: (int pageIndex) {
|
||||
setState(() {
|
||||
showLoadingIndicator = true;
|
||||
});
|
||||
},
|
||||
delegate: _orderInfoDataSource,
|
||||
onPageNavigationEnd: (int pageIndex) {
|
||||
setState(() {
|
||||
showLoadingIndicator = false;
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
]);
|
||||
},
|
||||
),
|
||||
);
|
||||
return Scaffold(body: LayoutBuilder(builder: (context, constraints) {
|
||||
return Row(children: [
|
||||
Column(children: [
|
||||
SizedBox(
|
||||
height: constraints.maxHeight - 60,
|
||||
width: constraints.maxWidth,
|
||||
child: _buildStack(constraints)),
|
||||
Container(
|
||||
height: 60,
|
||||
width: constraints.maxWidth,
|
||||
child: SfDataPager(
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
onPageNavigationStart: (int pageIndex) {
|
||||
setState(() {
|
||||
showLoadingIndicator = true;
|
||||
});
|
||||
},
|
||||
delegate: _orderInfoDataSource,
|
||||
onPageNavigationEnd: (int pageIndex) {
|
||||
setState(() {
|
||||
showLoadingIndicator = false;
|
||||
});
|
||||
}))
|
||||
])
|
||||
]);
|
||||
}));
|
||||
}
|
||||
|
||||
Widget buildDataGrid(BoxConstraints constraint) {
|
||||
return SfDataGrid(
|
||||
source: _orderInfoDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'orderID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'customerID',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Customer Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'orderDate',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Order Date',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridColumn(
|
||||
columnName: 'freight',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Freight',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildStack(BoxConstraints constraints) {
|
||||
Widget _buildStack(BoxConstraints constraints) {
|
||||
List<Widget> _getChildren() {
|
||||
final List<Widget> stackChildren = [];
|
||||
stackChildren.add(buildDataGrid(constraints));
|
||||
stackChildren.add(_buildDataGrid(constraints));
|
||||
|
||||
if (showLoadingIndicator) {
|
||||
stackChildren.add(Container(
|
||||
color: Colors.black12,
|
||||
width: constraints.maxWidth,
|
||||
height: constraints.maxHeight,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
),
|
||||
),
|
||||
));
|
||||
color: Colors.black12,
|
||||
width: constraints.maxWidth,
|
||||
height: constraints.maxHeight,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
))));
|
||||
}
|
||||
|
||||
return stackChildren;
|
||||
|
@ -508,10 +296,10 @@ Widget buildStack(BoxConstraints constraints) {
|
|||
);
|
||||
}
|
||||
|
||||
class OrderInfoDataSource extends DataGridSource{
|
||||
class OrderInfoDataSource extends DataGridSource {
|
||||
OrderInfoDataSource() {
|
||||
paginatedOrders = orders.getRange(0, 19).toList(growable: false);
|
||||
buildPaginateDataGridRows();
|
||||
_paginatedOrders = _orders.getRange(0, 19).toList(growable: false);
|
||||
buildPaginatedDataGridRows();
|
||||
}
|
||||
|
||||
List<DataGridRow> dataGridRows = [];
|
||||
|
@ -561,29 +349,30 @@ class OrderInfoDataSource extends DataGridSource{
|
|||
}
|
||||
}).toList());
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future<bool> handlePageChange(int oldPageIndex, int newPageIndex) async {
|
||||
int startIndex = newPageIndex * rowsPerPage;
|
||||
int endIndex = startIndex + rowsPerPage;
|
||||
if(startIndex < orders.length && endIndex <= orders.length){
|
||||
await Future.delayed(Duration(milliseconds: 2000));
|
||||
paginatedOrders = orders.getRange(startIndex, endIndex).toList(growable: false);
|
||||
int startIndex = newPageIndex * _rowsPerPage;
|
||||
int endIndex = startIndex + _rowsPerPage;
|
||||
if (startIndex < _orders.length && endIndex <= _orders.length) {
|
||||
await Future.delayed(Duration(milliseconds: 2000));
|
||||
_paginatedOrders =
|
||||
_orders.getRange(startIndex, endIndex).toList(growable: false);
|
||||
buildPaginatedDataGridRows();
|
||||
notifyListeners();
|
||||
}else{
|
||||
paginatedOrders = [];
|
||||
} else {
|
||||
_paginatedOrders = [];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void buildPaginatedDataGridRows() {
|
||||
dataGridRows = paginatedOrders.map<DataGridRow>((dataGridRow) {
|
||||
dataGridRows = _paginatedOrders.map<DataGridRow>((dataGridRow) {
|
||||
return DataGridRow(cells: [
|
||||
DataGridCell(columnName: 'orderID', value: dataGridRow.orderID),
|
||||
DataGridCell(columnName: 'customerID', value: dataGridRow.customerID),
|
||||
DataGridCell(columnName: 'orderDate', value: dataGridRow.orderData),
|
||||
DataGridCell(columnName: 'orderDate', value: dataGridRow.orderDate),
|
||||
DataGridCell(columnName: 'freight', value: dataGridRow.freight),
|
||||
]);
|
||||
}).toList(growable: false);
|
||||
|
@ -612,40 +401,37 @@ The following code example shows how to navigate the previous page programmatica
|
|||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(
|
||||
children: [
|
||||
MaterialButton(
|
||||
onPressed: () {
|
||||
controller.previousPage();
|
||||
},
|
||||
child: Text('Move Previous page'),
|
||||
),
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - 120,
|
||||
width: constraint.maxWidth,
|
||||
child: _buildDataGrid()),
|
||||
Container(
|
||||
height: 60,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: SfDataPager(
|
||||
delegate: orderInfoDataSource,
|
||||
initialPageIndex: index,
|
||||
controller: controller,
|
||||
pageCount: orderInfoDataSource.orders.length /
|
||||
orderInfoDataSource.rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
)),
|
||||
)
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
DataPagerController _controller = DataPagerController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(body: LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(children: [
|
||||
MaterialButton(
|
||||
onPressed: () {
|
||||
_controller.previousPage();
|
||||
},
|
||||
child: Text('Move Previous page'),
|
||||
),
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - 120,
|
||||
width: constraint.maxWidth,
|
||||
child: _buildDataGrid(constraint)),
|
||||
Container(
|
||||
height: 60,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: SfDataPager(
|
||||
delegate: _orderInfoDataSource,
|
||||
initialPageIndex: 2,
|
||||
controller: _controller,
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
)))
|
||||
]);
|
||||
}));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -713,7 +499,7 @@ Widget build(BuildContext context) {
|
|||
),
|
||||
child: SfDataPager(
|
||||
delegate: _orderInfoDataSource,
|
||||
pageCount: orders.length / rowsPerPage,
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
),
|
||||
|
@ -732,33 +518,32 @@ You can change the number of visible items i.e. page buttons in view by using th
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Flutter DataGrid Sample'),
|
||||
),
|
||||
body: LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - dataPagerHeight,
|
||||
width: constraint.maxWidth,
|
||||
child: _buildDataGrid()),
|
||||
Container(
|
||||
height: dataPagerHeight,
|
||||
child: SfDataPager(
|
||||
visibleItemsCount: 1,
|
||||
delegate: orderInfoDataSource,
|
||||
pageCount: orderInfoDataSource.orders.length /
|
||||
orderInfoDataSource.rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}));
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Flutter DataGrid Sample'),
|
||||
),
|
||||
body: LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - _dataPagerHeight,
|
||||
width: constraint.maxWidth,
|
||||
child: _buildDataGrid(constraint)),
|
||||
Container(
|
||||
height: _dataPagerHeight,
|
||||
child: SfDataPager(
|
||||
visibleItemsCount: 1,
|
||||
delegate: _orderInfoDataSource,
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -769,22 +554,22 @@ You can load any widget to page button by using [SfDataPager.pageItemBuilder](ht
|
|||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Flutter DataGrid Sample'),
|
||||
),
|
||||
body: LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - dataPagerHeight,
|
||||
width: constraint.maxWidth,
|
||||
child: _buildDataGrid()),
|
||||
Container(
|
||||
height: dataPagerHeight,
|
||||
child: SfDataPagerTheme(
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Flutter DataGrid Sample'),
|
||||
),
|
||||
body: LayoutBuilder(builder: (context, constraint) {
|
||||
return Column(children: [
|
||||
SizedBox(
|
||||
height: constraint.maxHeight - _dataPagerHeight,
|
||||
width: constraint.maxWidth,
|
||||
child: _buildDataGrid(constraint)),
|
||||
Container(
|
||||
height: _dataPagerHeight,
|
||||
child: SfDataPagerTheme(
|
||||
data: SfDataPagerThemeData(
|
||||
itemBorderColor: Colors.blue,
|
||||
itemBorderWidth: 1,
|
||||
|
@ -800,17 +585,13 @@ You can load any widget to page button by using [SfDataPager.pageItemBuilder](ht
|
|||
fontSize: 10, fontWeight: FontWeight.w700),
|
||||
));
|
||||
},
|
||||
delegate: orderInfoDataSource,
|
||||
pageCount: orderInfoDataSource.orders.length /
|
||||
orderInfoDataSource.rowsPerPage,
|
||||
delegate: _orderInfoDataSource,
|
||||
pageCount: _orders.length / _rowsPerPage,
|
||||
direction: Axis.horizontal,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}));
|
||||
}
|
||||
)))
|
||||
]);
|
||||
}));
|
||||
}
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
|
|
|
@ -171,8 +171,6 @@ You can also change the stroke width and displacement of refresh indicator by us
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
EmployeeDataSource _employeeDataSource = EmployeeDataSource();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Theme(
|
||||
|
@ -240,7 +238,6 @@ If you want to refresh data without showing a refresh indicator, you can pass `f
|
|||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
final GlobalKey<SfDataGridState> key = GlobalKey<SfDataGridState>();
|
||||
EmployeeDataSource _employeeDataSource = EmployeeDataSource();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -7,7 +7,7 @@ control: SfDataGrid
|
|||
documentation: ug
|
||||
---
|
||||
|
||||
## Right to Left (RTL) in Flutter DataGrid (SfDataGrid)
|
||||
# Right to Left (RTL) in Flutter DataGrid (SfDataGrid)
|
||||
|
||||
SfDataGrid supports right-to-left rendering. The columns will be rendered based on LTR and RTL direction.
|
||||
|
||||
|
@ -27,43 +27,41 @@ import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
),
|
||||
);
|
||||
textDirection: TextDirection.rtl,
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -73,6 +71,18 @@ Widget build(BuildContext context) {
|
|||
|
||||
To change the datagrid rendering direction from right to left, change the [locale](https://api.flutter.dev/flutter/material/MaterialApp/locale.html) to any of the RTL languages such as Arabic, Persian, Hebrew, Pashto, and Urdu.
|
||||
|
||||
To use `flutter_localizations`, add the package as dependency to `pubspec.yaml` file.
|
||||
|
||||
{% highlight dart %}
|
||||
|
||||
dependencies:
|
||||
flutter_localizations:
|
||||
sdk: flutter
|
||||
|
||||
{% endhighlight %}
|
||||
|
||||
Then, import the `flutter_localizations` library, specify [localizationsDelegates](https://api.flutter.dev/flutter/widgets/LocalizationsDelegate-class.html) and `supportedLocales` for `MaterialApp`.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
|
@ -82,52 +92,50 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: <Locale>[
|
||||
Locale('en'),
|
||||
Locale('ar'),
|
||||
// ... other locales the app supports
|
||||
],
|
||||
locale: Locale('ar'),
|
||||
home: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
localizationsDelegates: [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
),
|
||||
);
|
||||
supportedLocales: <Locale>[
|
||||
Locale('en'),
|
||||
Locale('ar'),
|
||||
// ... other locales the app supports
|
||||
],
|
||||
locale: Locale('ar'),
|
||||
home: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -20,53 +20,51 @@ N> The default value of `isScrollbarAlwaysShown` is false.
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
isScrollbarAlwaysShown: true,
|
||||
columns: [
|
||||
GridColumn(
|
||||
source: _employeeDataSource,
|
||||
isScrollbarAlwaysShown: true,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -82,54 +80,52 @@ The following example shows how to disable the horizontal and vertical scrolling
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
horizontalScrollPhysics: NeverScrollableScrollPhysics(),
|
||||
verticalScrollPhysics: NeverScrollableScrollPhysics(),
|
||||
columns: [
|
||||
GridColumn(
|
||||
source: _employeeDataSource,
|
||||
horizontalScrollPhysics: NeverScrollableScrollPhysics(),
|
||||
verticalScrollPhysics: NeverScrollableScrollPhysics(),
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -149,60 +145,62 @@ N> The default value of `canAnimate` is `false`.
|
|||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
FlatButton(
|
||||
child: Text('ScrollToCell'),
|
||||
onPressed: () {
|
||||
_controller.scrollToCell(15, 2);
|
||||
},
|
||||
),
|
||||
Expanded( child:SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: [
|
||||
GridColumn(
|
||||
TextButton(
|
||||
child: Text('ScrollToCell'),
|
||||
onPressed: () {
|
||||
_controller.scrollToCell(10, 1);
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
defaultColumnWidth: 150,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
controller: _controller,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
controller: _controller,
|
||||
)),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -220,60 +218,62 @@ N> The default value of `canAnimate` is `false`.
|
|||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
FlatButton(
|
||||
child: Text('ScrollToRow'),
|
||||
onPressed: () {
|
||||
_controller.scrollToRow(15);
|
||||
},
|
||||
),
|
||||
Expanded( child:SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: [
|
||||
GridColumn(
|
||||
TextButton(
|
||||
child: Text('ScrollToRow'),
|
||||
onPressed: () {
|
||||
_controller.scrollToRow(10);
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
defaultColumnWidth: 150,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
controller: _controller,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
controller: _controller,
|
||||
)),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -289,60 +289,62 @@ N> The default value of `canAnimate` is `false`.
|
|||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
FlatButton(
|
||||
child: Text('ScrollToColumn'),
|
||||
onPressed: () {
|
||||
_controller.scrollToColumn(2);
|
||||
},
|
||||
),
|
||||
Expanded( child:SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: [
|
||||
GridColumn(
|
||||
TextButton(
|
||||
child: Text('ScrollToColumn'),
|
||||
onPressed: () {
|
||||
_controller.scrollToColumn(1);
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
defaultColumnWidth: 150,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
controller: _controller,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
controller: _controller,
|
||||
)),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -365,63 +367,65 @@ N> The default value of `DataGridScrollPosition` is `Start`.
|
|||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
FlatButton(
|
||||
child: Text('ScrollToCell'),
|
||||
onPressed: () {
|
||||
_controller.scrollToCell(15, 2,
|
||||
canAnimate: true,
|
||||
rowPosition: DataGridScrollPosition.start,
|
||||
columnPosition: DataGridScrollPosition.start);
|
||||
},
|
||||
),
|
||||
Expanded( child:SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: [
|
||||
GridColumn(
|
||||
TextButton(
|
||||
child: Text('ScrollToCell'),
|
||||
onPressed: () {
|
||||
_controller.scrollToCell(10, 1,
|
||||
canAnimate: true,
|
||||
rowPosition: DataGridScrollPosition.start,
|
||||
columnPosition: DataGridScrollPosition.start);
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
defaultColumnWidth: 150,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
controller: _controller,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
controller: _controller,
|
||||
)),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -437,60 +441,62 @@ N> The default value of `canAnimate` is `false`.
|
|||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
FlatButton(
|
||||
child: Text('ScrollToVerticalOffset'),
|
||||
onPressed: () {
|
||||
_controller.scrollToVerticalOffset(500);
|
||||
},
|
||||
),
|
||||
Expanded( child:SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: [
|
||||
GridColumn(
|
||||
TextButton(
|
||||
child: Text('ScrollToVerticalOffset'),
|
||||
onPressed: () {
|
||||
_controller.scrollToVerticalOffset(500);
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
defaultColumnWidth: 150,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
controller: _controller,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
controller: _controller,
|
||||
)),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -506,60 +512,62 @@ N> The default value of `canAnimate` is `false`.
|
|||
|
||||
final DataGridController _controller = DataGridController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
FlatButton(
|
||||
child: Text('ScrollToHorizontalOffset'),
|
||||
onPressed: () {
|
||||
_controller.scrollToHorizontalOffset(400);
|
||||
},
|
||||
),
|
||||
Expanded( child:SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: [
|
||||
GridColumn(
|
||||
TextButton(
|
||||
child: Text('ScrollToHorizontalOffset'),
|
||||
onPressed: () {
|
||||
_controller.scrollToHorizontalOffset(400);
|
||||
}),
|
||||
Expanded(
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
defaultColumnWidth: 150,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
controller: _controller,
|
||||
columns: [
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
controller: _controller,
|
||||
)),
|
||||
);
|
||||
}
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
]))
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -575,43 +583,45 @@ The following example demonstrates how to load more rows when vertical scrolling
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
late _EmployeeDataSource employeeDataSource;
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
late ScrollController verticalScrollController;
|
||||
|
||||
void verticalListner() {
|
||||
if (verticalScrollController.position.pixels >=
|
||||
verticalScrollController.position.maxScrollExtent * (70 / 100)) {
|
||||
employeeDataSource.loadMoreRows();
|
||||
}
|
||||
void verticalListner() {
|
||||
if (_verticalScrollController.position.pixels >=
|
||||
_verticalScrollController.position.maxScrollExtent * (70 / 100)) {
|
||||
_employeeDataSource.loadMoreRows();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
employeeDataSource = _EmployeeDataSource();
|
||||
verticalScrollController = ScrollController()..addListener(verticalListner);
|
||||
}
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_employeeDataSource = _EmployeeDataSource();
|
||||
_verticalScrollController = ScrollController()..addListener(verticalListner);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Flutter DataGrid Sample'),
|
||||
),
|
||||
body: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
verticalScrollController: verticalScrollController,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: _getColumns()),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Flutter DataGrid Sample'),
|
||||
),
|
||||
body: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
verticalScrollController: _verticalScrollController,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: _getColumns()),
|
||||
);
|
||||
}
|
||||
|
||||
class _EmployeeDataSource extends DataGridSource {
|
||||
_EmployeeDataSource() {
|
||||
loadEmployees(25);
|
||||
}
|
||||
|
||||
List<_Employee> employees = [];
|
||||
List<Employee> employees = [];
|
||||
|
||||
List<DataGridRow> dataGridRows = [];
|
||||
|
||||
|
@ -622,39 +632,28 @@ class _EmployeeDataSource extends DataGridSource {
|
|||
DataGridRowAdapter buildRow(DataGridRow row) {
|
||||
return DataGridRowAdapter(cells: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
row.getCells()[0].value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(row.getCells()[0].value.toString(),
|
||||
overflow: TextOverflow.ellipsis)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
row.getCells()[1].value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(row.getCells()[1].value.toString(),
|
||||
overflow: TextOverflow.ellipsis)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
row.getCells()[2].value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(row.getCells()[2].value.toString(),
|
||||
overflow: TextOverflow.ellipsis)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
NumberFormat.currency(locale: 'en_US', symbol: '\$')
|
||||
.format(row.getCells()[3].value)
|
||||
.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.all(8),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
NumberFormat.currency(locale: 'en_US', symbol: '\$')
|
||||
.format(row.getCells()[3].value)
|
||||
.toString(),
|
||||
overflow: TextOverflow.ellipsis))
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -664,7 +663,7 @@ class _EmployeeDataSource extends DataGridSource {
|
|||
endIndex = startIndex + count;
|
||||
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
var employee = _Employee(
|
||||
var employee = Employee(
|
||||
1000 + i,
|
||||
1700 + i,
|
||||
names[i < names.length ? i : random.nextInt(names.length - 1)],
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -26,6 +26,14 @@ The `SortColumnDetails` object holds the following two properties:
|
|||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
List<Employee> _employees = <Employee>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_employees = getEmployeeData();
|
||||
_employeeDataSource = EmployeeDataSource(employees: _employees);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -98,8 +106,6 @@ To apply sorting for multiple columns in web and desktop, you can click the colu
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -162,8 +168,6 @@ In addition to sort the data in ascending/descending order, the SfDataGrid unsor
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -227,8 +231,6 @@ By default, column gets sorted when column header clicked. This behavior can be
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -289,8 +291,6 @@ The datagrid provides support the sequence numbers to display the sorted columns
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -354,8 +354,6 @@ The data grid disables sorting for an individual column by setting the [GridColu
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -419,8 +417,6 @@ The following code describes how to change sort icon color by using [SfDataGridT
|
|||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
import 'package:syncfusion_flutter_core/theme.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
|
|
@ -19,8 +19,6 @@ Each [StackedHeaderRow](https://pub.dev/documentation/syncfusion_flutter_datagri
|
|||
import 'package:syncfusion_flutter_core/theme.dart';
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late ProductDataSource _productDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
|
@ -96,8 +94,6 @@ You can provide multiple stacked headers to the datagrid by adding the multiple
|
|||
import 'package:syncfusion_flutter_core/theme.dart';
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late ProductDataSource _productDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
|
@ -182,8 +178,6 @@ You can also change the row height of stacked header row and column header row b
|
|||
import 'package:syncfusion_flutter_core/theme.dart';
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late ProductDataSource _productDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
|
|
|
@ -18,53 +18,50 @@ Change the header background color by using [SfDataGridThemeData.headerColor](ht
|
|||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Syncfusion Flutter DataGrid'),
|
||||
),
|
||||
body: SfDataGridTheme(
|
||||
data: SfDataGridThemeData(
|
||||
headerColor: const Color(0xff009889)),
|
||||
child: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
data: SfDataGridThemeData(headerColor: const Color(0xff009889)),
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
])));
|
||||
}
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
|
@ -74,55 +71,54 @@ Change the header background color by using [SfDataGridThemeData.headerColor](ht
|
|||
|
||||
Change the color of the header on hovering by using the [headerHoverColor]( https://pub.dev/documentation/syncfusion_flutter_core/latest/theme/SfDataGridThemeData/headerHoverColor.html) property.
|
||||
|
||||
N> This is applicable for web and desktop platforms.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Syncfusion Flutter DataGrid'),
|
||||
),
|
||||
body: SfDataGridTheme(
|
||||
data: SfDataGridThemeData(headerHoverColor: Colors.yellow),
|
||||
child: SfDataGrid(
|
||||
source: employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
width: 100,
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
data: SfDataGridThemeData(headerHoverColor: Colors.yellow),
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columnWidthMode: ColumnWidthMode.fill,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'ID',
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Name'))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
alignment: Alignment.center,
|
||||
child: Text('Salary'))),
|
||||
])));
|
||||
}
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
|
@ -138,52 +134,47 @@ Color and thickness of the grid lines can be changed by using the [SfDataGridThe
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGridTheme(
|
||||
data: SfDataGridThemeData(
|
||||
gridLineColor: Colors.amber, gridLineStrokeWidth: 3.0),
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
body: SfDataGridTheme(
|
||||
data: SfDataGridThemeData(
|
||||
gridLineColor: Colors.amber, gridLineStrokeWidth: 3.0),
|
||||
child: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
])));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
|
@ -217,41 +208,41 @@ Widget build(BuildContext context) {
|
|||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
headerGridLinesVisibility: GridLinesVisibility.both),
|
||||
|
@ -267,48 +258,48 @@ Widget build(BuildContext context) {
|
|||
|
||||
By default, the row highlighting on hovering support is enabled for the web and desktop platforms. Disable the row highlighting by setting the [SfDataGrid.highlightRowOnHover](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/highlightRowOnHover.html) property to `false`.
|
||||
|
||||
N> This is applicable for web and desktop platforms.
|
||||
|
||||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGrid(
|
||||
highlightRowOnHover: false,
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text('ID'),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Name'),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Designation'),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text('Salary'),
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
highlightRowOnHover: false,
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text('ID'),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Name'),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Designation'),
|
||||
)),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text('Salary'),
|
||||
)),
|
||||
]));
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
@ -320,19 +311,17 @@ Change the row highlighting color and text style by using the [SfDataGridThemeDa
|
|||
{% tabs %}
|
||||
{% highlight Dart %}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SfDataGridTheme(
|
||||
data: SfDataGridThemeData(
|
||||
rowHoverColor: Colors.yellow,
|
||||
rowHoverTextStyle: TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 14,
|
||||
)),
|
||||
child: SfDataGrid(
|
||||
source: _employeeDataSource,
|
||||
columns: <GridColumn>[
|
||||
data: SfDataGridThemeData(
|
||||
rowHoverColor: Colors.yellow,
|
||||
rowHoverTextStyle: TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 14,
|
||||
)),
|
||||
child: SfDataGrid(source: _employeeDataSource, columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
|
@ -361,11 +350,8 @@ Change the row highlighting color and text style by using the [SfDataGridThemeDa
|
|||
alignment: Alignment.centerRight,
|
||||
child: Text('Salary'),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
])));
|
||||
}
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
|
|
|
@ -20,90 +20,137 @@ The Flutter DataTable enables you to load the desired widget behind the swiped r
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
List<Employee> _employees = <Employee>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_employees = getEmployeeData();
|
||||
_employeeDataSource = EmployeeDataSource(employees: _employees);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SfDataGrid(
|
||||
allowSwiping: true,
|
||||
swipeMaxOffset: 100.0,
|
||||
source: employeeDataSource,
|
||||
startSwipeActionsBuilder:
|
||||
(BuildContext context, DataGridRow row, int rowIndex) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_employeeDataSource.dataGridRows.insert(
|
||||
rowIndex,
|
||||
DataGridRow(cells: [
|
||||
DataGridCell(value: 1011, columnName: 'id'),
|
||||
DataGridCell(value: 'Tom Bass', columnName: 'name'),
|
||||
DataGridCell(value: 'Developer', columnName: 'designation'),
|
||||
DataGridCell(value: 20000, columnName: 'salary')
|
||||
]));
|
||||
_employeeDataSource.updateDataSource();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.greenAccent,
|
||||
child: Center(
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
endSwipeActionsBuilder:
|
||||
source: _employeeDataSource,
|
||||
startSwipeActionsBuilder:
|
||||
(BuildContext context, DataGridRow row, int rowIndex) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_employeeDataSource.dataGridRows.removeAt(rowIndex);
|
||||
_employeeDataSource.updateDataSource();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.redAccent,
|
||||
child: Center(
|
||||
child: Icon(Icons.delete),
|
||||
),
|
||||
),
|
||||
);
|
||||
onTap: () {
|
||||
_employeeDataSource.dataGridRows.insert(
|
||||
rowIndex,
|
||||
DataGridRow(cells: [
|
||||
DataGridCell(value: 1011, columnName: 'id'),
|
||||
DataGridCell(value: 'Tom Bass', columnName: 'name'),
|
||||
DataGridCell(value: 'Developer', columnName: 'designation'),
|
||||
DataGridCell(value: 20000, columnName: 'salary')
|
||||
]));
|
||||
_employeeDataSource.updateDataGridSource();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.greenAccent,
|
||||
child: Center(
|
||||
child: Icon(Icons.add),
|
||||
)));
|
||||
},
|
||||
endSwipeActionsBuilder:
|
||||
(BuildContext context, DataGridRow row, int rowIndex) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_employeeDataSource.dataGridRows.removeAt(rowIndex);
|
||||
_employeeDataSource.updateDataGridSource();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.redAccent,
|
||||
child: Center(
|
||||
child: Icon(Icons.delete),
|
||||
)));
|
||||
},
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class EmployeeDataSource extends DataGridSource {
|
||||
EmployeeDataSource({required List<Employee> employees}) {
|
||||
dataGridRows = employees
|
||||
.map<DataGridRow>((dataGridRow) => DataGridRow(cells: [
|
||||
DataGridCell<int>(columnName: 'id', value: dataGridRow.id),
|
||||
DataGridCell<String>(columnName: 'name', value: dataGridRow.name),
|
||||
DataGridCell<String>(
|
||||
columnName: 'designation', value: dataGridRow.designation),
|
||||
DataGridCell<int>(
|
||||
columnName: 'salary', value: dataGridRow.salary),
|
||||
]))
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<DataGridRow> dataGridRows = [];
|
||||
|
||||
@override
|
||||
List<DataGridRow> get rows => dataGridRows;
|
||||
|
||||
@override
|
||||
DataGridRowAdapter? buildRow(DataGridRow row) {
|
||||
return DataGridRowAdapter(
|
||||
cells: row.getCells().map<Widget>((dataGridCell) {
|
||||
return Container(
|
||||
alignment: (dataGridCell.columnName == 'id' ||
|
||||
dataGridCell.columnName == 'salary')
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Text(
|
||||
dataGridCell.value.toString(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
));
|
||||
}).toList());
|
||||
}
|
||||
|
||||
void updateDataGridSource() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
|
@ -134,27 +181,27 @@ You can perform customized swipe functionality using the swiping callbacks. The
|
|||
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
late EmployeeDataSource _employeeDataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(builder: (context, constraints) {
|
||||
return SfDataGrid(
|
||||
allowSwiping: true,
|
||||
swipeMaxOffset: constraints.maxWidth,
|
||||
source: employeeDataSource,
|
||||
startSwipeActionsBuilder:
|
||||
source: _employeeDataSource,
|
||||
startSwipeActionsBuilder:
|
||||
(BuildContext context, DataGridRow row, int rowIndex) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_employeeDataSource.dataGridRows.removeAt(rowIndex);
|
||||
_employeeDataSource.updateDataSource();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.green,
|
||||
padding: EdgeInsets.only(left: 30.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Delete', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
);
|
||||
onTap: () {
|
||||
_employeeDataSource.dataGridRows.removeAt(rowIndex);
|
||||
_employeeDataSource.updateDataGridSource();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.green,
|
||||
padding: EdgeInsets.only(left: 30.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Delete', style: TextStyle(color: Colors.white))));
|
||||
},
|
||||
onSwipeUpdate: (details) {
|
||||
isReachedCenter =
|
||||
|
@ -162,50 +209,49 @@ Widget build(BuildContext context) {
|
|||
return true;
|
||||
},
|
||||
onSwipeEnd: (details) async {
|
||||
if (isReachedCenter &&
|
||||
_employeeDataSource.dataGridRows.isNotEmpty) {
|
||||
_employeeDataSource.dataGridRows.removeAt(details.rowIndex);
|
||||
_employeeDataSource.updateDataSource();
|
||||
if (isReachedCenter && _employeeDataSource.dataGridRows.isNotEmpty) {
|
||||
_employeeDataSource.dataGridRows.removeAt(details.rowIndex);
|
||||
_employeeDataSource.updateDataGridSource();
|
||||
isReachedCenter = false;
|
||||
}
|
||||
},
|
||||
columns: <GridColumn>[
|
||||
GridColumn(
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'id',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'ID',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'name',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Name',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'designation',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Designation',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridColumn(
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
columnName: 'salary',
|
||||
label: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'Salary',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче