Sorting doesn't work with onCellTap

Hello!

If I have allowSorting set to true, and then implement onCellTap(), then clicking on the column header no longer sorts the rows.

Sorting works fine without onCellTap().

Is there something I'm missing?

Also, is there a way to map a Cell's rowIndex to the object passed in to the DataGridSource?

Any help would be greatly appreciated. Thanks!


1 Reply

TP Tamilarasan Paranthaman Syncfusion Team September 21, 2022 01:44 PM UTC

Hi Grady,


Based on the provided information, we are unable to reproduce the reported issue. We have tested the following sample and the sorting is working with the onCellTap callback.


Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sample1238145130


Demo: https://www.syncfusion.com/downloads/support/directtrac/general/ze/demo-899956911


Please check the above sample and demo video. If you are still facing the same issue, please provide the following details to check further.


·       Provide a sample that is reproducible or modify the above sample as reproducible.

·       The platform (Web/Android/Windows/macOS/iOS) on which you faced the issue.

·       Flutter and DataGrid version which you have used.


It will be helpful for us to check on it and provide you with the solution at the earliest.


Regarding Query: Also, is there a way to map a Cell's rowIndex to the object passed in to the DataGridSource?


You can get the row index by finding the indexOf of the row from the DataGridSource.effectiveRows. Please check the following code snippet.


  @override

  Widget build(BuildContext context) {

    return Scaffold(

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

        body: SfDataGrid(

            source: datagridSource,

            columnWidthMode: ColumnWidthMode.fill,

            columns: getColumns,

            allowSorting: true,

            onCellTap: (details) {

              if (details.rowColumnIndex.rowIndex > 0) {

                int index = details.rowColumnIndex.rowIndex;

                DataGridRow row =

                    datagridSource.effectiveRows.elementAt(index - 1);

                int rowIndex = datagridSource.effectiveRows.indexOf(row);

                print(rowIndex);

              }

            }));

  }


We hope this helps. In case we misunderstood your requirement, please provide more specific or clear use case details. It will be helpful for us to check and provide an appropriate solution.


Regards,

Tamilarasan


Loader.
Up arrow icon