column-sortable icon indicating copy to clipboard operation
column-sortable copied to clipboard

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

Open danielbachhuber opened this issue 5 years ago • 3 comments

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.

danielbachhuber avatar Nov 01 '19 20:11 danielbachhuber

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.

Kyslik avatar Nov 02 '19 11:11 Kyslik

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?

danielbachhuber avatar Nov 08 '19 12:11 danielbachhuber

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

Healyhatman avatar Oct 23 '21 15:10 Healyhatman