0.1.8 • Published 4 years ago

@braniac/virtual-grid v0.1.8

Weekly downloads
19
License
MIT
Repository
-
Last release
4 years ago

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

PropertyTypeAllowed ValuesDescription
tiltestring|elementanyTable Header Title
columnsarrayarray of column definition objectsArray of column definitions
headerbooleantrue|falseHeader visibility
dataarrayarray of objectsArray of data objects
utilityobjectutility definitionTable utility configuration object
rowHeightnumberanyTable Row Height
fixedColsnumberany >= 0Frozen column count from left
minColumnWidthnumberanyMinimum column width
actionsobjectaction definitionTable 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'
    }
}
PropertyTypeAllowed ValuesDefinition
labelstringany
dataKeystringany
numericbooleantrue|false
visiblebooleantrue|false
widthnumberany > minColumnWidth
aligntextleft|right|center
displayFormatobjectdisplay format definitionOptional display format definition for numeric columns
filterobjectfilter definition
editorobjecteditor definition
Display Format Definition
PropertyTypeAllowed ValuesDefinition
thousandSeparatorbooleantrue|false
precisionnumberany > 0
suffixstringanyOptional suffix for the formatter
prefixstringanyOptional prefix for the formatter
currencyobjectcurrency format definitionOptional currency format definition
Currency definition
PropertyTypeAllowed ValuesDefinition
derivedbooleantrue|false
keystringany
frmtfunctionfunction should return {symbol:"$",prefixSymbol:true} format
Filter definition
PropertyTypeAllowed ValuesDefinition
enablebooleantrue|false
typestringdate|boolean|number|text
Editor definition
PropertyTypeAllowed ValuesDefinition
editablebooleantrue|false
typestringdate|boolean|number|text

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;
    }
}
PropertyTypeAllowed ValuesDefinition
optionalButtonarrayarray of functions should return element
ExportDatafunctionfunction should return boolean
onSearchfunctionfunction should return boolean
onSortfunctionfunction should return boolean
onFilterfunctionfunction 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:(...)
        }
}
PropertyTypeAllowed ValuesDefinition
onUpdateApplyfunctionfunction should return boolean
onSelectRowfunctionfunction should return boolean
onAddRowfunctionfunction should return boolean
onDeleteRowfunctionfunction should return boolean
rendererobjectaction renderer definitionOptional render definition to override defaults
Action Renderer Definition
PropertyTypeAllowed ValuesDefinition
EditRowfunctionfunction returning a element
AddRowfunctionfunction returning a element
DefaultRowfunctionfunction returning a element

Example

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;
        }
    }}
    />
}