doonfrs / pluto_grid_plus

PlutoGrid is a dataGrid for flutter that can be controlled by the keyboard on desktop and web. Of course, it works well on Android and IOS.
https://pluto.weblaze.dev
MIT License
18 stars 20 forks source link

[Bug] stateManager.setPage() not working #49

Open johnzhu123 opened 2 months ago

johnzhu123 commented 2 months ago

Steps to reproduce the bug

  1. create a button on the pluto_grid header
  2. on the handler function, use stateManager set the page
  3. navigate the page to page 3
  4. click the Clear Filters button
image

Page 1

image

Page 3

after click the button, the data is reacquired, but the page stay on page 3

image

Data is page 1, but the page stay on page 3

Expected results

when I use stateManagerProviders?.setPage(1); should jump to page 1

Actual results

but the page stayed on other page

Code sample

 late final PlutoGridStateManager stateManagerProviders;

PlutoGrid(
                  columns: newColumns,
                  rows: myDataRows,
                  onLoaded: (PlutoGridOnLoadedEvent event) {
                    stateManagerProviders = event.stateManager;
                    stateManagerProviders?.setShowColumnFilter(true);
                  },
                  onChanged: (PlutoGridOnChangedEvent event) {
                    print(event);
                  },
                  configuration: PlutoGridConfiguration(
                    style: const PlutoGridStyleConfig(
                      evenRowColor: Color.fromARGB(255, 239, 240, 245),
                    ),
                    columnFilter: PlutoGridColumnFilterConfig(
                      filters: const [
                        ...MyDefaultFilters,
                      ],
                      resolveDefaultColumnFilter: (column, resolver) {
                        if (column.field == 'text') {
                          return resolver<PlutoFilterTypeEquals>()
                              as PlutoFilterType;
                        } else if (column.field == 'number') {
                          return resolver<PlutoFilterTypeGreaterThan>()
                              as PlutoFilterType;
                        } else if (column.field == 'date') {
                          return resolver<PlutoFilterTypeLessThan>()
                              as PlutoFilterType;
                        } else if (column.field == 'select') {
                          return resolver<ClassYouImplemented>()
                              as PlutoFilterType;
                        }

                        return resolver<PlutoFilterTypeContains>()
                            as PlutoFilterType;
                      },
                    ),
                  ),
                  createHeader: (stateManager) {
                    return Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 10.0, vertical: 20.0),
                      child: MSKButton(
                        label: 'Clear Filters',
                        onPressed: () {
                          // this line will clear the filters
                          stateManagerProviders?.filterRows?.clear();
                          stateManagerProviders?.setPage(1);     // not working 
                          // stateManager.setPage(1);    //also not working 
                          filtersParam = filtersParam.where((item) {
                            return item["filterprop"] ==
                                myDefaultFilter["filterprop"];
                          }).toList();
                          _onFetch(PlutoLazyPaginationRequest(
                            page: 1,
                          ));
                        },
                      ),
                    );
                  },
                  createFooter: (stateManager) {
                    return PlutoLazyPagination(
                      // Determine the first page.
                      // Default is 1.
                      initialPage: 1,

                      // First call the fetch function to determine whether to load the page.
                      // Default is true.
                      initialFetch: true,

                      // Decide whether sorting will be handled by the server.
                      // If false, handle sorting on the client side.
                      // Default is true.
                      fetchWithSorting: true,

                      // Decide whether filtering is handled by the server.
                      // If false, handle filtering on the client side.
                      // Default is true.
                      fetchWithFiltering: true,

                      // Determines the page size to move to the previous and next page buttons.
                      // Default value is null. In this case,
                      // it moves as many as the number of page buttons visible on the screen.
                      pageSizeToMove: null,
                      fetch: _onFetch,
                      stateManager: stateManager,
                    );
                  })

Execution Environment

Flutter version Flutter 3.23.0-0.1.pre • channel beta • https://github.com/flutter/flutter.git Framework • revision 2feea7a407 (4 weeks ago) • 2024-06-06 10:19:10 +0700 Engine • revision bb10c54666 Tools • Dart 3.5.0 (build 3.5.0-180.3.beta) • DevTools 2.36.0

PlutoGrid version pluto_grid_plus: ^8.4.1

OS macOS 14.5 (23F79)