#Make table data selectable based on condition

3 messages · Page 1 of 1 (latest)

manic nova
#

I want to make my table data selectable if its status == 1

is there any way to do that?

My goal here is that I wanted to create a custom bulk action which they can borrow the available item.

  public function table(Table $table): Table
    {
        return $table
            ->heading('Inventories')
            ->emptyStateHeading('No inventories yet')
            ->selectable() // Only selectable if status is 'Available'
            ->columns([
                TextColumn::make('serial_number')
                    ->label('Serial Number')
                    ->sortable()
                    ->searchable(),
                TextColumn::make('status')
                    ->label('Status')
                    ->sortable()
                    ->badge()
                    ->color(fn ($state) => match ($state) {
                        0 => 'danger',     // for 'Unavailable'
                        1 => 'success',    // for 'Available'
                    })
                    ->formatStateUsing(fn ($state) => $state ? 'Available' : 'Unavailable')
                    ->searchable(),
                TextColumn::make('created_at')
                    ->sortable()
                    ->dateTime('F j h:i A')
                    ->searchable()
            ])
            ->filters([
                // Add table filters if necessary
            ])
            ->actions([
                // Add table actions if necessary
            ])
            ->bulkActions([
                // Add bulk actions if necessary
            ]);
    }

TIA ❤️

mental fractalBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

kindred lotus