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

@lifespikes/next-datatable

v1.6.0

Published

Datatable made with Shadcn, which can support server-side pagination and can synchronize its state with the url

Downloads

847

Readme

next-datatable

next-datatable is a library created using Shadcn, react-table, and nuqs. The goal is to provide a data table with the ability to have a simple API thanks to the support of react-table, a user-friendly interface using Shadcn, and the capability to automatically save its state in the URL with nuqs.

Usage

Let's define some columns

import { ColumnDef } from '@tanstack/react-table';


export const columns: ColumnDef<any>[] = [
  {
    id: 'select',
    header: ({ table }) => (
      <CheckboxPrimitive
        checked={table.getIsAllPageRowsSelected()}
        onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
        aria-label="Select all"
      />
    ),
    cell: ({ row }) => (
      <CheckboxPrimitive
        className="border-gray-400 data-[state=checked]:border-white"
        checked={row.getIsSelected()}
        onCheckedChange={(value) => row.toggleSelected(!!value)}
        aria-label="Select row"
      />
    ),
    enableSorting: false,
    enableHiding: false
  },
  {
    accessorKey: 'name',
    header: 'Name',
    cell: ({ row }) => (
      <div className="flex space-x-2 text-primary">
        <File className="h-4 w-4" />
        <span>{row.getValue('name')}</span>
      </div>
    )
  },
  {
    accessorKey: 'status',
    header: 'Status'
  },
  {
    id: 'actions',
    enableHiding: false,
    cell: ({ row }) => {
      return (
        <Button size="icon">
          <DownloadCloud className="h-4 w-4" />
        </Button>
      );
    }
  }
];

And let's use our datatable as follows

import { NextDataTable } from '@lifespikes/next-datatable';

const UsersTable = () => {
  const { data } = useGetUsers(); // Fetching data.


  return <NextDataTable data={data} columns={columns} />;
};

How can I use the pagination values to make a query?

You need to use the hook useGetNextTableState. For example:

import { NextDataTable, useGetNextTableState } from '@lifespikes/next-datatable';

const UsersTable = () => {

  const { pagination } = useGetNextTableState(); // get state from url

  const { data } = useGetUsers({
    page: pagination.pageIndex + 1,
    perPage: pagination.pageSize
  }); // Fetching data.


  return (
    <NextDataTable
      data={data}
      pageCount={data?.totalPages}
      defaultValues={{
        pagination: {
          pageIndex: data?.page - 1,
          pageSize: 10
        }
      }}
      columns={columns}
    />
  );
};

Check this example app

Example Video

https://github.com/lifespikes/packages/assets/67383906/7e2f5902-61e0-4676-af2e-7215d139abd8