Creating a Hybrid Column for Dynamic Display/Edit of Settings

Hi, I'm currently working on creating a resource for my settings, and I plan to use only the List page of my resource to display and edit these settings. The challenge I'm facing is that some of my settings are strings, some are booleans, and others are choices made from select options. Is there a way to create a hybrid column that displays either a SelectColumn for selects, a ToggleColumn for booleans, or just a TextInputColumn for strings based on the type of the setting? Otherwise I think I can do it via the FormBuilder and an Edit Page / a modal but I would prefer to make it easier. If it's just modifying a string I would like us to type directly in a TextInputColumn and not go into a modal then type then click on validate etc. Thanks in advance
12 Replies
DrByte
DrByte15mo ago
To be clear, are you asking whether the table shown in the List view can be editable AND have different field-types in each ROW of the same Column? (instead of define a field type for a column and all rows are the same type)
arthurpar
arthurparOP15mo ago
Yep that's it. I would like to have a column which can have a different field type depending on each row
DrByte
DrByte15mo ago
I've not done that. I don't think there's a built-in way for that, at least not at the "table" level. I'm pretty sure that the way the table is built relies on looping through defined components, and may not allow for interfering with that pattern. But ... does it really need to be a table? Why not just a one-page form? For example, the built-in support for the spatie/laravel-settings package allows (requires) you to set up a Settings page, which is a Form of various kinds of input fields, with a Save/Submit button at the bottom.
DrByte
DrByte15mo ago
In this particular example all these fields are Text inputs, but they could be any Filament-supported input type.
No description
awcodes
awcodes15mo ago
Each column relates to a field on the database. There is no way to make this possible, not only from the html table spec, but from a logic spec too. You can’t, for instance have a table column that can be both a Boolean, a text and datetime. It’s just not possible. Ie, a name column, can’t persist as multiple types of data when read or persisted to the db.
DrByte
DrByte15mo ago
Each column relates to a field on the database
Yes, I had meant to say that too. The Table features in Filament are tied to the database, and its columns always hold only one field-type. Hence, the suggestion to use the Settings package, which allows you to create your own field-types and edit them in a dedicated form.
awcodes
awcodes15mo ago
I’d say it more about the fields ability to handle the data. But yea.
DrByte
DrByte15mo ago
Yes, you're right.
awcodes
awcodes15mo ago
No doubt, and your not wrong, but the settings package isn’t necessarily table data. Could be an alternative solution, but still not table data.
DrByte
DrByte15mo ago
True that. But I only use it with table data myself 😊
awcodes
awcodes15mo ago
Right tool for the right job, as usual.
arthurpar
arthurparOP15mo ago
Alright thank you both. I think I'm gonna use a one page form then. In my DB the column "value" is stored as a string/varchar but the reason I need sometimes a select/a checkbox is because I have settings like "enable email verification" or "weight units". I'll give it a try with the one page form, thanks for your answers.
Want results from more Discord servers?
Add your server