laravel-views icon indicating copy to clipboard operation
laravel-views copied to clipboard

Customizable No Results Message

Open df999 opened this issue 3 years ago • 4 comments

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>';
    ...

df999 avatar Jun 10 '21 21:06 df999

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?

Gustavinho avatar Jun 14 '21 14:06 Gustavinho

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';

df999 avatar Jun 14 '21 15:06 df999

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.

Gustavinho avatar Jun 21 '21 03:06 Gustavinho

Okay cool - that sounds great!

df999 avatar Jun 21 '21 11:06 df999