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

quiksa-table

v1.0.4

Published

An advanced table component for React.

Downloads

374

Readme

Contributors Forks Stargazers Issues MIT License LinkedIn

About The Project

Product Name Screen Shot

QuiksaTable is a highly customizable and responsive table component designed for Next.js projects. Built with React and Tailwind CSS, it offers features like sorting, filtering, pagination, row selection, and inline editing to provide a seamless data management experience.

Features

  • Responsive Design: Ensures the table looks great on all screen sizes.
  • Sorting: Clickable headers to sort data ascending or descending.
  • Filtering: Global and column-specific filtering options.
  • Pagination: Navigate through data with ease.
  • Row Selection: Select individual or all rows.
  • Inline Editing: Edit cell data directly within the table.
  • Custom Actions: Add custom action buttons for each row.
  • Theming: Easily customize the table's appearance using Tailwind CSS.

Installation

To install QuiksaTable, you can use npm or yarn:

# Using npm
npm i quiksa-table

# Using yarn
yarn add quiksa-table

Usage

Basic Usage

Here's how you can integrate QuiksaTable into your Next.js project:

import React from "react";
import QuiksaTable from "quiksatable";

interface Page {
  id: number;
  name: string;
  author: string;
  slug: string;
  status: string;
  created_at: string;
}

