laravel-views
laravel-views copied to clipboard
Customizable No Results Message
Hey there,
It would be great if we could easily provide a custom Empty data message. Right now, the default one of There are no items in this table is a bit generic. People may not want a message at all for example.
I realize we can customize table-view.table-view.blade.php, but it seems a bit overkill to me: https://github.com/Gustavinho/laravel-views/blob/master/resources/views/table-view/table-view.blade.php
Would something like this make sense?
class UsersTableView extends TableView
{
protected $noResultsMessage = '<div class="flex justify-center items-center p-4">No Users Found</div>';
...
Hi @df999 sorry for the delayed response, I like your idea, I was thinking of using translation strings as keys to customize all the messages, however, with this solution, it wouldn't be possible to customize the message per view, or the look and feel for the message as it would be possible using a solution like you're suggesting, what do you think?
Hey @Gustavinho - yeah that would be an easy solution.
Is a more flexible solution as simple as something like this though?
@if (isset($this->noResultsMessage))
{{ $this->noResultsMessage }}
@else
<div class="flex justify-center items-center p-4">
<h1>{{ __('global.no_results_found') }} </h1>
</div>
@endif
It would have to be public, not protected though:
public $noResultsMessage = 'No results found';
Hi @df999 I was thinking about this, I will add the $noResultsMessage
public property to customize the message by a view, but also a $noResultsComponent
to fully customize the blade component to be displayed, in case we want to add a nicer message with images or links or what we need specifically.
Okay cool - that sounds great!