rrg

react-redux-grid

A React Grid/Tree Component written in the Redux Pattern

Showing:

Popularity

Downloads/wk

396

GitHub Stars

453

Maintenance

Last Commit

1yr ago

Contributors

27

Package

Dependencies

7

Size (min+gzip)

87.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

React-Redux Grid

npm version Build Status Dependency Status npm codecov Gitter bitHound Dependencies bitHound Overall Score Scrutinizer Code Quality Average time to resolve an issue Percentage of issues still open PRs Welcome

A Grid and Tree Component written in React using the Redux Pattern with plenty of open source examples, and an interesting backstory.

React Redux Grid

Features

  • Flat List or Tree Structure ➖ 🌲
  • Local and/or Remote Data Source
  • Local and/or Remote Pagination
  • Extensive Column Definitions 💪
  • Draggable Column Width/Resizing
  • Draggable Column Ordering
  • Sortable Columns
  • Grid Action Menus
  • Bulk Action Toolbar
  • Selection Model (Single, MultiSelect, Checkbox)
  • Event Handling for all kinds of DOM Events (List Below)
  • Extendable and Modular Style Built with JavaScript :bowtie:
  • Loading Mask
  • Built-in Error Handling Module
  • Handles Huge amount of Records (1000000+) ⭐

Installation

$ npm install react-redux-grid --save

If you would like to build and run the demo in your browser:

$ git clone https://github.com/bencripps/react-redux-grid.git
$ cd react-redux-grid
$ npm install
$ npm run start

Open your browser to: http://localhost:3000

Examples

Examples Github

Usage

import React from 'react';
import { render } from 'react-dom';
import { Grid } from 'react-redux-grid';

render(
    <Grid
        data={data}
        stateKey={stateKey}
    />,
    document.getElementById('grid-mount')
);

Documentation

FAQ

Grid Level Parameters

PropTypeDescription
statefulboolthe grid will store column configuration in browser local storage (based off of stateKey, so the key must be unique across all grids in a single application)
heightoneOfType([number, string, bool])the height of the grid container, if false, then no height will be set
stateKeystringunique id for grid, more information available
showTreeRootNodeboolused with tree-grid, to determine if root node should be displayed
classNamesarraya list of strings to be applied to the grid container as classes
eventsobjectgrid event object, more information below
reducerKeysobjectobject describing custom named reducers, more information below
pageSizeintnumber of records to shown on a single grid page
emptyDataMessageanycan be a string or a react component, which will be displayed if no grid data is available
dragAndDropboolwhether drag and drop of rows should be enabled
gridTypeoneOf(['grid', 'tree'])whether the grid will be a flat list or a tree view
dataarrayOf(object)local data for grid to display, more information available
dataSourcefuncfunction which returns data to display, more information available
filterFieldsobjectoptional object describing additional values to filter grid data

Columns

export const columns = [
    {
        name: 'Name',
        dataIndex: 'name',
        editor: '<input type="text" required />',
        width: '10%',
        className: 'additional-class',
        renderer: ({ column, value, row }) => (
            <span> Name: { value } </span>
        ),
        hidden: false,
        placeholder: 'Name',
        validator: ({ value, values }) => value.length > 0,
        change: ({ values }) => ({
            otherColDataIndex: 'newValue'
        }),
        editable: ({ value, values }) => {
            if (value === 'ShouldDisabled') {
                return true;
            }
            return false;
        },
        hideable: false,
        resizable: false,
        moveable: false,
        HANDLE_CLICK: () => { console.log('Header Click'); },
        createKeyFrom: true
    }
];
PropTypeDescription
namestringtitle of column to be displayed
dataIndexoneOfType([string, array])the key accessor for the column value (required parameter). more information available
editorjsxwhen an editor is used, this element will be rendered in place of the edited cell, more information available
widthintwidth of column (if none is provided, a default width will be applied)
classNamearrayadditional class names to apply to header of this column
rendererfunca function which returns the cell contents for this column, more information available
hiddenboolwhether the column is hidden or visible
hideableboolwhether the column can be hidden
moveableboolwhether this column can be moved
placeholderstringthe placeholder that will be used for the editor input
validatorfunca func that should return a boolean, to determine if the newly input value is valid
changefunca func that should return an object where keys are the dataIndex of affected columns, and the values will be the new values associated with that dataIndex.
editableoneOfType([func, bool])whether the field should be disabled while in edit mode.
createKeyFromboolsee full documentation on createKeyFrom
sortFnfuncwhen a local sort action occurs, you can provide a method that will be passed to sort

