Skip to content

Exporting a dynamic column that's done using getStateUsing #224

@jimiero

Description

@jimiero

Hello,

On my FilamentPHP table, i have some dynamic columns build like:

$columns[] = TextColumn::make('total_user')
            ->label('Total')
            ->alignCenter()
            ->getStateUsing(function ($record, Table $table) use ($total_user) {
                $total = 0; // Initialize total
                foreach ($table->getColumns() as $column) {
                    /** @var TextColumn  $column */
                    $columnName = $column->getName();

                    // Check if the column name starts with 'day_'
                    if (strpos($columnName, 'day_') === 0) {
                        // Get the state of the current column (value)
                        $state = $column->getState();
                        // Add the state to the total if it's numeric
                        if (is_numeric($state)) {
                            $total += $state;
                        }
                    }
                }

                return $total;
            });

@pxlrbt

When I browse the table using filamentphp all good, that column state returns the correct value, but in the export it comes with value 0 any idea what it may be wrong?

@

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions