Kyslik / column-sortable

Package for handling column sorting in Laravel 5/6/7/8
MIT License
644 stars 105 forks source link

Disable link from sortableLink() when there aren't any entries #136

Open danielbachhuber opened 4 years ago

danielbachhuber commented 4 years ago

If the collection doesn't contain any entries, it would be nice if sortableLink() only displayed the title, and didn't render a link.

Happy to submit a pull request if you can provide some direction. My code has a bunch of ugly conditionals right now.

Kyslik commented 4 years ago

Could you please elaborate a bit more and provide an example?

Yea all PRs are welcome. Most likely you want to take a look at https://github.com/Kyslik/column-sortable/blob/L6/src/ColumnSortable/SortableLink.php#L21 function and do some shenanigans there.

danielbachhuber commented 4 years ago

Sorry for the late reply here.

Could you please elaborate a bit more and provide an example?

Sure. Here's my sortable table that has entries:

image

When there are no results on the table, I'd expect the table headings to render as, say, spans instead of links:

image

Most likely you want to take a look at https://github.com/Kyslik/column-sortable/blob/L6/src/ColumnSortable/SortableLink.php#L21 function and do some shenanigans there.

It looks like SortableLink doesn't have any knowledge of the result set it's sorting, which I suppose makes sense.

The simplest approach would be to add a new parameter, and make it the responsibility of the caller to determine whether the SortableLink should render. I don't love this though. Can you think of a more elegant approach?

Healyhatman commented 3 years ago

@if($collection->isNotEmpty()) @sortablelink() @else just text @endif