bosskmk / pluto_grid

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
637 stars 291 forks source link

[Feature] Advanced filtering option (AND, OR, ...) #956

Closed jubnl closed 7 months ago

jubnl commented 9 months ago

Problem : All filters seem to be AND filters. I need to filter a column based on several possible values.

Examples:

Initial table: Col1 Col2
A D
A E
B E
C F
Filter: Col1(value = A OR B) Col1 Col2
A D
A E
B E
Filter: Col1(value = B OR C) Col1 Col2
B E
C F

At the moment I haven't found a way other than filtering the rows myself, then removing all rows and adding my filtered rows.

Acacio2000 commented 9 months ago

See: https://github.com/bosskmk/pluto_grid/blob/master/demo/lib/screen/feature/column_filtering_screen.dart ClassYouImplemented

In this my example to every text fields use custom filter and CaseInsensitive I converted every text fields to UPPER Use COMMA to separate words: Ex: "A,B" "B,C" in any order: "A,B" = "B,A"

String toUpperCaseWithoutAccents(String input) { input = removeDiacritics(input).trim().toUpperCase(); return input; }

class ClassFilterContainAllWords implements PlutoFilterType { const ClassFilterContainAllWords(); @override get compare => ({ required String? base, required String? search, required PlutoColumn? column, }) { if (search != null) { search = toUpperCaseWithoutAccents(search); } var keys = search!.split(',').map((e) => e.trim().toUpperCase()).toList(); return keys.every((key) => base!.toUpperCase().contains(key)); }; @override String get title => 'Custom filter'; }

columnFilter: PlutoGridColumnFilterConfig( filters: const [ ...FilterHelper.defaultFilters, ClassFilterContainAllWords(), ], resolveDefaultColumnFilter: (column, resolver) { if (column.type is PlutoColumnTypeText) { return resolver() as PlutoFilterType; } return resolver() as PlutoFilterType; }, ),

image

image

github-actions[bot] commented 8 months ago

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

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.