# @braniac/virtual-grid

> ``` { return

Latest version **0.1.8** (published 2020-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @braniac/virtual-grid
pnpm add @braniac/virtual-grid
yarn add @braniac/virtual-grid
bun add @braniac/virtual-grid
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2020-06-26 |
| First published | 2020-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 42.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | prasadmadanayake |

## Links

- npm: https://www.npmjs.com/package/@braniac/virtual-grid
- npm.io page: https://npm.io/package/@braniac/virtual-grid

## Dependencies (18)

- [uuid](https://npm.io/package/uuid.md) ^7.0.1
- [react](https://npm.io/package/react.md) ^16.12.0
- [eslint](https://npm.io/package/eslint.md) ^6.8.0
- [moment](https://npm.io/package/moment.md) ^2.24.0
- [webpack](https://npm.io/package/webpack.md) ^4.41.6
- [react-dom](https://npm.io/package/react-dom.md) ^16.12.0
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [typescript](https://npm.io/package/typescript.md) ^3.8.3
- [@date-io/core](https://npm.io/package/@date-io/core.md) 1.3.6
- [react-scripts](https://npm.io/package/react-scripts.md) 3.4.0
- [@date-io/moment](https://npm.io/package/@date-io/moment.md) 1.x
- [react-virtualized](https://npm.io/package/react-virtualized.md) ^9.21.2
- [@testing-library/dom](https://npm.io/package/@testing-library/dom.md) ^6.12.2
- [@testing-library/react](https://npm.io/package/@testing-library/react.md) ^9.3.2
- [eslint-plugin-flowtype](https://npm.io/package/eslint-plugin-flowtype.md) ^4.6.0
- [@testing-library/jest-dom](https://npm.io/package/@testing-library/jest-dom.md) ^4.2.4
- [@testing-library/user-event](https://npm.io/package/@testing-library/user-event.md) ^7.1.2

## Recent versions

- 0.1.8 (latest) — 2020-06-26
- 0.1.7 — 2020-05-24
- 0.1.6 — 2020-05-15
- 0.1.5 — 2020-05-15
- 0.1.4 — 2020-04-29
- 0.1.3 — 2020-04-11
- 0.1.2 — 2020-04-09
- 0.1.1 — 2020-04-09
- 0.1.0 — 2020-04-09
- 0.0.9 — 2020-03-29
- 0.0.8 — 2020-03-29
- 0.0.7 — 2020-03-28
- 0.0.6 — 2020-03-10
- 0.0.5 — 2020-03-10
- 0.0.4 — 2020-02-28
- … 3 more at https://npm.io/package/@braniac/virtual-grid/versions

## README

# Table Wrapper for React Virtualized

## Usage

```
<Table
    title={title}
    columns={columns}
    header
    data={data}
    utility={{
        optionalButton:[
            (i)=>{
                return <React.Fragment key={`optional.ele.${i}`}>
                    <IconButton edge="start" className={classes.icon} color="inherit" onClick={close} aria-label="Close">
                        <CloseIcon />
                    </IconButton>
                </React.Fragment>
            }
        ],
        ExportData:(e)=>{
            return true;
        },
        onSearch:(e)=>{ return true;},
        onSort:(o)=>{
            return true;
        },
        onFilter:(o)=>{
            return true;
        }
    }}
    rowHeight={55}
    fixedCols={0}
    minColumnWidth={250}
    actions={{
        onUpdateApply: ({rowIndex,data:value}) => {

            return true;
        },
        onSelectRow:()=>{
            return true;
        },
        onAddRow:({rowIndex,data:value})=>{

            return true;
        }
    }}
/>

