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

rowData & columnData with Closure #16

Open
truonghuytq opened this issue Dec 28, 2024 · 3 comments
Open

rowData & columnData with Closure #16

truonghuytq opened this issue Dec 28, 2024 · 3 comments

Comments

@truonghuytq
Copy link

image

rowData & columnData has supported closure but the function is not. Please update

@atmonshi
Copy link
Member

how do you suggest to fix this?

@truonghuytq
Copy link
Author

Copied from filament select options

    protected array | Arrayable | string | Closure $columnData = [];

    public function columnData(array | Arrayable | string | Closure $data): static
    {
        $this->columnData = $data;

        return $this;
    }

    public function getColumnData(): array
    {
        $columns = $this->evaluate($this->columnData) ?? [];

        if (is_string($columns) && enum_exists($enum = $columns)) {
            if (is_a($enum, LabelInterface::class, allow_string: true)) {
                return array_reduce($enum::cases(), function (array $carry, LabelInterface & UnitEnum $case): array {
                    $carry[$case?->value ?? $case->name] = $case->getLabel() ?? $case->name;

                    return $carry;
                }, []);
            }

            return array_reduce($enum::cases(), function (array $carry, UnitEnum $case): array {
                $carry[$case?->value ?? $case->name] = $case->name;

                return $carry;
            }, []);
        }

        if ($columns instanceof Arrayable) {
            $columns = $columns->toArray();
        }

        return $columns;
    }

@atmonshi
Copy link
Member

great, if you test it and its working in your case, can you submit a PR

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants