Images don't move when other columns are sorted

Following the example projects, you can see that the image column does not move when other columns are sorted.

Is there a way to load images into a grid column such that they actually move with their associated data? The demo project just puts the images in a separate container, and the column sorting example just doesn't include images.

In the example below you can see that the images remain fixed even though the order of ID/Name has changed.






3 Replies 1 reply marked as answer

NK Neelakandan Kannan Syncfusion Team November 3, 2020 11:47 AM UTC

Hi Grady,

 

Thanks for contacting Syncfusion support.

 

If you want to load an image based on the currently sorted order, you have to use the DataGridSource[index] indexer instead of the datasource collection which you set in dataSource property of DataGridSource. DataGrid provides the inner sorted list collection in the DataGridSource[index]indexer. Please find the below code snippet,

 

@override

  Widget build(BuildContext context) {

    return Scaffold(

        appBar: AppBar(title: Text('Syncfusion Flutter DataGrid')),

        body: SfDataGrid(

            allowSorting: true,

            source: _employeeDataSource,

            columnWidthMode: ColumnWidthMode.auto,

            cellBuilder:

                (BuildContext context, GridColumn column, int rowIndex) {

              return Container(

                padding: const EdgeInsets.all(3),

                child: _employeeDataSource[rowIndex].dealer,

              );

            },

            columns: _columns));

  }

 

Sample link: https://www.syncfusion.com/downloads/support/forum/159317/ze/Sorting_Example-2056397591.zip

 

Regards,

Neelakandan


Marked as answer

GR Grady November 3, 2020 02:55 PM UTC

Right! I was using the collection instead of the source. Thanks so much Neelakandan!


NK Neelakandan Kannan Syncfusion Team November 4, 2020 04:23 AM UTC

Hi Grady,

Thanks for your update.

We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you.  


Loader.
Up arrow icon