```

### Table Props
| Property | Type |Allowed Values| Description |
|---|---|---|---|
|`tilte`|<code>string&#124;element</code>|`any`| Table Header Title|
|`columns`|`array`|`array of column definition objects`| Array of column definitions|
|`header`|`boolean`|<code>true&#124;false</code>|Header visibility|
|`data`|`array`|`array of objects`|Array of data objects|
|`utility`|`object`|`utility definition`|Table utility configuration object|
|`rowHeight`|`number`|`any`|Table Row Height|
|`fixedCols`|`number`|`any >= 0`|Frozen column count from left|
|`minColumnWidth`|`number`|`any`|Minimum column width|
|`actions`|`object`|`action definition`|Table actions column configurations|

#### Column Definition

```
{    
    label: 'Fat (g)',
    dataKey: 'fat',
    numeric: true,
    visible:true,
    width:200,
    align:"right",
    displayFormat:{
      thousandSeparator:true,
      precision:2,
      suffix:"%",
      currency:{
        derived:true,
        key:"calories",
        frmt:(data)=>{return {id:data,symbol:"LKR",prefixSymbol:false}}
      }
    }
    ,
    filter:{
      enable:true,
      type:"number"
    },
    editor:{
      editable:true,
      type:'number'
    }
}
```

|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`label`|`string`|`any`||
|`dataKey`|`string`|`any`||
|`numeric`|`boolean`|<code>true&#124;false</code>||
|`visible`|`boolean`|<code>true&#124;false</code>||
|`width`|`number`|`any > minColumnWidth`||
|`align`|`text`|<code>left&#124;right&#124;center</code>||
|`displayFormat`|`object`|`display format definition`|Optional display format definition for numeric columns|
|`filter`|`object`|`filter definition`||
|`editor`|`object`|`editor definition`||

###### Display Format Definition
|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`thousandSeparator`|`boolean`|<code>true&#124;false</code>||
|`precision`|`number`|`any > 0`||
|`suffix`|`string`|`any`|Optional suffix for the formatter|
|`prefix`|`string`|`any`|Optional prefix for the formatter|
|`currency`|`object`|`currency format definition`|Optional currency format definition|

###### Currency definition
|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`derived`|`boolean`|<code>true&#124;false</code>||
|`key`|`string`|`any`||
|`frmt`|`function`|`function` should return `{symbol:"$",prefixSymbol:true}` format||


###### Filter definition
|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`enable`|`boolean`|<code>true&#124;false</code>||
|`type`|`string`|<code>date&#124;boolean&#124;number&#124;text</code>||


###### Editor definition
|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`editable`|`boolean`|<code>true&#124;false</code>||
|`type`|`string`|<code>date&#124;boolean&#124;number&#124;text</code>||

#### Utility Definition
```
{
    optionalButton:[
                (i)=>{
                    return <React.Fragment key={`optional.ele.${i}`}>
                        <IconButton>
                            <CloseIcon />
                        </IconButton>
                    </React.Fragment>
                }
            ],
    ExportData:(e)=>{
        return true;
    },
    onSearch:(e)=>{ return true;},
    onSort:(o)=>{
        return true;
    },
    onFilter:(o)=>{
        return true;
    }
}
```

|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`optionalButton`|`array`|`array` of `function`s should return `element`||
|`ExportData`|`function`|`function` should return `boolean` ||
|`onSearch`|`function`|`function` should return `boolean`||
|`onSort`|`function`|`function` should return `boolean`||
|`onFilter`|`function`|`function` should return `boolean`||

####Actions definition

```
{
    onUpdateApply: ({rowIndex,data:value}) => {
        return true;
    },
    onSelectRow:()=>{
        return true;
    },
    onAddRow:({rowIndex,data:value})=>{
        return true;
    },
    onDeleteRow:({rowIndex,data:value})=>{
        return true;
    },
    renderer:{
            EditRow:(...),
            AddRow:(...),
            DefaultRow:(...)
        }
}
``` 

|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`onUpdateApply`|`function`|`function` should return `boolean`||
|`onSelectRow`|`function`|`function` should return `boolean`||
|`onAddRow`|`function`|`function` should return `boolean`||
|`onDeleteRow`|`function`|`function` should return `boolean`||
|`renderer`|`object`|`action renderer definition`|Optional render definition to override defaults|

##### Action Renderer Definition

|Property|Type|Allowed Values|Definition|
|---|---|---|---|
|`EditRow`|`function`|`function` returning a `element`||
|`AddRow`|`function`|`function` returning a `element`||
|`DefaultRow`|`function`|`function` returning a `element`||

### Example

```jsx harmony

const cols = [

  {
    label: 'Dessert',
    dataKey: 'dessert',
    visible:true,
    width:60,
    sortable:true,
    filter:{
      enable:true,
      type:"text"
    },
    editor:{
      editable:false,
      type:'text'
    }
  },
  {
    label: 'Calories (g)',
    dataKey: 'calories',
    numeric: true,
    visible:true,
    sortable:true,
    width:200,
    flexGrow: 1.0
  },
  {
    label: 'Fat (g)',
    dataKey: 'fat',
    numeric: true,
    visible:true,
    flexGrow:1,
    width:200,
    align:"right",
    displayFormat:{
      thousandSeparator:true,
      precision:2,
      suffix:"%",
      currency:{
        derived:true,
        key:"calories",
        frmt:(data)=>{return {id:data,symbol:"LKR",prefixSymbol:false}}
      }
    }
    ,
    filter:{
      enable:true,
      type:"number"
    },
    editor:{
      editable:true,
      type:'number'
    }
  }
];


const data = Array.from({length: 600}, (x,i) => {return  cols.reduce((acc,{dataKey,type,numeric=false},i)=>{

  if(type && type === "boolean")
    acc[dataKey] = Math.floor(Math.random() * Math.floor(3)) %2 === 0 ;
  else
    acc[dataKey] = numeric ? Math.floor(Math.random() * Math.floor(3000)) + 1 : Math.random().toString(36).substring(2);
  return acc;
},{})});

const Sample = (props)=>{
    return  <Table
    title={"Test Table"}
    columns={cols}
    header
    data={data}
    utility={{
        optionalButton:[
            (i)=>{
                return <React.Fragment key={`optional.ele.${i}`}>
                    <IconButton>
                        <CloseIcon />
                    </IconButton>
                </React.Fragment>
            }
        ],
        ExportData:(e)=>{
            return true;
        },
        onSearch:(e)=>{ return true;},
        onSort:(o)=>{
            return true;
        },
        onFilter:(o)=>{
            return true;
        }
    }}
    rowHeight={55}
    fixedCols={0}
    minColumnWidth={250}
    actions={{
        onUpdateApply: ({rowIndex,data:value}) => {
    
            return true;
        },
        onSelectRow:()=>{
            return true;
        },
        onAddRow:({rowIndex,data:value})=>{
    
            return true;
        }
    }}
    />
}

```

---
_Source: https://npm.io/package/@braniac/virtual-grid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
