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

@beqom/data-grid

v0.0.3

Published

demo: https://beqom.github.io/data-grid/

Downloads

39

Readme

Data Grid

demo: https://beqom.github.io/data-grid/

Getting started

Install

$ npm install @beqom/data-grid --save

# or

$ yarn add @beqom/data-grid

Be sure to have all the required peer dependencies:

  • @beqom/alto-ui: ^0.3.2
  • prop-types: >=15.0.0
  • react: >=15.0.0
  • react-dom: >=15.0.0
  • react-redux: >=5.0.0
  • redux: >=3.0.0

Webpack

You need to support the scss imports of the components. you will need those loaders as devDependencies:

  • style-loader
  • css-loader
  • sass-loader

webpack.config.js

{
  module: {
    rules: [
      {
        // be sure to not exclude node modules
        test: /\.s?css$/,
        loaders: ["style-loader", "css-loader", "sass-loader"],
      },
    ],
  },
}

Redux

You need to import the reducer in your store:

reducer.js

import { reducer as DataGridReducer } from '@beqom/data-grid';
import { combineReducers } from 'redux';

export default combineReducers({
  DataGridReducer,
  // other reducers...
});

Usage

Props

tableId

PropTypes.string.isRequired

As the reducer is shared between all DataGrid instance, an unique id is needed. Could be generated randomly in the contructor of your component.

reducerName

`PropTypes.string.isRequired``

Name of the reducer you gave when you added to redux with combineReducer.

rowKey

PropTypes.string.isRequired

Column key that identify a row as unique. Often "id".

fetchData

PropTypes.func.isRequired

Function that return a promise. This promise should return the following result:

{
  // Should be wrap in Immutable.fromJS()
  groups: [
    { key: "identity", title: "Identity", },
    { key: "name", title: "Name", group: "identity" },
    { key: "address", title: "Address" },
    // ...
  ],
  // Should be wrap in Immutable.fromJS()
  columns: [
    {
      key: "firstname",
      title: "Firstname",
      order: 2,
      dataType: "string",
      layout: { visible: true, width: 120 },
      editable: false,
      formula: null,
      formatter: null,
      group: "name",
      editorType: "text"
    }
    // ...
  ],
  // Should be wrap in Immutable.fromJS()
  rows: [
    { idEmployee: "123", fistname: "Bob", /* ... */},
    // ...
  ],
  settings: {
    // optionnal
    sort: {
      columnKey: "firstname",
      way: 1, // 1: ASC, -1: DESC
    },
    // optionnal
    pagination: {
      max: 9, // number of pages
      rowsPerPage: 10,
      current: 1, // current page between 1 --> max
    } ,
  },
}

See example for mor informations.

onChangeCell

PropTypes.func.isRequired

A function that is called when the content of a cell change and might need to be push to the server. This call is already debounced.

See example for mor informations.

Example

import Immutable from 'immutable';
import { DataGrid } from '@beqom/data-grid';

const fetchData = settings => {
  const { pagination, sort } = settings;
  const url = `my-domain.com/api/employees?
    sortway${sort.way}&
    sortcolumn${sort.column}&
    currentpage${pagination.current}&
    pagesize${pagination.rowsPerPage}&
  `;

  return fetch(url)
    .then(result => ({
      columns: Immutable.fromJs(formatColumns(result.fields)),
      rows: Immutable.fromJs(result.rows),
      settings,
      groups: Immutable.fromJs(formatGroup(result.feildsParent)),
    }));
}

const handleChangeCell = ({
  key,
  value,
  rowIndex,
  row,
  rows,
  column,
  columns
}) => {
  fetch(`my-domain.com/api/employees/${key}`, {
    method: 'PUT',
    body: JSON.stringify(value),
  });
}

const EmployeeGrid = ({ id }) => (
  <DataGrid
    tableId={id}
    reducerName="DataGridReducer"
    rowKey="idEmployee"
    fetchData={fetchData}
    onChangeCell={handleChangeCell}
  />
);