Implementing a table on a resource-view-page
Hey - I think I'm missing something, so maybe just point me in the right direction.
Given I got a resource with a relation to another model. Now what I wanna do is something like this on my view-page:
But
Section->schema
expects type Filament\Forms\Components\Component
- so I tried creating my own component via php artisan make:component MyComponent
and following the table-builder-docs, but filament seem to not like this aswell, since it's throwing Argument #1 ($component) must be of type Filament\Forms\Components\Component, App\View\Components\MyComponent given
.
Hopefully I'm missing an easy way here, since I just want a simple table for my relation and creating a new component (even if it works) would just add aditional load to the database, since I already got my relation already loaded through the view-page.53 Replies
Why not use the Relationship Manager for this?
Filament
Relation managers - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Might be an idea, but how do I get it into the Section->schema()-function on my view page?
So this will allow you to add it to the Resource which is what you are trying to do. It will automatically add it to the footer and if you define more than 1, it will create a tab effect to tab between them
Ah okay, but that approach is completely out of the question here.
My Viewpage is basically a Template which I wanna use for multiple purposes and "just adding to the footer" won't work here.
Plus - there will be other components on the footer aswell, so I need a more generalized approach.
You asked how to add it to the view page of the resouce. This is how you do that
So you have a custom app outside of the resource
inside the ->schema-function on said view-page... 😉
I was hoping that there is something along the lines of Grid::make -> but with Tables.
You cannot add a table to the schema, you could render another component inside it, so a bespoke livewire component with tables added, then just render that livewire component.
But that gives me the error which I stated above. So I guess that my call to my custom-component might be wrong?
You're schema above is not rendering a custom livewire component as far as I can see
You have a custom field for Tables but that's all
I tried my custom-component like this:
But that resulted in 'Argument #1 ($component) must be of type Filament\Forms\Components\Component, App\View\Components\MyComponent given' -> so maybe my call is wrong here?
I don't get what you are trying to tell me with this - sorry. 🙂
But like I said - maybe my custom-component call is wrong?
Sorry if I seem a bit dumb - I'm new to the whole Livewire + Filament world. 🙂 I'm used to jQuery and plain old views... 😄
The way I would do it is just build a livewire component and implement tables as normal.
php artisan make:livewire CustomTables
Then use the view field wihtin forms to render that component i.e.
livewire.CustomTables
You can pass the id within viewData on the view field to fetch the records. If I understand what you are trying to do correctly.
So my call would actually have to look like this?
I tried that, but then I get
Property [$table] not found on component
even tho it implements HasTable and uses InteractsWithTable...You need to read the docs on how to add the table to a livewire component 😉
Hahahaha - I did and that gives me the "property $table not found"-error... 😄 I am genunely wondering if I am too stupid or if i'm missing something...
Okay - I will try to retrace my steps here... I think I made an error somewhere.
So when that error occurs it means that the livewire component is not setup for tables and tables has now been implemented on the table class.
Can you provide your custom component file
I'm on it - but I have to redact it, since it's a commercial-project. Gimme a minute. 🙂
1.)
php artisan make:component MyComponent
2.) adding {{ $this->table }}
to the view.
3.) Docs: "Implement the HasTable interface and use the InteractsWithTable trait" -> ✅
4.) Add relationmarker to constructor for query -> ✅
5.) Set query and one colum to test. -> ✅
Now my file looks like this:
and the Secion-code should look like this then:
Section::make('myheader')
->icon('myicon')
->schema([
View::make('components.my-custom-components.relationship-stuff.thisone')->viewData(['relationID' => $this->record->id])
])
those were my steps so far...You’re not using a livewire component. Using make:view creates a laravel component. They are different things.
No - I used
php artisan make:component MyComponent
-> should that not create a Livewire-Component? Is Laravel (10) dumb here? 😄That is wrong. You need make:livewire to create a livewire component.
Laravel component !== Livewire component.
Like I posted above 🤣 it’s not your day @husky110 😜
I love you too man. ❤️ 🤣
Okay - I tried using a livewire-component but i'm still getting "Property [$table] not found on component : [app.filament.resources.shippingmanagement.deliveries-resource.pages.view-deliveries]" -> which is actually the page and not the component-view? The flying f?
@awcodes - We need a dumbed down Table-Component simillar to "Grid::make" - like Table::make for morons like me... 😄
Well, tables inside of forms isn’t a common use case. There is a table widget though.
Actually I'm on a view-page (like /show) and not a form...
The view page is just a disabled form.
Under the hood - possible. But here I see a pretty heavy usecase, since it's about displaying details. 🙂
And tables themselves dont work inside a form because they use forms themselves for the filters and in html you can’t nest forms.
That's what I meant with "dumbed down" -> there are no filters! Just show me the freaking relation-details and that's it. 😄
Thats why we have the table widget. You just won’t be able to add it to a section inside the form schema.
That’s exactly what relation managers do.
You still can’t put them in a form schema though.
And that's my problem with that... 😄
I have to develop that 💩 myself - right? 😄
You could still use a custom view with a normal table.
Or you can make a custom page then layout any way you need. You just can’t use the tables package inside a form. That’s a limitation of html since the tabes package uses forms for certain aspects of the table.
Hmm - maybe an idea for V3 or a plugin... Like some sort of "easy" table that just shows records, but has none of the comfort-features. Cause the output of the table-package is great and does not use traditional tables. Would be realy great to have that easily accessible.
V3 will have InfoLists. Not really a table but a more controlled way to display readonly data.
What we are talking here about is listing the positions on a deliveryslip (I can say that much) and there something along the lines of
Table::make('relationname')->columns([TextColumn::make('relation_p1'), TextColumn::make('relation_p2')])
would be really cool.GitHub
filament/packages/infolists/docs/02-getting-started.md at 3.x · fil...
Admin panel, form builder and table builder for Laravel. Built with the TALL stack. Designed for humans. - filament/packages/infolists/docs/02-getting-started.md at 3.x · filamentphp/filament
Thanks. Right now I'm fearing that V3 will have to include a rewrite of anything I've done with V2 so far, which is not in my ballpark for the next 3-4 months at least, since I'm developing my app alone.
It will include an upgrade script that should limit what you’ll need to rewrite.
Yep - still a month away tho and I will wait a bit longer, just to get the first common bugs out. 😉
Okay - back to my table... So I will have to build it myself somehow - got it.
Obviously, custom components and things like that are outside the scope of that script.
I reckoned. 🙂
There’s also #awcodes-table-repeater which might get you what you’re after. Might have to massage the data a little though.
It’s an extension of the repeater formatted to render as a table.
Hmm - I was think about this one aswell... But for now I think I will just make a custom view and get done with it.
So for now - anyone reading this: Getting a filament-style-table into a page is not really directly possible at the moment.
Wellll, it is possible, just not exactly simple 🙂 Here's a table in a form :
I've used tables like this in many places and the key is really what toeknee and awcodes have said above: to rely on custom livewire components to wrap the table and to know the implications of nested form tags. Either you avoid the outer form tag (you can use a full filament form without a wrapping form tag) or you make sure not to rely on the inner form's behavior (because the browser will extract it out of the parent form element)
Great
Can you please provide some code for this? 🙂
I'm planning on writing a short article on it in the Tricks section of the website. In the meantime, maybe I can help you from where you are now. What solution did you land on in the end for your use-case?
you'll love this 😅
Just to recap what I have in the short video ☝️
- Starting on a regular Filament Edit page
- Added a form component as a wrapper for a custom Livewire component
- Added the Livewire component, implementing the
HasTable
interface
- Modified the table
Blade template to remove the nested form
elements (not needed for my use-case)
I call it "the crappy livewire-/filament-noob-approach that get's the job done. 😄
View::make('myshittyapproach')->viewData(['data' => $lol]);
If it's any encouragement for you, I'm also doing this in another part of my app (custom <table> markup reusing the filament CSS classes)
hmmm - seeing my m again - I really should make a package out of it...
to anyone seeing this -> m is my memcached-replacement for the __ function ^^