omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
261 stars 114 forks source link

feat: add Searchable EnumColumn and improve SearchCriteriaProvider #292

Closed Chris53897 closed 1 year ago

Chris53897 commented 1 year ago

My goal is to have a searchable enums. The enum has a label() function to get the searchable (display) name. You can search for "Männ" and it filters the dataset correct. Find search-Values in Enum::labels() or names of an enum and configure the search-query accordingly.

For this reason i need the IN Operator, that is not yet possible, if i see this correct. There are more possible implementation. I want to know how you want this to be handled.

Tests will be added after idea is general approved.

Example Enum:

`Enum GenderType: string { case MALE = 'M'; case FEMALE = 'F';

public function label(): string
{
    return self::getLabel($this);
}

public static function getLabel(self $value): string
{
    return match ($value) {
       // Lang: German
        self::MALE    => 'Männlich',
        self::FEMALE  => 'Weiblich',
    };
}`

Ideas for improvement:

WDYT?

github-actions[bot] commented 1 year ago

Stale pull request message

Chris53897 commented 1 year ago

Waiting for reponse from @curry684 It would be great at least to have the IN-Operator in the main repo. I do not know if the enum Case is generic enough for you.

curry684 commented 1 year ago

Sorry I don't habitually look into draft PRs, and it's complicated to review lots of changes in one.

  1. I don't think a separate handler for IN is needed as IN is similar to other expressions with a left/right expr. Fully supported by Doctrine's comparisons as well: https://www.doctrine-project.org/projects/doctrine-collections/en/stable/expressions.html
  2. This is beside that I think IN should not be used for freetext filtering. If the target data is discrete as with an enum the filter should be a dropdown, and then you can just use = for comparison again.
  3. I'm not sure what the case is for a specific EnumColumn then, as enums support __toString and are therefore fully compatible with TextColumn, TwigColumn et al. The use of pseudointerfaces (defining a function that should be implemented on the enum) is not something I support.
Chris53897 commented 1 year ago

Thanks for your review.

1) I do not know how to rewrite the IN-Expression for Enums. But as this will no be added, i will use my fork. 2) Additional i added Dropdown for Filtering. Search would have been some nice addon. 3) The reason behind the additional function name, is that we have multiple Text-Representations of our enums (short, long, html)

I will close this