Description

Table with full rows and columns virtualization.

Demo here

Simple example:

Example

import * as React from 'react';
import { render } from 'react-dom';
import { Table } from '@biorate/react-virtual-table';
import '@biorate/react-virtual-table/dist/style.css';

render(
<Table
width={800}
height={375}
headers={[
{
title: `Field 1`,
field: `field_1`,
width: 400,
},
{
title: `Field 2`,
field: `field_2`,
width: 400,
},
{
title: `Field 3`,
field: `field_3`,
width: 400,
},
]}
items={[
{
field_1: 0,
field_2: 0,
field_3: 0,
},
{
field_1: 1,
field_2: 1,
field_3: 1,
},
{
field_1: 2,
field_2: 2,
field_3: 2,
},
{
field_1: 3,
field_2: 3,
field_3: 3,
},
{
field_1: 4,
field_2: 4,
field_3: 4,
},
]}
/>,
document.getElementById('root'),
);

Huge data example:

Example

import * as React from 'react';
import { render } from 'react-dom';
import { range, random } from 'lodash';
import { Table } from '@biorate/react-virtual-table';
import '@biorate/react-virtual-table/dist/style.css';
let j = 0;

render(
<Table
style={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 1500,
height: 600,
}}
headers={range(0, 1000).map((item) => ({
fixed: [0, 1].includes(item) ? 'left' : [3, 5].includes(item) ? 'right' : undefined,
title: `Field ${item}`,
field: `field_${item}`,
width: random(100, 200),
}))}
items={range(0, 10000).map(() => {
const item = {};
for (const i of range(0, 1000)) item[`field_${i}`] = j++;
return item;
})}
/>,
document.getElementById('root'),
);

Inspired by

Hierarchy

  • Component<{
        border?: number;
        headers: Columns;
        height?: number;
        items: Rows;
        no-footer?: boolean;
        no-header?: boolean;
        no-paginator?: boolean;
        pagination?: PaginationProps;
        render?: {
            content?: ((row, col, index, rows) => unknown);
            footer?: ((col) => unknown);
            header?: ((col) => unknown);
        };
        style?: Record<string, any>;
        width?: number;
    }, unknown>
    • Table

Constructors

  • Parameters

    • props: {
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      } | Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>

    Returns Table

  • Parameters

    • props: {
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }
      • Optional border?: number

        Description

        Table borders width

      • headers: Columns

        Description

        Declaring headers

      • Optional height?: number

        Description

        Table height

      • items: Rows

        Description

        Array of objects for render

      • Optional no-footer?: boolean

        Description

        Don't render footer, false by default

      • Optional no-header?: boolean

        Description

        Don't render header, false by default

      • Optional no-paginator?: boolean

        Description

        Don't render paginator, false by default

      • Optional pagination?: PaginationProps

        Description

        Paginator settings

      • Optional render?: {
            content?: ((row, col, index, rows) => unknown);
            footer?: ((col) => unknown);
            header?: ((col) => unknown);
        }

        Description

        Render functions for override

        • Optional content?: ((row, col, index, rows) => unknown)
        • Optional footer?: ((col) => unknown)
            • (col): unknown
            • Parameters

              Returns unknown

              Description

              Header render function, returns row field name by default

        • Optional header?: ((col) => unknown)
            • (col): unknown
            • Parameters

              Returns unknown

              Description

              Header render function, returns header title (or header field, if title not exists) by default

      • Optional style?: Record<string, any>

        Description

        Css styles of table wrapper

      • Optional width?: number

        Description

        Table width

    • context: any

    Returns Table

Properties

#bounds: RefObject<HTMLDivElement> = ...
#store: Store = ...
context: any

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType. Should be used with type annotation or static contextType.

static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>
props: Readonly<{
    border?: number;
    headers: Columns;
    height?: number;
    items: Rows;
    no-footer?: boolean;
    no-header?: boolean;
    no-paginator?: boolean;
    pagination?: PaginationProps;
    render?: {
        content?: ((row, col, index, rows) => unknown);
        footer?: ((col) => unknown);
        header?: ((col) => unknown);
    };
    style?: Record<string, any>;
    width?: number;
}> & Readonly<{
    children?: ReactNode;
}>
refs: {
    [key: string]: ReactInstance;
}

Type declaration

  • [key: string]: ReactInstance
state: Readonly<unknown>
contextType?: Context<any>

If set, this.context will be set at runtime to the current value of the given Context.

Usage:

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
static contextType = Ctx
context!: React.ContextType<typeof Ctx>
render () {
return <>My context's value: {this.context}</>;
}
}

Methods

  • Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.

    Calling Component#setState generally does not trigger this method.

    This method will not stop working in React 17.

    Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

    Parameters

    • nextProps: Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>
    • nextContext: any

    Returns void

  • Called immediately before rendering when new props or state is received. Not called for the initial render.

    Note: You cannot call Component#setState here.

    This method will not stop working in React 17.

    Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

    Parameters

    • nextProps: Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>
    • nextState: Readonly<unknown>
    • nextContext: any

    Returns void

  • Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

    Parameters

    • error: Error
    • errorInfo: ErrorInfo

    Returns void

  • Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.

    Calling Component#setState generally does not trigger this method.

    Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

    Parameters

    • nextProps: Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>
    • nextContext: any

    Returns void

  • Called immediately before rendering when new props or state is received. Not called for the initial render.

    Note: You cannot call Component#setState here.

    Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

    Parameters

    • nextProps: Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>
    • nextState: Readonly<unknown>
    • nextContext: any

    Returns void

  • Parameters

    • Optional callback: (() => void)
      Optional
        • (): void
        • Returns void

    Returns void

  • Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

    Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated lifecycle events from running.

    Parameters

    • prevProps: Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>
    • prevState: Readonly<unknown>

    Returns any

  • Type Parameters

    • K extends never

    Parameters

    • state: unknown
    • Optional callback: (() => void)
      Optional
        • (): void
        • Returns void

    Returns void

  • Called to determine whether the change in props and state should trigger a re-render.

    Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

    If false is returned, Component#render, componentWillUpdate and componentDidUpdate will not be called.

    Parameters

    • nextProps: Readonly<{
          border?: number;
          headers: Columns;
          height?: number;
          items: Rows;
          no-footer?: boolean;
          no-header?: boolean;
          no-paginator?: boolean;
          pagination?: PaginationProps;
          render?: {
              content?: ((row, col, index, rows) => unknown);
              footer?: ((col) => unknown);
              header?: ((col) => unknown);
          };
          style?: Record<string, any>;
          width?: number;
      }>
    • nextState: Readonly<unknown>
    • nextContext: any

    Returns boolean

Generated using TypeDoc