Skip to content
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

Added trim functionality to Text Column #152

Merged
merged 3 commits into from
Mar 10, 2021
Merged

Added trim functionality to Text Column #152

merged 3 commits into from
Mar 10, 2021

Conversation

jamessessford
Copy link
Contributor

Morning folks,

TLDR: Added trim functionality to Text Column

I found that I was using the getValueUsing callback a lot of the time just to trim the length of the content but if I did this I lost the ability to search or sort on that field.

I've added a trim helper to the Text column that takes a trim length and then trims the value after it's been taken from the record.

Example usage:

Columns\Text::make('reference')->primary()->searchable()->sortable()->trim(6),

This allows me to only show the first six characters of the reference in the table but retain search and sort functionality.

Cheers!

@danharrin
Copy link
Member

Hey James! This sounds like a job for formatUsing rather than getValueUsing. We should use the trim() method to set that callback, similar to date(). Let me know how that goes.

@danharrin danharrin added enhancement New feature or request pending changes labels Mar 10, 2021
@ryangjchandler
Copy link
Member

I think this method should probably be called truncate or limit, since PHP's trim function is for removing characters at each end, not actually limiting the length of a string.

@jamessessford
Copy link
Contributor Author

Totally agreed @ryangjchandler - Updating now

Changed function to use formatUsing
@jamessessford
Copy link
Contributor Author

I've changed the function to limit rather than trim (that was the str helper it's piggybacking) and updated to use formatUsing rather than getValueUsing.

Cheers!

@danharrin danharrin merged commit c5259e2 into filamentphp:develop Mar 10, 2021
@jamessessford jamessessford deleted the trim-text branch March 10, 2021 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants