© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3mo ago•
25 replies
mohdaftab

How to display the sum of total amount for selected records with bulk action?

3️⃣v3✅ SolvedTable builder
Hello,
I am struggling to find a way to show the sum from the amounts column when I select the rows using the bulkaction.
I want to show the total sum: $1000 like this besides the text 10 records selected just above the table.
Please let me know how can I do that?
Thank you so much.
image.png
Solution
@98.dev I got it to work

I added these values in the amounts column
TextColumn::make("amount")
                    ->prefix("$")

                    ->extraAttributes(function ($record) {
                        return [
                            'data-record-id' => $record->id,
                            'data-amount' => $record->amount, // or the column you want to sum
                        ];
                    })
                    ->sortable(),
TextColumn::make("amount")
                    ->prefix("$")

                    ->extraAttributes(function ($record) {
                        return [
                            'data-record-id' => $record->id,
                            'data-amount' => $record->amount, // or the column you want to sum
                        ];
                    })
                    ->sortable(),

then added thsi in ManageDriverPayments.php file

public function booted(): void
    {
        FilamentView::registerRenderHook(
            TablesRenderHook::SELECTION_INDICATOR_ACTIONS_BEFORE,
            fn() => view('components.driver-payment-selected-total-sum'),
            scopes: static::class
        );
    }
public function booted(): void
    {
        FilamentView::registerRenderHook(
            TablesRenderHook::SELECTION_INDICATOR_ACTIONS_BEFORE,
            fn() => view('components.driver-payment-selected-total-sum'),
            scopes: static::class
        );
    }


and then finally added this in driver-payment-selected-total-sum.php

<div
    x-data="{
        sum: 0,
        updateSum() {
            this.sum = selectedRecords.reduce((total, id) => {
                const row = document.querySelector(`[data-record-id='${id}']`);
                return total + (row ? Number(row.dataset.amount) : 0);
            }, 0);
        }
    }"
    x-effect="updateSum()"
    x-show="selectedRecords.length > 0"
    class="px-4 py-2 bg-gray-100 rounded-md dark:bg-gray-800">
    <p class="text-sm text-gray-700 dark:text-gray-300" style="color:green; font-weight:bold;">
        Total Sum: $<span x-text="sum.toFixed(2)"></span>
    </p>
</div>
<div
    x-data="{
        sum: 0,
        updateSum() {
            this.sum = selectedRecords.reduce((total, id) => {
                const row = document.querySelector(`[data-record-id='${id}']`);
                return total + (row ? Number(row.dataset.amount) : 0);
            }, 0);
        }
    }"
    x-effect="updateSum()"
    x-show="selectedRecords.length > 0"
    class="px-4 py-2 bg-gray-100 rounded-md dark:bg-gray-800">
    <p class="text-sm text-gray-700 dark:text-gray-300" style="color:green; font-weight:bold;">
        Total Sum: $<span x-text="sum.toFixed(2)"></span>
    </p>
</div>


and it works great.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Automatic Sum of Selected Bulk Action item column
FilamentFFilament / ❓┊help
13mo ago
Bulk Action: change "x records selected"
FilamentFFilament / ❓┊help
12mo ago
Accessing the selected records before firing a bulk action
FilamentFFilament / ❓┊help
13mo ago
Count selected records in Table Builder Bulk Action form
FilamentFFilament / ❓┊help
3y ago