Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] When changing filters programatically only the last filter is applied #105

Open
TimoSchmuck opened this issue Dec 5, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@TimoSchmuck
Copy link

I want to set more than one filter programatically. For one filter it is working as expected, but not for more. Only the last filter is applied.

Steps to reproduce the bug:
Have two columns in PlutoGrid and then changing two filters at the same time via the eventManager is not working.

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      stateManager!.eventManager!.addEvent(
        PlutoGridChangeColumnFilterEvent(
            column: column[0],
            filterType: const PlutoFilterTypeContains(),
            filterValue:  'columnFilter0'
            debounceMilliseconds:
                stateManager!.configuration.columnFilter.debounceMilliseconds),
        );
        stateManager!.eventManager!.addEvent(
          PlutoGridChangeColumnFilterEvent(
              column: column[1],
              filterType: const PlutoFilterTypeContains(),
              filterValue: 'columnFilter1',
              debounceMilliseconds:
                  stateManager!.configuration.columnFilter.debounceMilliseconds),
        );
});

Execution Environment

Flutter 3.24.5 • channel stable • https://github.com/flutter/flutter.git
Dart 3.5.4 
DevTools 2.37.3

PlutoGrid version
pluto_grid_plus: ^8.4.3

OS
web

@TimoSchmuck TimoSchmuck added the bug Something isn't working label Dec 5, 2024
@stan-at-work
Copy link

@TimoSchmuck I'l check it out

@stan-at-work
Copy link

stan-at-work commented Dec 7, 2024

@TimoSchmuck I fixed the bug

The issue was that the PlutoGridEventType.debounce was blocking your second event.

I’ve made it configurable, and the default is now set to PlutoGridEventType.normal, which means no transformer is blocking your events.

I’ve also updated all other references that were using PlutoGridEventType.debounce to ensure no side effects occur as a result of this change..

Recording-2024-12-07-172728


You can test it with this code (AFTER MY PR IS MERGED)
import 'package:flutter/material.dart';
import 'package:pluto_grid_plus/pluto_grid_plus.dart';

class EmptyScreen extends StatefulWidget {
  static const routeName = 'empty';

  const EmptyScreen({super.key});

  @override
  _EmptyScreenState createState() => _EmptyScreenState();
}

class _EmptyScreenState extends State<EmptyScreen> {
  late List<PlutoColumn> columns;

  late List<PlutoRow> rows;

  late PlutoGridStateManager stateManager;

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

    columns = [
      PlutoColumn(
        title: 'column1',
        field: 'column1',
        type: PlutoColumnType.text(),
      ),
      PlutoColumn(
        title: 'column2',
        field: 'column2',
        type: PlutoColumnType.text(),
      ),
      PlutoColumn(
        title: 'column3',
        field: 'column3',
        type: PlutoColumnType.text(),
      ),
    ];

    rows = [
      for (int i = 1; i <= columns.length; i++)
        PlutoRow(
          cells: {
            'column1': PlutoCell(value: 'column${i + 1}'),
            'column2': PlutoCell(value: 'column${i + 2}'),
            'column3': PlutoCell(value: 'column${i + 3}'),
          },
        ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          TextButton.icon(
            label: Text('Clear filter'),
            onPressed: () {
              stateManager.eventManager!.addEvent(
                PlutoGridClearColumnsFilterEvent(columns: columns),
              );
            },
            icon: Icon(Icons.clear),
          ),
          TextButton.icon(
            label: Text('Set filter'),
            onPressed: () {
              stateManager.eventManager!.addEvent(
                PlutoGridChangeColumnFilterEvent(
                  column: columns[1],
                  filterType: const PlutoFilterTypeContains(),
                  filterValue: 'column3',
                ),
              );
              stateManager.eventManager!.addEvent(
                PlutoGridChangeColumnFilterEvent(
                  column: columns[0],
                  filterType: const PlutoFilterTypeContains(),
                  filterValue: 'column2',
                ),
              );
            },
            icon: Icon(Icons.add),
          )
        ],
      ),
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.all(15),
          child: PlutoGrid(
            columns: columns,
            rows: rows,
            onChanged: (PlutoGridOnChangedEvent event) {
              print(event);
            },
            onLoaded: (PlutoGridOnLoadedEvent event) {
              stateManager = event.stateManager;
            },
          ),
        ),
      ),
    );
  }
}

stan-at-work pushed a commit to stan-at-work/pluto_grid_plus that referenced this issue Dec 7, 2024
@stan-at-work
Copy link

@doonfrs Could you look at the PR for this ?

#111

@stan-at-work stan-at-work mentioned this issue Dec 7, 2024
@TimoSchmuck
Copy link
Author

Hi, thank you for your quick response. I will check it out as soon as the new version is going live!

Copy link

github-actions bot commented Jan 8, 2025

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Jan 8, 2025
@stan-at-work
Copy link

@doonfrs Could you close this ?

@github-actions github-actions bot removed the stale label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants