-
I'm trying to have the filters result count shown on a custom element after the filter button, but It looks the $rows variable is not accessible there ? Any idea on how to get the Filter result count ? Thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 12 replies
-
If you check out #1051 , I've given a method to get the currently visible IDs. You can use the same approach to get the Count. Two different approaches depending on where you need the data If you need it back in the DataComponent as a variableComponent will have something like public int $rowCount = 0; public function configure(): void
{
$this->setComponentWrapperAttributes([
"x-data" => "{ rowCount : \$wire.entangle('rowCount ') }"
])
->setConfigurableAreas([
'before-pagination' => ['includes.areas.before-pagination']
]);
} Your custom blade (includes.areas.before-pagination) will have something like @aware(['rows','component'])
<div x-init="rowCount = {{ $rows->total() }};" ></div> Keep in mind this will cause an additional page load, so worth using .defer on the entangle() if you want to avoid this, it will result in your first render not containing this though! Another Blade within the Component (e.g. configurableArea or customView)Component will have something like public function configure(): void
{
$this->setComponentWrapperAttributes([
"x-data" => "{ rowCount : 0 }"
])
->setConfigurableAreas([
'before-pagination' => ['includes.areas.before-pagination']
]);
} Your custom blade (includes.areas.before-pagination) will have something like @aware(['rows','component'])
<div x-init="rowCount = {{ $rows->total() }};" ></div> You can then use the following in your blade. <span x-text="rowCount"></span> This approach WILL be up to date without an additional refresh. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I tried your solution
but $rows is always null ... |
Beta Was this translation helpful? Give feedback.
-
In my Resources/Views folder…
Where should it be then ?
Thanks !
… On 31 Mar 2023, at 00:53, Joe ***@***.***> wrote:
Where are you including your blade file?
—
Reply to this email directly, view it on GitHub <#1113 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJBTUDFXUL3WD74EQ2OCM23W6YFILANCNFSM6AAAAAAWCBJIF4>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
No, as I wanted to have the filter result count visible without having to scroll to the bottom of the table, I tried to use 'toolbar-left-end’.
|
Beta Was this translation helpful? Give feedback.
-
Yes the count is correctly displayed :)
|
Beta Was this translation helpful? Give feedback.
-
And there is probably some jquery code somewhere... |
Beta Was this translation helpful? Give feedback.
-
Yes I'm using slide-down filters... Thanks ++ Maybe I should wait for the next released then ? |
Beta Was this translation helpful? Give feedback.
-
Great ! FYI I'm adding the filter result count on the right of it with your solution... |
Beta Was this translation helpful? Give feedback.
Yeah, that won't work I'm afraid! You'll need to pass it in via Alpine.
There are a few steps here:
1) Set up an Alpine variable
Do this in the componentWrapper (so that it is available to all of the child elements). This will hold the rowCount!
2) Set two custom views
First blade - "rowCountUpdateView" must be in before-pagination OR after-pagination areas, this is used solely for setting the Alpine variable to the correct value! I'd recommend using the before-pagination area!
Second blade - "YourOtherCustomView" Wherever you'd like to display the value!