Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Nullable table row url #2110

Open
leesherwood opened this issue Dec 3, 2024 · 2 comments
Open

[Feature Request]: Nullable table row url #2110

leesherwood opened this issue Dec 3, 2024 · 2 comments

Comments

@leesherwood
Copy link

leesherwood commented Dec 3, 2024

Overview

Allow setting whether a table row has a clickable URL on a per-row basis

Detailed explanation

I have a table that lists a Document model which has a status of pending or accepted. Only accepted documents have a public URL you can click through too.

So I added this:

->setTableRowUrl(fn($row) => $row->status === 'accepted' ? route("account.documents.show", $row) : null)

This works, albeit with a some unneccessary markup in the HTML

<td .... onclick="window.open('', '_self')" .... >

but I also want to change the cursor, I don't want it to change to a pointer for null URLs. Ideally i'd have a not allowed cursor. I tried this:

->setTrAttributes(fn($row) => ['class' => $row->status !== 'accepted'? 'cursor-not-allowed' : ''])

but this outputs the following class list:

cursor-pointer .... rappasoft-striped-row cursor-not-allowed

Because:

->class(['cursor-pointer' => ($isTailwind && $this->hasTableRowUrl() && ($customAttributes['default'] ?? true))])

public function hasTableRowUrl(): bool
{
return isset($this->trUrlCallback);
}
public function getTableRowUrl(int|Model $row): ?string
{
return isset($this->trUrlCallback) ? call_user_func($this->trUrlCallback, $row) : null;
}

Notes

I propose that:

public function hasTableRowUrl(): bool
    {
        return isset($this->trUrlCallback);
    }

Is changed too:

public function hasTableRowUrl(int|Model $row): bool
    {
        return $this->getTableRowUrl($row) !== null;
    }
@leesherwood
Copy link
Author

Should this change (or similar) not make it into the library, and someone stumble's across this, you can do the following to make it work.

->setTrAttributes(fn($row, $rowIndex) => [
    'default' => false,
    'class' => implode(' ', [
        'dark:text-white', 
        ($rowIndex % 2 === 0 ? 'bg-white dark:bg-gray-700' : 'bg-gray-50 dark:bg-gray-800'), 
        ($row->status !== 'approved' ? 'cursor-not-allowed italic text-gray-400': 'cursor-pointer')])
     ]
)

Just means pulling the default style classes into your own code and disabling them from auto-applying.

Not as elegant but it works.

@lrljoe
Copy link
Collaborator

lrljoe commented Dec 3, 2024

Leave this one with me, what you're saying makes sense, but I need to validate any other impact.

Given the propensity for people to publish the package views, it may be that a new method needs to be added to support this, while maintaining the current behaviour on the existing method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants