shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
58.62k stars 3.2k forks source link

[feat]: DataTable Columns (ColumnDef) doesn't support passing of any state/functions #3608

Open sagar-jani opened 2 weeks ago

sagar-jani commented 2 weeks ago

Feature description

I have actions in data-table - copy, I want to show different icon to user when user clicked on the action. However i can't define any state inside columns.

Here is what I want to do

  const copyToClipboard = async () => {
    try {
      await navigator.clipboard.writeText(loan.accountno);
      setIsCopied(true);
      setTimeout(() => setIsCopied(false), 2000);
    } catch (err) {
      console.error('Failed to copy text: ', err);
    }
  };

    <DropdownMenuItem className="cursor-pointer" onClick={copyToClipboard}>
      {isCopied ? (
        <CopyCheckIcon className="h-4 w-4" />
      ) : (
        <CopyIcon className="h-4 w-4" />
      )}
      Copy
    </DropdownMenuItem>

Affected component/components

No response

Additional Context

Additional details here...

Before submitting