Editor

export const plugins = {
    EDITOR: {
        type: 'inline',
        enabled: true,
        focusOnEdit: true
    }
}
PropTypeDescription
typeoneOf(['inline', 'grid'])two editors are available by default. in grid mode, all fields are editable. in inline mode, only a single line is editable at a time
enabledboolif true, the grid will have an editor available
focusOnEditboolfocus the first editable input when an edit event occurs (defaults to true)

Column Manager

export const plugins = {
    COLUMN_MANAGER: {
        resizable: false
        defaultColumnWidth: `${100 / columns.length}%`,
        minColumnWidth: 10,
        moveable: true,
        headerActionItemBuilder: () => {},
        sortable: {
            enabled: true,
            method: 'local',
            sortingSource: 'http://url/to/sortingSource'
        }
    }
}
PropTypeDescription
resizableboolwill set all columns to resizable. This parameter will not override columns that have declared they are not resizable from the columns array
defaultColumnWidthintif no column width is provided, columns will be divided equally. this can be overwritten by providing a new string template
minColumnWidthintthe minimum width a column can be dragged to
moveableboolwhether the columns can be reordered by drag
headerActionItemBuilderfuncbuild a custom jsx component to be used as the header action items
sortableobjectan object that describes whether columns can be sorted
sortable.enabledboolan object that describes whether columns can be sorted
sortable.methodoneOf(['local', 'remote'])whether sorting will execute locally, or remotely
sortable.sortingSourcestringwhere sorting data will be retrieved (a required parameter for remote sorting)

Pagination

export const plugins = {
    PAGER: {
        enabled: true,
        pagingType: 'remote',
        toolbarRenderer: (pageIndex, pageSize, total, currentRecords, recordType) => {
            return `${pageIndex * pageSize} through ${pageIndex * pageSize + currentRecords} of ${total} ${recordType} Displayed`;
        },
        pagerComponent: false
    }
};
PropTypeDescription
enabledboolwhether a pager will be used, defaults to true
pagingTypeoneOf(['local', 'remote'])defaults to local
toolbarRendererfunca function which which returns the description of the current pager state, ex: 'Viewing Records 10 of 100'
pagerComponentjsxif you'd like to pass your own pager in, you can supply a jsx element which will replace the pager entirely

Grid Actions

export const plugins = {
    GRID_ACTIONS: {
        iconCls: 'action-icon',
        onMenuShow: ({ columns, rowData }) => {

            console.log('This event fires before menushow');

            if (rowData.isDisabled) {
                return ['menu-item-key'] // this field will now be disabled
            }

        },
        menu: [
            {
                text: 'Menu Item',
                key: 'menu-item-key',
                EVENT_HANDLER: () => {
                    alert('Im a menu Item Action');
                }
            }
        ]
    }
};
PropTypeDescription
iconClsstringclass to be used for the action icon
menuarrayOf(object)menuItems, with text, key, EVENT_HANDLER properties. each object must contain a unique key relative to it's parent array. These keys will be used as the JSX element key.
onMenuShowfunca method that fires upon menu action click. @return an array of keys to disable menu items that correspond with these keys.

Selection Model

export const plugins = {
    SELECTION_MODEL: {
        mode: 'single',
        enabled: true,
        editEvent: 'singleclick',
        allowDeselect: true,
        activeCls: 'active-class',
        selectionEvent: 'singleclick'
    }
};
PropTypeDescription
modeoneOf(['single', 'multi', 'checkbox-single', 'checkbox-multi'])determines whether a single value, or multiple values can be selected
editEventoneOf(['singleclick', 'doubleclick', 'none'])what type of mouse event will trigger the editor
enabledboolwhether the selection model class is initialized
allowDeselectboolwhether a value can be deselected
activeClsstringthe class applied to active rows upon selection
selectionEventoneOf(['singleclick', 'doubleclick'])the browser event which triggers the selection event

Error Handler

export const plugins = {
    ERROR_HANDLER: {
        defaultErrorMessage: 'AN ERROR OCURRED',
        enabled: true
    }
};
PropTypeDescription
defaultErrorMessagestringthe default error message to display when no error information is available
enabledboolwhether the error handler should be initialized

Loader

export const plugins = {
    LOADER: {
        enabled: true
    }
};
PropTypeDescription
enabledboolwhether the loading mask should be initialized

Bulk Actions

