robsontenorio / mary

Laravel Blade UI Components for Livewire 3
https://mary-ui.com
Other
965 stars 114 forks source link

custom formating for fields in table ? #639

Closed sergeynilov closed 8 hours ago

sergeynilov commented 10 hours ago

In laravel 11 / livewire 3 app I added "robsontenorio/mary": "^1.35" and reading docs at https://mary-ui.com/docs/components/table and trying to use it I did not find : a) how can set custom formating for fields like enum datetime ? Sure, reading data in request on server side I can make map and set custom formating for any field I need, but as I use these fields in sorting and field value and custom formating of the field can be different - I would like not to make such mapping. Any decision ?

b) I need to show first 20 chars of long text field. Again I can cut the text at server side, but can I show the all text in some kind of hint/popover/separate modal to show all text?

anfeichtinger commented 9 hours ago

You can overwrite the content of each cell how you want it to be with @scope. Here is an example from the docs.

@php
    $users = App\Models\User::with('city')->take(3)->get();

    $headers = [
        ['key' => 'name', 'label' => 'Nice Name'],
    ];
@endphp

<x-table :headers="$headers" :rows="$users">
    @scope('cell_name', $user)
        ({{  $loop->index }}) {{ $user->name }}
    @endscope
</x-table>

You can use this to trim your text, add a tooltip, format your DateTime etc. Anything missing?

sergeynilov commented 8 hours ago

Thanks!