Introducing a Super-Fast DataGrid Widget for Flutter | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Introducing a Super-Fast DataGrid Widget for Flutter

Introducing a Super-Fast DataGrid Widget for Flutter

Data grids play a vital role in software development in all platforms, and Flutter is not an exception in this. So, we developed a DataGrid widget for the Flutter platform that is very fast and is capable of handling very large amounts of data. This DataGrid widget in Flutter is now available in our 2020 Volume 2 release

The Syncfusion Flutter DataGrid can be used to display and manipulate data in tabular format.

It was built from the ground up to achieve the best possible performance even when loading a large amount of data.

The DataGrid has the following essential features in its initial release:

Let’s look at these features and the steps to integrate this new widget into your app in this blog post.

Different types of columns

DataGrid lets you display different data types (int, double, string, and date-time) in different columns. It can load any widget in its columns for data visualization. The following column types are supported:

  • GridTextColumn: To display the string data type.
  • GridNumericColumn: To display the numeric data types such as int, double.
  • GridDateTimeColumn: To display the date-time data type.
  • GridWidgetColumn: To load any widget or multiple widgets.

Also, GridNumericColumn and GridDateTimeColumn types provide support to format the values based on the NumberFormat and DateFormat, respectively.

The following screenshot shows the DataGrid with a Dealer column, which is a GridWidgetColumn that loads the Image widget.

GridWidgetColumn with Image Widget
GridWidgetColumn with Image Widget

Real-time updates

The DataGrid can handle high-frequency updates for demanding scenarios. You can refresh specific cells when the corresponding cells’ data is updated in the underlying data source.

The following .gif image shows the DataGrid updating the real-time stock exchange data with high frequency.

Real-Time Updates in Flutter DataGrid
Real-Time Updates in Flutter DataGrid

Column sizing

Column width can be adjusted (auto fit) based on the content of any column or column header. All the   columns can be made to fit in the viewport of the DataGrid.

It is also possible to hide specific columns based on the device’s resolution. You can customize the width of all the columns or individual columns with the built-in column-sizing options.

Row selection

DataGrid lets you select a row or multiple rows with the following built-in selection modes:

    • Single: Only one row can be selected.
    • Single deselect: Only one row can be selected and it can be deselected on tapping again on that row.
    • Multiple: Multiple rows can be selected and deselected, as well.

Note: You can use the keyboard to navigate through rows and cells in the web platform.

Refer to the following screenshot.

Row Selection in Flutter DataGrid

Styling and conditional styling

You can customize element styles such as text style and background color in the DataGrid to display visually appealing data. You can also customize the styles conditionally based on the data.

Refer to the following screenshot.

Styling and Conditional Styling in Flutter DataGrid

Row height customization

You can adjust (auto fit) the row height based on the content of any column or certain columns to           enhance the readability of the content. It is also possible to set the row height conditionally.

Refer to the following screenshot.

Row Height Customization in Flutter DataGrid

Theme

The DataGrid control has light and dark built-in theme support to adapt the control to the rest of the business application.

Refer to the following screenshot.

Flutter DataGrid with Dark Theme Support

Getting started with the DataGrid widget

We have seen the primary features of the Flutter DataGrid widget. This section will explain the steps to add the Flutter DataGrid widget to your application and use its basic features.

Step 1: Add Flutter DataGrid to an application

Create a simple project using the instructions given in the Getting started with your first Flutter app documentation.

Step 2: Add dependency

Add the following Syncfusion Flutter DataGrid dependency to your pubspec.yaml file.

dependencies:
syncfusion_flutter_datagridr: ^xx.x.xx

Note: Here, xx.x.xx denotes the version of the Syncfusion Flutter DataGrid package.

Step 3: Get packages

Run the following command to get the required packages.

$ flutter pub get

Step 4: Import package

Import the following package in your Dart code.

import 'package:syncfusion_flutter_datagrid/datagrid.dart';

Step 5: Creating data for an application

Create a simple data source for SfDataGrid as shown in the following code example.

Here, we are giving the employee details as the data for the DataGrid.

class Employee {
  Employee(this.id, this.name, this.designation, this.salary);
  final int id;
  final String name;
  final String designation;
  final int salary;
}