export const plugins = {
    BULK_ACTIONS: {
        enabled: true,
        actions: [
            {
                text: 'Bulk Action Button',
                EVENT_HANDLER: () => {
                    console.log('Doing a bulk action');
                }
            }
        ]
    }
};
PropTypeDescription
enabledboolwhether the bulk action toolbar should be used
actionsarrayOf(object)the actions (including button text, and event handler) that will be displayed in the bar

Row renderer

export const plugins = {
    ROW: {
        enabled: true,
        renderer: ({rowProps, cells, row}) => {
          return (
              <tr { ...rowProps }>
                  { cells }
              </tr>
            );
        }
    }
};
PropTypeDescription
enabledboolwhether the bulk action toolbar should be used
rendererfuncfunction which returns the row contents for this row

Events

All grid events are passed in as a single object.

export const events = {
    HANDLE_CELL_CLICK: () => {},
    HANDLE_CELL_DOUBLE_CLICK: () => {},
    HANDLE_BEFORE_ROW_CLICK: () => {},
    HANDLE_ROW_CLICK: () => {},
    HANDLE_ROW_DOUBLE_CLICK: () => {},
    HANDLE_BEFORE_SELECTION: () => {},
    HANDLE_AFTER_SELECTION: () => {},
    HANDLE_BEFORE_INLINE_EDITOR_SAVE: () => {},
    HANDLE_AFTER_INLINE_EDITOR_SAVE: () => {},
    HANDLE_BEFORE_BULKACTION_SHOW: () => {},
    HANDLE_AFTER_BULKACTION_SHOW: () => {},
    HANDLE_BEFORE_SORT: () => {},
    HANLE_BEFORE_EDIT: () => {},
    HANDLE_AFTER_SELECT_ALL: () => {},
    HANDLE_AFTER_DESELECT_ALL: () => {},
    HANDLE_AFTER_ROW_DROP: () => {},
    HANDLE_BEFORE_TREE_CHILD_CREATE: () => {},
    HANDLE_EDITOR_FOCUS: () => {},
    HANDLE_EDITOR_BLUR: () => {}
};

Each function is passed two arguments, the first is a context object which will contain metadata about the event, and the second argument is the browser event if applicable.

HANDLE_CELL_CLICK = ({ row, rowId, rowIndex }, e) => {}

Style

All core components and plugins have corresponding .styl files that can be extended or overwritten. Class names have also been modularized and are available to modify or extend within src/constants/gridConstants.js

To update CLASS_NAMES or the CSS_PREFIX dynamically, you can use the applyGridConfig function. More information is available here.


export const CSS_PREFIX = 'react-grid';

export const CLASS_NAMES = {
    ACTIVE_CLASS: 'active',
    DRAG_HANDLE: 'drag-handle',
    SORT_HANDLE: 'sort-handle',
    SECONDARY_CLASS: 'secondary',
    CONTAINER: 'container',
    TABLE: 'table',
    HEADER: 'header',
    ROW: 'row',
    CELL: 'cell',
    PAGERTOOLBAR: 'pager-toolbar',
    EMPTY_ROW: 'empty-row',
    LOADING_BAR: 'loading-bar',
    DRAGGABLE_COLUMN: 'draggable-column',
    COLUMN: 'column',
    SORT_HANDLE_VISIBLE: 'sort-handle-visible',
    BUTTONS: {
        PAGER: 'page-buttons'
    },
    SELECTION_MODEL: {
        CHECKBOX: 'checkbox',
        CHECKBOX_CONTAINER: 'checkbox-container'
    },
    ERROR_HANDLER: {
        CONTAINER: 'error-container',
        MESSAGE: 'error-message'
    },
    EDITOR: {
        INLINE: {
            CONTAINER: 'inline-editor',
            SHOWN: 'shown',
            HIDDEN: 'hidden',
            SAVE_BUTTON: 'save-button',
            CANCEL_BUTTON: 'cancel-button',
            BUTTON_CONTAINER: 'button-container'
        }
    },
    GRID_ACTIONS: {
        CONTAINER: 'action-container',
        SELECTED_CLASS: 'action-menu-selected',
        MENU: {
            CONTAINER: 'action-menu-container',
            ITEM: 'action-menu-item'
        }
    },
    BULK_ACTIONS: {
        CONTAINER: 'bulkaction-container',
        DESCRIPTION: 'bulkaction-description',
        SHOWN: 'shown',
        HIDDEN: 'hidden'
    }

};

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial