maxim-saplin / data_table_2

In-place substitute for Flutter's DataTable and PaginatedDataTable with fixed/sticky header and extra features
https://pub.dev/packages/data_table_2
BSD 3-Clause "New" or "Revised" License
202 stars 135 forks source link

How to have selected rows on table create with AsyncDataTableSource? #254

Open francois-robert opened 7 months ago

francois-robert commented 7 months ago

Is there a way to have selected rows when creating table with AsyncDataTableSource? I tried to pass selected at true on every DataRow2 within getRows() function but it does nothing.

Any idea ?

@override
  Future<AsyncRowsResponse> getRows(int startIndex, int count) async {
    final (items, paging) = await context.read<C>().fetchWithPaging(offset: startIndex, pageSize: count);

    this.items = items ?? [];

    if (items == null || paging == null) return AsyncRowsResponse(0, []);

    return AsyncRowsResponse(
      paging.total ?? 0,
      items
          .map(
            (item) => DataRow2(
              key: ValueKey<int>(item.hashCode),
              selected: true,
              onSelectChanged: selectable ? (value) => performSelectChanged(item, value) : null,
              color: color == null ? null : color!(item),
              cells: buildCells(context, item, this).map((e) => DataCell(Center(child: e))).toList(),
            ),
          )
          .toList(),
    );
  }
maxim-saplin commented 7 months ago

AsyncDataTableSource abstract class has own logic for selection and setting selected: true, in the AsyncRowsResponse is ignored.

If you happen to submit a PR with a fix for that - I am happy to review.