Giter Site home page Giter Site logo

seij-net / yagrid Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 1.29 MB

Yet another grid. A tool for building dynamic tables and grids with built-in editor and type registry. Targeted to management software.

License: BSD 3-Clause "New" or "Revised" License

TypeScript 92.35% JavaScript 6.53% CSS 0.23% Shell 0.33% MDX 0.56%

yagrid's Introduction

yagrid

Yet another grid. A tool for building dynamic tables and grids with built-in editor and type registry. Targeted to management software.

heavy development production ready

test and build

Installation

Using yarn yarn add @seij/yagrid or npm npm i @seij/yagrid.

YAGrid depends on React that shall already be installed in your project as it comes as a peer-dependency. Your React version must support hooks.

We export this component as

Typescript

  • YAGrid is build with Typescript. You get native typings. All imports shall be resolved to @seij/yagrid. Do not import from submodules event if you can reach them.

Build yourself and examples

After cloning use the classic npm install and npm run build commands to build. Build is taken care of by Rollup.

To launch the Storybook interface, use npm run storybook.

Launch npm run test for unit tests.

Known issues

  • @rollup/plugin-typescript doesn't generate Typescript definition files
  • Unfortunatly a bug with @rollup/plugin-typescript doesn't generate Typescript definition files

Datatypes

Datatypes add rendering features to types. Each grid can use a registry of data types to customize globally the rendering of known types.

It is possible to build a type registry outside the scope of a particular grid, and pass the type registry as grid properties.

You can also have as many as registries as you want and reuse them across grids of your app.

An important point is that you CAN NOT provide column definitions with types unknown by the registry of the displayed grid.

Default minimalist registry

If no type registry is given, a default one will be used with the following known types: string, boolean, int, decimal, percent. All data will render toString(). Nullish values will render as empty text.

Custom registry

To create a custom registry, use the TypesRegistryBuilder and add your types. Each type must come with a renderer that accepts the data and possiblty nullish values (null, undefined). It MUST return a string (even if empty)

Each type registred will be added to the default registry. If one of your types overlap with the default registry (like percent in following example), your type wins.

You can combine your type registry with custom renderer for columns. If a renderer had been provided for a column, it wins over the registry.

To be clear, when data must be displayed, we use the first found in this order : column renderer, custom type renderer, default type renderer.

If you ask yourself how to manage i18n issues, here we are. You get a precise control on how data is displayed. Up to you. An advice would be to have a "ready-to-go" registry at start of your app, immutable, and then pass it to all your grids. This way, your collegues won't have to be bothered about formatting in your app anymore.

 const customTypes = new TypesRegistryBuilder()
    .add("percent", data => data==null ? "" : ""+(data * 100)+"%")
    .add("monetaryAmountInt", data => ""+(data || 0))
    .add("monetaryAmountDecimal", function(data){
        return new Intl.NumberFormat(undefined, { minimumFractionDigits: 2, style: "decimal" })
            .format(data||0)
    })
    .build()

const gridProps: GridProps<S> = {
    //... other props like columns, plugins, etc.
    types: customTypes
}

 return <Grid {...gridProps} />

Note that in this example nullish data are handled differently depending on the type. This is useful in many cases. For example, on one table you don't want "0" numbers to appear, on others you want them whatever.

Provided plugins

Currently provided plugins

Name Description
item-add Provides a toolbar button to add an item. When user clicks, an editable row opens to edit the item. Provides confirm, cancel button and a temporary item to be able to cancel.
item-edit Provides row editing features. A button triggers row editing, then user can validate or cancel the row. Also manages a temporary item to be able to cancel.
item-delete Provides row button to delete item, confirm and cancel buttons.
empty-message Displays a custom empty message or component if data is empty
table-footer Displays a custom component in table footer (tfoot) area
table-classnames Using table layout, adjusts the classnames based in displayed item, column, etc.

Each plugin comes with its own documentation. Be sure to take a look at it

Plugin development

Naming

Internal plugins as well a third-party plugins shall expose a Config object and a create(cfg:Config) function.

The goal is to provide an unified naming for importing and instanciating plugins.

// Could be third party plugins
import { EditItem, DeleteItem, AddItem } from "@seij/yagrid";
// When creating the grid
const props: GridProps<ItemType> = {
    // ...
    plugins: [
        EditItem.create({ /** edit item config */ }),
        DeleteItem.create({ /** edit item config */ }),
        AddItem.create({ /** edit item config */ }),
        // ...
    ]
}
return <Grid {...props} />

yagrid's People

Contributors

jpetre avatar sebastienjust avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mcisse3007

yagrid's Issues

Setup CI

Setup CI environment (build + test)

Separate plugin state actions

At the moment actions are declared here but we need to put them separated in each plugin.

Core shall provide only core actions. Each plugin shall enrich possible actions and keep those actions local to the plugin

Generate Typescript definition files

Due to a bug in @rollup/plugin-typescript, dist/ doesn't contain Typescript definition files.
Need to be done when the problem is solved in rollup

Layout as a plugin

Layout must be a plugin.
Without layout plugin declared by user, switch to TableLayout as default layout.

Explain why we need YAGrid

Explain in a few words why we needed YAGrid, including

  • need for a style-free component
  • do not depend on any other framework than react
  • strong typing system
  • plugin architecture
  • for apps with hundreds of tables that need to be industrialized
  • editing table data as a very strong feature based on type system
  • separate view from data, especially for data rendering and editing needs
  • do not always match columns to data
  • externalized data (the component does not manage the data itself)
  • not relying on components for state management
  • better error management
  • etc.

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.