@@ -36,77 +36,81 @@ class _MyHomePageState extends State<MyHomePage> {
3636 @override
3737 Widget build (BuildContext context) {
3838 return Scaffold (
39- appBar: AppBar (
40- title: const Text ('Syncfusion Flutter DataGrid' ),
41- ),
42- body: SfDataGrid (
43- allowSorting: true ,
44- source: _employeeDataSource,
45- columns: < GridColumn > [
46- GridTextColumn (
47- columnName: 'id' ,
48- label: Container (
49- padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
50- alignment: Alignment .center,
51- child: Text (
52- 'ID' ,
53- ))),
54- GridTextColumn (
55- columnName: 'name' ,
56- label: Container (
57- padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
58- alignment: Alignment .center,
59- child: Text ('Name' ))),
60- GridTextColumn (
61- columnName: 'designation' ,
62- label: Container (
63- padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
64- alignment: Alignment .center,
65- child: Text (
66- 'Designation' ,
67- overflow: TextOverflow .ellipsis,
68- ))),
69- GridTextColumn (
70- columnName: 'salary' ,
71- label: Container (
72- padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
73- alignment: Alignment .center,
74- child: Text ('Salary' ))),
75- ],
76- ));
39+ appBar: AppBar (
40+ title: const Text ('Syncfusion Flutter DataGrid' ),
41+ ),
42+ body: SfDataGrid (
43+ source: _employeeDataSource,
44+ allowSorting: true ,
45+ columns: < GridColumn > [
46+ GridTextColumn (
47+ columnName: 'id' ,
48+ label: Container (
49+ padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
50+ alignment: Alignment .centerRight,
51+ child: Text (
52+ 'ID' ,
53+ ))),
54+ GridTextColumn (
55+ columnName: 'name' ,
56+ label: Container (
57+ padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
58+ alignment: Alignment .centerLeft,
59+ child: Text (
60+ 'Name' ,
61+ ))),
62+ GridTextColumn (
63+ columnName: 'city' ,
64+ width: 110 ,
65+ label: Container (
66+ padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
67+ alignment: Alignment .centerLeft,
68+ child: Text (
69+ 'City' ,
70+ overflow: TextOverflow .ellipsis,
71+ ))),
72+ GridTextColumn (
73+ columnName: 'Freight' ,
74+ label: Container (
75+ padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
76+ alignment: Alignment .centerRight,
77+ child: Text ('Freight' ))),
78+ ],
79+ ),
80+ );
7781 }
7882
7983 List <Employee > populateData () {
8084 return < Employee > [
81- Employee (10001 , 'James' , 'Project Lead ' , 20000 ),
82- Employee (10002 , 'Kathryn' , 'Manager ' , 30000 ),
83- Employee (10003 , 'Lara' , 'Developer ' , 15000 ),
84- Employee (10004 , 'Michael' , 'Designer ' , 15000 ),
85- Employee (10005 , 'martin ' , 'Developer ' , 15000 ),
86- Employee (10006 , 'newberry ' , 'Developer ' , 15000 ),
87- Employee (10007 , 'Balnc' , 'Developer ' , 15000 ),
88- Employee (10008 , 'Perry' , 'Developer ' , 15000 ),
89- Employee (10009 , 'Gable' , 'Developer ' , 15000 ),
90- Employee (10010 , 'grimes ' , 'Developer ' , 15000 ),
91- Employee (10011 , 'Lara ' , 'Developer ' , 15000 ),
92- Employee (10012 , 'Michael ' , 'Designer ' , 15000 ),
93- Employee (10013 , 'martin ' , 'Developer ' , 15000 ),
94- Employee (10014 , 'newberry ' , 'Developer ' , 15000 ),
95- Employee (10015 , 'Balnc ' , 'Developer ' , 15000 ),
85+ Employee (10001 , 'James' , 'Bruxelles ' , 20000 ),
86+ Employee (10002 , 'Kathryn' , 'Rosario ' , 30000 ),
87+ Employee (10003 , 'Lara' , 'Recife ' , 15000 ),
88+ Employee (10004 , 'Michael' , 'Graz ' , 15000 ),
89+ Employee (10005 , 'Martin ' , 'Montreal ' , 15000 ),
90+ Employee (10006 , 'Newberry ' , 'Tsawassen ' , 15000 ),
91+ Employee (10007 , 'Balnc' , 'Campinas ' , 15000 ),
92+ Employee (10008 , 'Perry' , 'Resende ' , 15000 ),
93+ Employee (10009 , 'Gable' , 'Resende ' , 15000 ),
94+ Employee (10010 , 'Grimes ' , 'Recife ' , 15000 ),
95+ Employee (10011 , 'Newberry ' , 'Tsawassen ' , 15000 ),
96+ Employee (10012 , 'Balnc ' , 'Campinas ' , 15000 ),
97+ Employee (10013 , 'Perry ' , 'Resende ' , 15000 ),
98+ Employee (10014 , 'Gable ' , 'Resende ' , 15000 ),
99+ Employee (10015 , 'Grimes ' , 'Recife ' , 15000 ),
96100 ];
97101 }
98102}
99103
100104class Employee {
101- Employee (this .id, this .name, this .designation , this .salary );
105+ Employee (this .id, this .name, this .city , this .freight );
102106
103107 final int id;
104108
105109 final String name;
106110
107- final String designation ;
111+ final String city ;
108112
109- final int salary ;
113+ final int freight ;
110114}
111115
112116class EmployeeDataSource extends DataGridSource {
@@ -115,9 +119,8 @@ class EmployeeDataSource extends DataGridSource {
115119 .map <DataGridRow >((e) => DataGridRow (cells: [
116120 DataGridCell <int >(columnName: 'id' , value: e.id),
117121 DataGridCell <String >(columnName: 'name' , value: e.name),
118- DataGridCell <String >(
119- columnName: 'designation' , value: e.designation),
120- DataGridCell <int >(columnName: 'salary' , value: e.salary),
122+ DataGridCell <String >(columnName: 'city' , value: e.city),
123+ DataGridCell <int >(columnName: 'freight' , value: e.freight),
121124 ]))
122125 .toList ();
123126 }
@@ -132,7 +135,9 @@ class EmployeeDataSource extends DataGridSource {
132135 return DataGridRowAdapter (
133136 cells: row.getCells ().map <Widget >((e) {
134137 return Container (
135- alignment: Alignment .center,
138+ alignment: ['id' , 'freight' ].contains (e.columnName)
139+ ? Alignment .centerRight
140+ : Alignment .centerLeft,
136141 padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
137142 child: Text (e.value.toString ()),
138143 );
0 commit comments