🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@lsky/v-table

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lsky/v-table

> React components for render table with virtual

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

Virtual Table

React components for render table with virtual

Installing

npm

$ npm i @lsky/v-table

yarn

$ yarn add @lsky/v-table

And you need to React and ReactDom

$ npm i react react-dom

Example

Basic usage

import React from 'react'
import VTable from '@lsky/v-table'

class Index extends React.PureComponent {
  tableRender({
    rowIndex, columnIndex, key, style,
  }) {
    return (
      <div key={key} style={style}>{`row-${rowIndex}-col-${columnIndex}`}</div>
    )
  }

  render() {
    return (
      <VTable
        width={860}
        height={600}
        rowHeight={40}
        columnWidth={100}
        columnCount={100}
        rowCount={1000}
        render={this.tableRender}
      />
    )
  }
}

Wrap Adaptive

Adaptive component will adapt the container width and height, and return the width and height value.

Warning: The parent element must have relative attr.

import React from 'react'
import VTable, { Adaptive } from '@lsky/v-table'

class Index extends React.PureComponent {
  tableRender({
    rowIndex, columnIndex, key, style,
  }) {
    return (
      <div key={key} style={style}>{`row-${rowIndex}-col-${columnIndex}`}</div>
    )
  }

  render() {
    return (
      <Adaptive>
        {({ width, height }) => (
          <VTable
            width={width}
            height={height}
            rowHeight={40}
            columnWidth={100}
            columnCount={100}
            rowCount={1000}
            render={this.tableRender}
          />
        )}
      </Adaptive>
    )
  }
}

Wrap WindowScroller

*Warning: * WindowScroller cannot be mixed with Adaptive.


import React from 'react'
import VTable, { WindowScroller } from '@lsky/v-table'

class Index extends React.PureComponent {
  tableRender({
    rowIndex, columnIndex, key, style,
  }) {
    return (
      <div key={key} style={style}>{`row-${rowIndex}-col-${columnIndex}`}</div>
    )
  }

  render() {
    return (
      <WindowScroller>
        {({ scrollTop, scrollLeft }) => (
          <VTable
            width={860}
            height={600}
            scrollTop={scrollTop}
            scrollLeft={scrollLeft}
            rowHeight={40}
            columnWidth={100}
            columnCount={100}
            rowCount={1000}
            render={this.tableRender}
          />
        )}
      </WindowScroller>
    )
  }
}

Component Props

VTable

attrtypedefault valuerequireddesc
columnWidthnumber | ((columnIndex) => number)nulltruecolumn width
columnCountnumbernulltruecolumn count
rowHeightnumber | ((rowIndex) => number)nulltruerow height
rowCountnumbernulltruerow count
widthnumbernulltruecontainer width
heightnumbernulltruecontainer height
scrollTopnumbernullfalsescrollTop. if passed in, change to controlled component
scrollLeftnumbernullfalsescrollLeft. if passed in, change to controlled component
render(({rowIndex, columnIndex, key, style}) => React.node)nulltruerender cell
onScroll(({scrollTop, scrollLeft}) => void)nullfalseonScroll
isWindowScrollerbooleannullfalseis use WindowScroller component wrap

Adaptive

attrtypedefault valuerequireddesc
defaultWidthnumbernullfalsedefault width
defaultHeightnumbernullfalsedefault height
children(({width, height}) => React.node)nulltruechildren

WindowScroller

attrtypedefault valuerequireddesc
scrollLeftnumbernullfalsescroll left
scrollTopnumbernullfalsescroll top
children(({scrollLeft, scrollTop}) => React.node)nulltruechildren

Keywords

react-component

FAQs

Package last updated on 18 Nov 2020

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