const columns = [
  {
    header: "Name",
    accessor: "name",
    filterable: true,
    sortable: true,
    editable: true,
    editorType: "text",
  },
  {
    header: "Author",
    accessor: "author",
    filterable: true,
    sortable: true,
    editable: false,
  },
  {
    header: "Slug",
    accessor: "slug",
    filterable: true,
    sortable: true,
    editable: false,
  },
  {
    header: "Status",
    accessor: "status",
    filterable: true,
    sortable: true,
    editable: true,
    editorType: "select",
    editorOptions: [
      { label: "Published", value: "published" },
      { label: "Draft", value: "draft" },
      { label: "Inactive", value: "inactive" },
    ],
    formatter: (value: string) => {
      const statusColors: Record<string, string> = {
        published: "bg-green-100 text-green-800",
        draft: "bg-yellow-100 text-yellow-800",
        inactive: "bg-red-100 text-red-800",
      };
      return (
        <span className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${statusColors[value]}`}>
          {value}
        </span>
      );
    },
  },
  {
    header: "Created",
    accessor: "created_at",
    filterable: true,
    sortable: true,
  },
];

const actions = [
  {
    label: "Show",
    onClick: (row: Page) => alert(`Showing details for ${row.name}`),
    className: "text-indigo-600 hover:text-indigo-900 focus:outline-none focus:underline",
  },
];

const data: Page[] = [
  {
    id: 1,
    name: "Home",
    author: "John Doe",
    slug: "home",
    status: "published",
    created_at: "2023-01-01",
  },
  {
    id: 2,
    name: "About",
    author: "Jane Smith",
    slug: "about",
    status: "draft",
    created_at: "2023-02-15",
  },
  {
    id: 3,
    name: "Contact",
    author: "Mike Johnson",
    slug: "contact",
    status: "inactive",
    created_at: "2023-03-10",
  },
];

const fetchData = async (params: any) => {
  // Replace with your data fetching logic
  return new Promise<{ data: Page[]; totalPages: number }>((resolve) => {
    setTimeout(() => {
      resolve({ data, totalPages: 1 });
    }, 1000);
  });
};

const handleCellUpdate = async (rowKeyValue: number, columnKey: keyof Page, newValue: any) => {
  // Handle cell update logic
  console.log(`Updating row ${rowKeyValue}, column ${columnKey} with value ${newValue}`);
};

const PageTable: React.FC = () => {
  return (
    <QuiksaTable<Page, "id">
      columns={columns}
      data={data}
      fetchData={fetchData}
      sortable
      filterable
      pageable
      itemsPerPage={5}
      initialSortConfig={{ key: "name", direction: "ascending" }}
      actions={actions}
      rowKey="id"
      selectable
      onSelectionChange={(isAllSelected, selectedRowKeys) => {
        console.log("All Selected:", isAllSelected);
        console.log("Selected Rows:", Array.from(selectedRowKeys));
      }}
      onCellUpdate={handleCellUpdate}
    />
  );
};

export default PageTable;

Customization

You can customize the table's appearance and behavior using the theme prop and by modifying the columns configuration.

Props

QuiksaTable accepts the following props:

| Prop | Type | Description | | ---------------------- | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | columns | Column<T>[] | Array of column definitions. | | data | T[] | Data to be displayed in the table. | | fetchData | (params: any) => Promise<any> | Function to fetch data for server-side rendering. | | sortable | boolean | Enables or disables sorting functionality. | | filterable | boolean | Enables or disables filtering functionality. | | pageable | boolean | Enables or disables pagination. | | itemsPerPage | number | Number of items to display per page. | | initialSortConfig | SortConfig<T> \| null | Initial sort configuration. | | actions | Action<T>[] | Array of action buttons to display in each row. | | customHeaderComponent| React.ReactNode | Custom component to display in the table header. | | rowKey | K | Unique key to identify each row. | | selectable | boolean | Enables or disables row selection. | | onSelectionChange | (isAllSelected: boolean, selectedRowKeys: Set<T[K]>) => void | Callback function when row selection changes. | | onCellUpdate | (rowKeyValue: T[K], columnKey: keyof T, newValue: any) => Promise<void> | Callback function when a cell is updated. | | theme | QuiksaTableTheme | Custom theme configuration for the table. |

Column Definitions

Each column can have the following properties:

| Property | Type | Description | | --------------- | ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- | | header | string | Display name of the column. | | accessor | K | Key to access the corresponding data in the row. | | filterable | boolean | Enables or disables filtering for the column. | | sortable | boolean | Enables or disables sorting for the column. | | editable | boolean | Enables or disables inline editing for the column. | | editorType | EditorType | Type of editor to use for inline editing (text, number, select, date). | | editorOptions | Array<{ label: string; value: any }> | Options for select editors. | | formatter | (value: any) => React.ReactNode | Function to format the display of the cell's value. | | filterType | FilterType | Type of filter to use (text, number, select, date). | | filterOptions | Array<{ label: string; value: any }> | Options for select filters. |

Examples

Inline Editing

Enable inline editing for specific columns by setting editable to true and specifying the editorType.

const columns = [
  {
    header: "Name",
    accessor: "name",
    editable: true,
    editorType: "text",
  },
  // ...other columns
];

Custom Actions

Add custom action buttons to each row.

const actions = [
  {
    label: "Show",
    onClick: (row: Page) => alert(`Showing details for ${row.name}`),
    className: "text-indigo-600 hover:text-indigo-900 focus:outline-none focus:underline",
  },
];

Theming

Customize the table's appearance using the theme prop. You can override default styles by providing your own styles.

  • Ensure you have Tailwind CSS set up in your Next.js project. If not, follow the official Tailwind CSS installation guide.

Customize the table's appearance using the theme prop. You can override default styles by providing your own styles.

const customTheme: QuiksaTableTheme = {
  tableClassName: "min-w-full divide-y divide-gray-200",
  headerClassName: "bg-indigo-50",
  // ...other theme properties
};

<QuiksaTable
  // ...other props
  theme={customTheme}
/>

Server-Side Data Fetching

For large datasets, utilize server-side data fetching by providing the fetchData prop.

const fetchData = async (params: any) => {
  const response = await fetch(`/api/data?page=${params.page}&limit=${params.itemsPerPage}`);
  const result = await response.json();
  return { data: result.data, totalPages: result.totalPages };
};

<QuiksaTable
  // ...other props
  fetchData={fetchData}
/>

Contributing

Contributions are welcome! Please follow these steps:

  • Fork the repository.
  • Create a new branch (git checkout -b feature/YourFeature).
  • Commit your changes (git commit -am 'Add some feature').
  • Push to the branch (git push origin feature/YourFeature).
  • Open a pull request.

Contact

Alper Dursun - @github - [email protected]