New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: selectable table columns #1693
feature: selectable table columns #1693
Conversation
Regarding storage of selected/visible columns, I'd opt for I'd prefer to see a table-level flag that makes columns selectable, as well as the method on the column that can be used to disable the functionality for that particular column. The inverse of what you have now basically. |
I think the behavior is like a toggle to enable/disable or show/hidden. for me "selectability" refers to another type of action other than showing/hiding something. I like the option of having a table-level method to enable the function globally and two column-level methods to change the default display and disable the feature. |
Toggleable doesn't roll of the tongue... |
Ok so let's think through the DX, if we flip this to a table-level flag. $table
->columns(...)
->filters(...)
->selectable() // Is this what we want to see?
My thinking is that by making the table Perhaps the public function selectable(int $initiallySelected = 1) As for the individual column option, perhaps... Tables\Columns\TextColumn::make('name')->alwaysSelected(),
Tables\Columns\TextColumn::make('email')->selected(),
Tables\Columns\TextColumn::make('phone') Adding Thoughts? |
Agree. I just use word "toggle" for enable/disable something Example $table->enableColumnToggle(bool | Closure)
$column->canToggle(bool | Closure)
$column->defaultToggleState(bool | Closure) |
Ok this has been significantly reworked, based on my comment yesterday. The simplest way to make use of the new column selection is to add the $table
->columns(...)
->filters(...)
->selectable(); By default, this will auto-select the first column in the table, and hide the rest. You can pass in an integer to this method to change the default number of columns selected. You can also control selection on an individual column if you want. Two methods are available: Tables\Columns\TextColumn::make('name')->alwaysSelected(),
Tables\Columns\TextColumn::make('email')->selected(),
Tables\Columns\TextColumn::make('phone') The Note: if you explicitly set selection on any individual columns, the table-level @dmandrade While I still have mixed feelings about the 'selectable' verbiage, I want to try and keep to a terse term if possible, rather than multi-word methods like @ryangjchandler Most of the code you commented on has now changed, feel free to re-visit. However, before getting too detailed with the code specifics, I'd like to hear your thoughts on this updated API and whether you like the high-level approach. I still haven't focused much on closure arguments and such, wanting to get the big picture in place first. |
Hey, I've just had a chance to review this and quickly fix some formatting things. Overall, its great, you're definitely on the right track. However. I dont think the term "select" or "selectable" is suitable here. Since that could easily get confused with selecting rows that we used for bulk actions. I'm not sure of an alternative though... tbh I think I prefer "toggleable" but I'm open to other suggestions. Maybe Also, persistence of toggled columns between page reloads didn't seem to work for me, not sure if its a bug or you haven't thought about it yet. |
Could you use Visible? Then you could have toggleVisibility() and alwaysVisible(). |
I think |
Anything I can do to help get this PR merged? I would love to use this feature in a current project |
Not sure if @jszobody wants us to take over or not, he's probably very busy. If you're interested though, you could maybe clone his branch and rename any terminology from "select" to "toggleVisibility". Might require quite a few changes but all of the real work to get the feature working has been done. |
Sorry folks, yes I've been out of town lately and too busy to revisit this. I won't be able to put much effort in until after next week. There are a few open questions in my mind that perhaps @danharrin can help clarify for me.
|
Hey, yes there is a IMO, the API should just be on the columns and not My proposal is: $condition // if the column should be toggleable
Column::make()->toggleable(bool $condition = true, bool $isVisibleByDefault = true) then you could use With regards to implementing persistence - lets stick to sessions for now. We use that in other areas, like storing the pagination settings. |
5e598aa
to
c3dad48
Compare
4d8a31d
to
4a0c728
Compare
It's actually perfect, it looks like I just made tons of comments but I just added |
@danharrin Sweet, will sort these tomorrow. 🎉 |
0db0011
to
9558933
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me now.
And it all works with the new changes? |
@danharrin Yeah, all good still. Just tested :) |
Just pulled this down for testing, looks like the columns are visible oppositely to what their checkbox says? When the table first load, the columns should be hidden / visible based on Screen.Recording.2022-04-19.at.13.49.24.mov |
Oh yeah, I've been thinking of this the wrong way. Just need to invert the |
Actually, I'm not sure now... to me you're toggling the column so the checkbox being checked is almost indicating that you've toggled it. Happy either way though! |
"Toggling" to me sounds like the process of showing/hiding the column, not an indication of whether the column is visible or not. To me, I think it makes more sense if checked = visible, as on the original video #1693 (comment) |
Yeah, cool. I can change that in a bit. |
I do @saade |
This is a first rough stab at adding column selection to tables. This is what it looks like:
To make a column selectable, add
->selectable()
when defining a column. If any columns in a table are selectable, the action icon appears on the table.I very closely followed the way filters are implemented, copied and pasted quite a bit of that code.
I'm looking for input on a number of items:
ColumnSelection
andCanBeSelectable
andisColumnSelectionVisible
and I'm really not sure these are well named. Is there a better single-word term for this "column selectability" behavior anyone can think of?->selectable()
it is hidden by default until you select it. Need a way to also indicate that it should default to visible, thoughts on a good method name for that?tables::table.buttons.filter.label
which obviously will need to change.Feedback welcome. =)