Create the collection of employee data with the required number of data objects. The method used to populate the data objects is initialized in the initState().

  @override
  void initState() {
    super.initState();
    populateData();
  }

  void populateData() {
    _employees.add(Employee(10001, 'James', 'Project Lead', 20000));
    _employees.add(Employee(10002, 'Kathryn', 'Manager', 30000));
    _employees.add(Employee(10003, 'Lara', 'Developer', 15000));
    _employees.add(Employee(10004, 'Michael', 'Designer', 15000));
    _employees.add(Employee(10005, 'Martin', 'Developer', 15000));
    _employees.add(Employee(10006, 'Newberry', 'Developer', 15000));
    _employees.add(Employee(10007, 'Balnc', 'Developer', 15000));
    _employees.add(Employee(10008, 'Perry', 'Developer', 15000));
    _employees.add(Employee(10009, 'Gable', 'Developer', 15000));
    _employees.add(Employee(10010, 'Steve', 'Testing Engineer', 15000));
    _employees.add(Employee(10011, 'Nancy', 'Testing Engineer', 15000));
    _employees.add(Employee(10012, 'Andrew', 'UX designer', 15000));
    _employees.add(Employee(10013, 'Zachery', 'UX designer', 15000));    
  }

Step 6: Creating a DataSource for DataGrid

DataGridSource is used to obtain the row data for the SfDataGrid. So, create the DataSource from the DataGridSource and override the following APIs in it:

  • dataSource: To fetch the number of rows available for data population. Also, it is used to fetch the corresponding data object to process the selection.
  • getCellValue: To fetch the value for each cell.

DataGridSource objects are expected to be long-lived, not recreated with each build.

Refer to the following code example.

final List<Employee> _employees = <Employee>[];

final EmployeeDataSource _employeeDataSource = EmployeeDataSource();

class EmployeeDataSource extends DataGridSource {
  @override
  List<Object> get dataSource => _employees;

  @override
  getCellValue(int rowIndex, String columnName) {
    switch (columnName) {
      case 'id':
        return _employees[rowIndex].id;
        break;
      case 'name':
        return _employees[rowIndex].name;
        break;
      case 'salary':
        return _employees[rowIndex].salary;
        break;
      case 'designation':
        return _employees[rowIndex].designation;
        break;
      default:
        return ' ';
        break;
    }
  }

Create an instance of DataGridSource and set this object to the source property of SfDataGrid as in the following code example.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Syncfusion DataGrid'),
      ),
      body: SfDataGrid(
                    source: _employeeDataSource,
          ),
      ),
    );
  }

Step 7: Defining columns

As discussed earlier, SfDataGrid lets you show different data types (int, double, string, and date-time) in different types of columns. You can add the column collection to the columns property as illustrated in the following code example.

final EmployeeDataSource _employeeDataSource = EmployeeDataSource();
  
@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Syncfusion DataGrid'),
      ),
      Body: SfDataGrid(
                    source: _employeeDataSource,
                    columns: [
                      GridNumericColumn(mappingName: 'id',  headerText:'ID'),
                      GridTextColumn(mappingName: 'name', headerText: 'Name'),
                      GridTextColumn(mappingName: 'designation', headerText: 'Designation'),
                      GridNumericColumn(mappingName: 'salary', headerText: 'Salary'),
                    ],                                                   
                  ),
          ),
      ),
    );
  }

On executing this code example, we will get output like in the following screenshot.
Output showing the employees' Details

Coming soon

We are currently working on providing the following features for the DataGrid in our upcoming releases:

  • Editing
  • Sorting
  • Paging
  • Column resizing
  • Column drag and drop
  • Grouping
  • Row drag and drop

Conclusion

I hope you enjoyed this blog and got to know about the new Syncfusion Flutter DataGrid and its features. This widget is available in the 2020 Volume 2 release. You can find the user guide here, and you can also check out our samples in this GitHub location. Additionally, you can download and check out our demo app in Google Play and the App Store.

For existing customers, the new version is available for download from the License and Downloads page. If you are not yet a Syncfusion customer, you can try our 30-day free trial to check out our available features.

Also, if you need a new widget for the Flutter framework or new features in our existing widgets, please let us know in the comments section below. You can also contact us through our support forumDirect-Trac, or feedback portal. We are always happy to assist you!

googleplay.png

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed