solid-dnd icon indicating copy to clipboard operation
solid-dnd copied to clipboard

Attempt at Row DnD implementation on @tanstack/solid-table

Open Koning3ton opened this issue 11 months ago • 1 comments

Hello,

Thanks for this great library! I'm trying to implement the Row DnD example for React for the SolidJS version.

Below my current implementation can be found. Feedback always welcome!

Code can be found on StackBlitz.

I also include the DraggableRow implementation of my code example here for completeness:

import { flexRender } from '@tanstack/solid-table';
import {
  createSortable,
  useDragDropContext,
  transformStyle,
} from '@thisbeyond/solid-dnd';

// Row Component shown when row is dragged
const DraggableRow = ({ row, className }: { row: any; className?: string }) => {
  const sortable = createSortable(row.original.id);
  const context = useDragDropContext();
  const state = context && context[0];

  return (
    <tr
      ref={sortable.ref}
      class={className}
      style={transformStyle(sortable.transform)}
      classList={{
        'opacity-25': sortable.isActiveDraggable,
        'transition-transform': !!state?.active.overlay,
      }}
    >
      {row.getVisibleCells().map((cell: any, idx: number) =>
        cell.column.id == 'drag-handle' ? ( // Only the Drag handle should allow the row to be dragged.
          <td
            {...sortable.dragActivators}
            class="border border-border"
            style={{ height: '1px', width: cell.column.getSize() + 'px' }}
          >
            {flexRender(cell.column.columnDef.cell, cell.getContext())}
          </td>
        ) : (
          <td
            class="border border-border"
            style={{ height: '1px', width: cell.column.getSize() + 'px' }}
          >
            {flexRender(cell.column.columnDef.cell, cell.getContext())}
          </td>
        )
      )}
    </tr>
  );
};
export default DraggableRow;

Koning3ton avatar Jan 19 '25 19:01 Koning3ton

Thank you for sharing, your example helped a lot!

Terbiy avatar Mar 27 '25 15:03 Terbiy