Git Product home page Git Product logo

payload-table-field's Introduction

Payload Table Field

Adds a table field (using React Table) to Payload.

Features:

  • Display / Edit data using React Table
  • Pagination
  • Sorting
  • Row Selection

image

Installation

  yarn add payload-table-field
  #OR
  npm i payload-table-field

Basic Usage

Import the field and then use it in your payload collection fields array.

// import plugin
import { CollectionConfig, Field } from 'payload/types'
import { tableField } from 'payload-table-field'

import mockData from '../mocks/mockData'

const Examples: CollectionConfig = {
  slug: 'examples',
  admin: {
    useAsTitle: 'title',
  },
  fields: [
    {
      type: 'text',
      name: 'title',
    },
    tableField(
      {
        name: 'table_example',
        label: 'Example Table - Movies',
        defaultValue: mockData,
      },
      {
        pagination: true, // Enable pagination?
        paginationPageSize: 10, // Default pagination page size
        paginationPageSizes: [5, 10, 25, 50, 100], // Available pagination page sizes
        editable: false, // Allow cells to be edited?
        rowSelection: true, // Enable row selection
        columns: [
          {
            key: 'id',
            name: 'ID',
            enableSorting: true // Allow this column to be sorted
          },
          { key: 'title', name: 'Title' },
          { key: 'year', name: 'Year' },
        ],
      },
    ) as Field,
  ],
}

export default Examples

Note

While this plugin is still in development, the basic feature set of React Table has been implemented.

payload-table-field's People

Contributors

notchris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

payload-table-field's Issues

SyntaxError: Cannot use import statement outside a module

Hello!

Wanted to use this plugin, but I can't get it running.

Using it like this:

import { tableField } from "payload-table-field";
import { type Block } from "payload/types";

export const TableBlock: Block = {
  slug: "Table",
  interfaceName: "TableBlock",
  fields: [
    {
      name: "items",
      type: "array",
      required: true,
      fields: [
        tableField(
          {
            name: "table",
            label: "Table",
          },
          {
            pagination: true,
            paginationPageSize: 10,
            paginationPageSizes: [5, 10, 25, 50, 100],
            editable: false,
            rowSelection: true,
            columns: [
              {
                key: "id",
                name: "ID",
                enableSorting: true,
              },
              { key: "title", name: "Title" },
              { key: "year", name: "Year" },
            ],
          },
        ),
      ],
    },
  ],
};

but getting this error:

/Users/user/dev/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/payload-table-field/src/index.ts:1
import { Field, JSONField } from 'payload/dist/exports/types'
^^^^^^
@nextgen/cms:dev:
SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/user/dev/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]/node_modules/ts-node/src/index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/Users/user/dev/apps/cms/src/blocks/Table.ts:11:26)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.