npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

draggable-table-row

v2.0.3

Published

draggable-table-row is a React component designed to add drag-and-drop functionality to table rows. This package ensures that the order of rows is preserved across page reloads and allows you to integrate additional button functionalities within the table

Downloads

34

Readme

draggable-table-row

draggable-table-row is a React component designed to add drag-and-drop functionality to table rows. This package ensures that the order of rows is preserved across page reloads and allows you to integrate additional button functionalities within the table rows.

Features

  • Drag-and-Drop: Reorder table rows easily with drag-and-drop support.
  • Persistent State: Row order is preserved across page reloads using localStorage.
  • Customizable: Integrate custom buttons and functionalities within each row.
  • Simple Integration: Easily integrate with existing React tables.
  • Drag and Drop: Optionally highlight rows while dragging with isDragAndDrop prop.

Demo

Watch the demo of the draggable table row feature below:

Watch the demo

Installation

To install the package, run the following command:

 npm install draggable-table-row

import

 import { DndProvider, HTML5Backend } from 'draggable-table-row'
import {MainTable,TableRow} from 'draggable-table-row';

Usage/Examples

main.jsx or index.js

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import { BrowserRouter } from "react-router-dom";
import { DndProvider, HTML5Backend } from 'draggable-table-row'

ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <BrowserRouter>
      <DndProvider backend={HTML5Backend}>
        <App />
      </DndProvider>
    </BrowserRouter>
  </React.StrictMode>
);


import React, { useState } from "react";
import { FaCloudDownloadAlt } from "react-icons/fa";
import {MainTable,TableRow} from 'draggable-table-row'

export const MyTable = () => {
  const [data, setData] = useState([
    { _id: "1", userName: "John Doe", email: "[email protected]", phone: "123-456-7890", address: "123 Elm St" },
    { _id: "2", userName: "Jane Smith", email: "[email protected]", phone: "987-654-3210", address: "456 Oak St" },
    { _id: "3", userName: "Alice Johnson", email: "[email protected]", phone: "555-555-5555", address: "789 Pine St" },
    { _id: "4", userName: "Bob Brown", email: "[email protected]", phone: "111-222-3333", address: "101 Maple St" }
  ]);

  // Function to render custom cells in table rows
  const renderCustomCellTbody = (item, index) => (
    <>
      <td className="px-6 py-4">{item.userName}</td>
      <td className="px-6 py-4">{item.email}</td>
      <td className="px-6 py-4">{item.phone}</td>
      <td className="px-6 py-4">{item.address}</td>
      <td className="px-6 py-4 w-[100px]">
        <button
          type="button"
          className="border border-black p-2 rounded w-[120px] flex items-center"
          onClick={() => alert(`Clicked on ${item.userName}`)}
        >
          <span className="mr-5 flex items-center mx-5">Button <FaCloudDownloadAlt className="ml-3" /></span>
        </button>
      </td>
    </>
  );

  return (
    <div className="bg-[#1f214e] sm:py-[30px] h-[100vh]">
      <div className="container">
        <MainTable
          dataLength={data?.length}
          setStateFun={setData}
          isDragAndDrop="true"
          tableDivClass={` py-[30px]`}
          tableClass="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400"
        >
          <thead className="text-xs border-t border-l border-r text-white rounded-[10px] uppercase bg-[#1f214e] dark:bg-gray-700 dark:text-gray-400">
            <tr>
              <th scope="col" className="px-6 py-3">User Name</th>
              <th scope="col" className="px-6 py-3">Email</th>
              <th scope="col" className="px-6 py-3">Phone</th>
              <th scope="col" className="px-6 py-3">Address</th>
              <th scope="col" className="px-6 py-3">Action</th>
            </tr>
          </thead>
          <tbody>
            {data?.map((item, index) => (
              <TableRow
                key={`${item._id}-${index}`}
                item={item}
                index={index}
                customeRow={renderCustomCellTbody}
                tableBodyRowClass="my-2 bg-white border-b border-gray-800 dark:bg-gray-800 dark:border-gray-700"
              />
            ))}
          </tbody>
        </MainTable>
      </div>
    </div>
  );
};