Use column text for sorting and filter pills if no $filterNames or $sortNames exist #286
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to define a better default value for filter/sorting pills, by giving precedence on the column text (if exists) over the column name of the model
let's see a use case: in non-english languages db column names often differs from what's displayed to the user, and this is greatly handled by laravel-livewire-tables:
but, for filtering and sorting I obtain this:
that's to say the human readable db column name:
ucwords(strtr('first_name', ['_' => ' ', '-' => ' '])) // First Name
but, usually, I want the filter pills labels to be equal to the displayed column name:
I know this could solved by defining
$filterNames
and$sortNames
properties, but that's kinda redundant.. as my labels are already written in columns definitionsso I think we can create a "pills label" priority such as
$sortNames[$col]
> Column Text > Human Readable Db Columnthis can be obtained by changing this:
to this:
hope to have well explained the issue and the solution I'm trying to propose
a better solution would be extracting this logic in a method of
WithFilter
andWithSorting
traits, but did not want to change so many lines without your opinion about thisas usual, thumbs up for your great work!