Giter VIP home page Giter VIP logo

mui-virtualized-table's Introduction

mui-virtualized-table

Combination of Material UI visual components with react-virtualized for improved performance and features with a simple API.

For examples of <MuiTable> in action, see demo or view the source

Features

  • Uses windowing for performance (via react-virtualized)
  • Freeze rows and/or columns
  • Fixed or variable (%) column widths
  • Resizable columns

Props

Property Type Required Default Description
data array Data to render using defined columns
columns array Defines the columns in the table.
Column format: {'name', 'header', 'onHeaderClick', 'width', 'cell', ...cellProps }
name: Name of header
header: (optional) Name to display instead 'name'
onHeaderClick: (optional) Callback when header is clicked on (has precendence over onHeaderClick on table
width: (optional) Width of cell
cell: (optional) Callback for rendering associated column cell data. Passes the row data for the associated cell.
cellProps object func
width number Visible width of table. Will scroll horizontally if sum of column widths are greater than defined width
columnWidth number or func Static column widths if number, calulated based on columns definitons if not specificed, or can pass in a function to peform own calcuation based on data
height number calculted from data.length or pagination.rowsPerPage if defined Visible height of table. Will scroll vertically if sum of column heights are great than defined height
maxHeight number 0 Maximum height of table. Useful when using calculated
fitHeightToRows boolean false Always fit the content height to row data. Only useful when using pagination and you want to reduce the height on non-full pages (will move paginator on different length results)
rowHeight number 48 Height of rows
fixedRowCount number 0 Number of rows to remain fixed at the top of the viewport (freeze rows). Based on columns definition order
fixedColumnCount number 0 Number of columns to remain fixed at the left of the viewport (freeze columns). Based on columns definition order
includeHeaders bool false Add header row to top of data. Useful to also set fixedRowCount to 1
onHeaderClick func Called with column definition of header clicked on. Useful to set sort data and set orderBy and orderDirection
onCellClick func Called with column definition and row data when non-header cell is clicked on (ex. onCellClick={(event, { column, rowData, data} ) => alert(rowData[column.name])})
onCellDoubleClick func Called with column definition and row data when non-header cell is double clicked on (ex. onCellDoubleClick={(event, { column, rowData, data} ) => alert(rowData[column.name])})
onCellContextMenu func Called with column definition when non-header cell is right clicked on (ex. onCellContextMenu={(event, { column }) => alert(column.name)})
pagination object If defined, will add pagination to bottom of table and pass props to Material-UI's TablePagination component. Must set count, onChangePage, page, and rowsPerPage if defined.
orderBy string If defined, will show column's header with matching name using TableSortLabel
orderDirection string 'desc' The order of the sort direction
resizable bool Enable column resizing handles

Running Storybook

This project has some storybook stories.

To run storybook, you have to install the story dependencies first:

$ cd stories
$ yarn install
$ cd ..

Then use yarn to run the storybook script:

$ yarn install
$ yarn storybook

mui-virtualized-table's People

Contributors

204504byse avatar alexander7161 avatar benbeshel avatar cvanem avatar marklemerise avatar pashadia avatar techniq avatar thedillonb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mui-virtualized-table's Issues

Add rowIndex to cellProps

Hi,

First i would like to thank you for this nice library.

I think it would be useful to pass the rowIndex to cellProps function.

The reasoning behind this, is that i would like to display styles that depends on the state of data that is not in the subset passed to the table but it is in the superset.

https://github.com/techniq/mui-virtualized-table/blob/master/src/index.js#L221

const resolveCellProps = cellProps =>
  typeof cellProps === 'function'
    ? cellProps(column, rowData, hoveredColumn, hoveredRowData)
    : cellProps;
// TODO: Deep merge (do not override all defaultCellProps styles if column.cellProps.styles defined?)
const { style: cellStyle, ...cellProps } = {
  ...resolveCellProps(defaultCellProps),
  ...resolveCellProps(column.cellProps)

};

cellProps(column, rowData, hoveredColumn, hoveredRowData, rowIndex)

Do you see any reason to not add this? I could create a PR for this if needed

Regards,
Luis

cellProps missing in TypeScript definitions

After upgrading to 2.2.1, I'm getting the following error from TypeScript:

src/Devices/Devices.tsx:122:9 - error TS2322: Type '({ header: Element; cell: (d: SelectableDevice) => Element; width: number; cellProps: { padding: string; }; } | { header: string; name: string; } | { header: string; name: string; width: number; } | { ...; } | { ...; } | { ...; } | { ...; })[]' is not assignable to type 'IMuiVirtualizedTableColumn<SelectableDevice>[]'.
  Type '{ header: Element; cell: (d: SelectableDevice) => Element; width: number; cellProps: { padding: string; }; } | { header: string; name: string; } | { header: string; name: string; width: number; } | { ...; } | { ...; } | { ...; } | { ...; }' is not assignable to type 'IMuiVirtualizedTableColumn<SelectableDevice>'.
    Type '{ header: Element; cell: (d: SelectableDevice) => Element; width: number; cellProps: { padding: string; }; }' is not assignable to type 'IMuiVirtualizedTableColumn<SelectableDevice>'.
      Object literal may only specify known properties, and 'cellProps' does not exist in type 'IMuiVirtualizedTableColumn<SelectableDevice>'.

122         cellProps: { padding: 'checkbox' },
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/mui-virtualized-table/index.d.ts:81:3
    81   columns: Array<IMuiVirtualizedTableColumn<TRow>>;
         ~~~~~~~
    The expected type comes from property 'columns' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<MuiVirtualizedTable<SelectableDevice>> & Readonly<PropsWithChildren<IMuiVirtualizedTableProps<SelectableDevice>>>'


Found 1 error.

It seems like the cellProps property is missing in the TypeScript definitions for IMuiVirtualizedTableColumn.

[QUESTION] How can i style the headers?

Hi,

I want to apply custom styles to my frozen header / column.

I am styling the background with:

.ReactVirtualized__Grid.topRightGrid, 
.ReactVirtualized__Grid.topLeftGrid,
.ReactVirtualized__Grid.bottomLeftGrid{
    background-color: ${Color.primary};
    color: ${Color.textColor2};
}

However the cellHeader style from MUI is taking precedence for the font color.

Any ideas?

Thanks

withstyles is undefined in 3.0.0

After installing v3.0.0-4, I get this error on the browser console "TypeError: Cannot read property 'withstyles' of undefined". The error is in the last line export default withStyles(styles, { withTheme: true })(MuiTable);. I think for withStyles, the import has to specifically be at "@material-ui/core/styles".

Make rows collapsible

I got a use case where there are few rows that are collapsible. That possible for this lib. If so, what would be the tweak?

TypeScript support

It would be great to have native TypeScript support and typings for this project.

Make Table Cells Editable

Hello, so this is a great npm package for having a virtualized MUI Table.

However, in my use case I need all the cells to be editable. How can I put the data into textfields or simply make the cell directly editable?

Warning: componentWillReceiveProps has been renamed

Hi,

I get this warning at run-time:

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: MuiTable```

Using React 16.11.0

theme.spacing.unit usage has been deprecated

Hi,

I get a error in the console at run-time:

Material-UI: theme.spacing.unit usage has been deprecated.
It will be removed in v5.
You can replace `theme.spacing.unit * y` with `theme.spacing(y)`.

I'm using Material-UI 4.9.5

Stacktrace:

You can use the `https://github.com/mui-org/material-ui/tree/master/packages/material-ui-codemod/README.md#theme-spacing-api` migration helper to make the process smoother. 
./node_modules/react-dom/index.js@http://localhost:8080/en/static/js/home.c83ab16a.js:218854:20
div
./node_modules/react-dom/cjs/react-dom.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:218809:5
div
div
./node_modules/scheduler/cjs/scheduler.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:259722:5
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
div
fn@http://localhost:8080/en/static/js/home.c83ab16a.js:101:20
./node_modules/scheduler/index.js@http://localhost:8080/en/static/js/home.c83ab16a.js:259739:20
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
./node_modules/scheduler/cjs/scheduler.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:259722:5
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
div
div
div
./node_modules/scheduler/index.js@http://localhost:8080/en/static/js/home.c83ab16a.js:259739:20
./node_modules/react-dom/cjs/react-dom.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:218809:5
./node_modules/react-dom/cjs/react-dom.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:218809:5
fn@http://localhost:8080/en/static/js/home.c83ab16a.js:101:20
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
fn@http://localhost:8080/en/static/js/home.c83ab16a.js:101:20
./node_modules/react-dom/cjs/react-dom.development.js/<@http://localhost:8080/en/static/js/home.c83ab16a.js:191103:36
./node_modules/react-dom/cjs/react-dom.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:218809:5
fn@http://localhost:8080/en/static/js/home.c83ab16a.js:101:20
./node_modules/react-dom/cjs/react-dom.development.js@http://localhost:8080/en/static/js/home.c83ab16a.js:218809:5
fn@http://localhost:8080/en/static/js/home.c83ab16a.js:101:20 index.js:1

Custom cell rendrer

Hi,

Can I use a custom cell renderer? I simply need to add a checkbox in a table cell. Couldn't find any sample in the storybook.

Thanks

Not able to pass a function into columnWidth

The docs state that columnWidth could either be a number or a func. But when giving the prop a function it throws the following error:

checkPropTypes.js:19 Warning: Failed prop type: Invalid prop `columnWidth` of type `function` supplied to `MuiTable`, expected `number`.
    in MuiTable (created by WithStyles(MuiTable))
    in WithStyles(MuiTable) (created by AutoSizer)
(...)
Uncaught Error: Invalid size returned for cell 0 of value NaN
    at CellSizeAndPositionManager.getSizeAndPositionOfCell (CellSizeAndPositionManager.js:105)
    at CellSizeAndPositionManager._binarySearch (CellSizeAndPositionManager.js:252)
    at CellSizeAndPositionManager._findNearestCell (CellSizeAndPositionManager.js:305)
    at CellSizeAndPositionManager.getVisibleCellRange (CellSizeAndPositionManager.js:217)
    at ScalingCellSizeAndPositionManager.getVisibleCellRange (ScalingCellSizeAndPositionManager.js:160)
    at Grid._calculateChildrenToRender (Grid.js:811)
    at Grid.render (Grid.js:717)
    at finishClassComponent (react-dom.development.js:13194)
    at updateClassComponent (react-dom.development.js:13156)
    at beginWork (react-dom.development.js:13825)
(...)
Uncaught Error: Invalid size returned for cell 0 of value NaN
    at CellSizeAndPositionManager.getSizeAndPositionOfCell (CellSizeAndPositionManager.js:105)
    at CellSizeAndPositionManager._binarySearch (CellSizeAndPositionManager.js:252)
    at CellSizeAndPositionManager._findNearestCell (CellSizeAndPositionManager.js:305)
    at CellSizeAndPositionManager.getVisibleCellRange (CellSizeAndPositionManager.js:217)
    at ScalingCellSizeAndPositionManager.getVisibleCellRange (ScalingCellSizeAndPositionManager.js:160)
    at Grid._calculateChildrenToRender (Grid.js:811)
    at Grid.render (Grid.js:717)
    at finishClassComponent (react-dom.development.js:13194)
    at updateClassComponent (react-dom.development.js:13156)
    at beginWork (react-dom.development.js:13825)
(...)
react-dom.development.js:14227 The above error occurred in the <Grid> component:
    in Grid (created by MultiGrid)
    in div (created by MultiGrid)
    in div (created by MultiGrid)
    in MultiGrid (created by MuiTable)
    in div (created by Table)
    in Table (created by WithStyles(Table))
    in WithStyles(Table) (created by MuiTable)
    in MuiTable (created by WithStyles(MuiTable))
    in WithStyles(MuiTable) (created by AutoSizer)
    in div (created by AutoSizer)

Unnecessary horizontal scroll bar on Windows

Tables show an unnecessary horizontal scroll bar after scrolling vertically for a bit. This happens only on Windows (tested with Windows 10 and different browsers). I made a minimal example here that does show the behavior: https://codesandbox.io/s/v8z0lwvpj7

The same can be observed for some of the examples (e.g. https://techniq.github.io/mui-virtualized-table/?selectedKind=Basic&selectedStory=fixed%2Ffreeze%20row%28s%29&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel).

When visiting the site with any browser on Windows and then scrolling the table up and down a little, a horizontal scroll bar appears.

It seems to be happening mainly when scrolling back up after having scrolled down.

OrderBy not working

Looks like using MUI v4.x the orderby isn't working to add the TableSortLabel to the header.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.