Socket
Book a DemoInstallSign in
Socket

@inventi/common-grid

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inventi/common-grid

[![ReactJs][react-image]][react-url] [![TypeScript][typescript-image]][typescript-url] [![Redux][redux-image]][redux-url] [![Storybook][storybook-image]][storybook-url] [![Download Count][download-image]][download-url] [![GitHub license][license-image]][l

2.0.5-beta.2
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
4
Weekly downloads
 
Created
Source

Inventi Common Grid

ReactJs TypeScript Redux Storybook Download Count GitHub license

Robust, complex and sophisticated component for datagrid rendering.

  • server side and client side sorting
  • server side and client side filtering
  • moving columns via drag and drop
  • column grouping
  • easy to be styled
  • redux support for external control
  • high level of customization

Installation

yarn add @inventi/mailstep-common-grid

Usage

const columnDefinitions = [
     { name: 'username', title: 'User name', flexBasis: 160 },
     { name: 'age', title: 'Age', flexBasis: 160, filteringType: 'number', },
     { name: 'isAdmin', title: 'Admin', flexBasis: 160, filteringType: 'flag', },
]

const data = [
    { id: 1, username: 'John deen', age: 27, isAdmin: true },
    { id: 2, username: 'Emily Watson', age: 22, isAdmin: false },
]

const gridActions = {
  setPage: (number) => console.log('setPage', number),
  setRowsPerPage: (number) => console.log('setRowsPerPage', number),
  addFilter: (column, value, filterProps) => console.log('add filter for column', column ),
}

const gridSelectors = {
    page: 1,
    rowsPerPage: 10
}

const MyPage = () =>
    <CommonGrid
        columnsDefinitions={columnDefinitions}
        rowsData={data}
        gridActions={gridDummyActions}
        gridSelectors={gridSelectors}
    />

Props

actionColumnDefinition: ActionColumn

Used to define the first column of the grid. This column usually contains buttons for displaying detail or editing data in a row and other features.

ActionColumn:

Object with keys:

NameTypeRequiredDescriptionDefault
actionOptionsArray<BatchAction>nohandlers for batch action on grid[]
canRowEditbooleannoshows / hides the edit buttonfalse
canRowReadbooleannoshows / hides the read buttonfalse
createLink(params) => stringnocallback for above buttons-
forceCheckboxesbooleannodisplays checkboxes in each rowfalse

BatchAction

Object with keys:

NameTypeRequiredDescriptionDefault
valuestringyes-
labelstringyes-
isEnabled(checkedRows) => booleanno-

allowRowSelect: boolean, default: false

Enable select a row by clicking.

className: string, default: ''

Main className over the entire grid.

columnLayout: 'normal' | 'no-scroll', default: normal

TODO

components: Components

Used to define custom components in the grid. Object with keys:

NameTypeRequiredDescriptionDefault
TranslatorReact.ComponentTypenosee TranslatorPublicInterfaceProps-
CheckboxReact.ComponentTypenosee CheckboxPublicInterfaceProps-
ButtonReact.ComponentTypenosee ButtonPublicInterfaceProps-
SwitchReact.ComponentTypenosee SwitchPublicInterfaceProps-
PaginatorReact.ComponentTypenosee PaginatorProps-
ColumnTitleReact.ComponentTypenosee ColumnTitleProps-

TranslatorPublicInterfaceProps

Its a component with props

NameTypeRequiredDescriptionDefault
idstringno-
defaultsstringno-

CheckboxPublicInterfaceProps

Its a component with props

NameTypeRequiredDescriptionDefault
namestringno-
labelstring, JSX.Elementno-
onChange(event) => voidno-
checkedbooleanno-

ButtonPublicInterfaceProps

Its a component with props

NameTypeRequiredDescriptionDefault
childrenReact.ReactNodeno-
typebutton, submit, resetno-
appearancestringno-
isLoadingbooleanno-
disabledbooleanno-
marginstringno-
classNamestringno-
onClick(event) => voidno-

SwitchPublicInterfaceProps

Its a component with props

NameTypeRequiredDescriptionDefault
namestringno-
labelstringno-
onChange(event) => voidno-
checkedbooleanno-

PaginatorProps

Its a component with props

NameTypeRequiredDescriptionDefault
pagenumberyes-
itemCountnumberyes-
itemPerPagenumberyes-
onPageChange(number) => voidno-

ColumnTitleProps

Custom component to replace column title and sorting indicator

NameTypeRequiredDescriptionDefault
titlestring | JSX.Elementnotitle of the column-
isSortablebooleanyescan column be sorted-
sortValueasc | desc | nullyescurrent applied sort on this column-
onSetSort(sortValue) => voidnoset new sort value for column-

columnsDefinitions: Array

Defines the properties of each grid column.

ColumnDefinition type

Object with keys:

NameTypeRequiredDescriptionDefault
namestringyes-
groupstringnoDivides columns into the same groups.-
systemNamestringno-
systemFilterstringno-
titlestringno-
filteringbooleanno-
filteringTypenumber, text, date, flagno-
filterExtraPropsFilterExtraPropsno-
getFilterCriteria(value: string) => {[column]: any}no-
filterOptionsArray<Option>no-
sortingbooleanno-
formatRowValue(row) => React.nodeno-
cellComponentReact.ComponentTypenosee DataCellProps-
flexGrownumberno-
flexShrinknumberno-
fixedSizebooleanno-
alwaysOnbooleanno-
defaultHiddenbooleanno-

FilterExtraProps

Object with keys:

NameTypeRequiredDescriptionDefault
isMultibooleannoselect filter is multiSelect-
comparatorsanynooverrides default grid comparators-
filterTimebooleannofilters time too-
decimalsnumbernohow many decimals should be used-
isFloatbooleannofloat filtering should be used-
isBigIntbooleannobig Int filtering should be used-

DataCellProps

NameTypeRequiredDescriptionDefault
rowDataTno-
onRowAction`(id, field, value) => voidPromise`no
columnColumnDefinitionno-

errorMessage: string

If an error occurs somewhere on the page, typically while loading data into the grid, we can display it in the grid where the rows are rendered.

extraControlButtons: Array

Buttons for other user actions can be displayed around the grid.

ExtraControlButton

Object with keys:

NameTypeRequiredDescriptionDefault
nodeReact.ReactNodeno-
onClick() => voidno-
onSelect(value: string) => voidno-
labelReact.nodeno-
styleprimary, secondaryno-
optionsArray<Option>no-
positiontop-left, top-right, bottom-left, bottom-rightno-
hidebooleanno-
hideChevronbooleanno-
disabledbooleanno-

filters: FiltersConfig

gridActions: GridActionsType

gridSelectors: GridSelectorsType

hideAllControls: boolean, default: false

If set, only grid and paginator will be rendered. No other control above and below grid will be rended. Use if you want to handle grid configuration in custom way

hideColumnConfig: boolean, default: false

isLoading: boolean, default: isLoading

minColumnWidth: number, default: 30

onBatchAction: (action: batchAction, affectedRows: T[]) => void

onRowAction: (id: string, field: string, value: any) => void

onRowEditClick: (id: string, row: TData) => void

onRowReadClick: (id: string, row: TData) => void

onRowClick: (id: string, row: TData) => void

rowsData: RowProps[]

totalRowsCount: number, default: 0

getRowClass: (row: TData) => string

Optionally callback that add a classname on each row for a given result

    const getRowClass = (row) => {
        if (row.count > 100) {
            return 'warning'
        }
        return ''
    }

Contributors

License

MIT

FAQs

Package last updated on 31 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.