Giter VIP home page Giter VIP logo

react-vt-table's Introduction

React-VT-Table

Table realisation based on react-window library.

Features

  • Efficiently rendering large tables.
  • Allow custom renderers for row, cell, and header.
  • Built-in resize columns.
  • Built-in auto-scrolling.
  • Easy to add your own sorting and selecting mechanisms (see examples).
  • Works with Immutable.Iterable data lists or native arrays of objects.

Installation

npm install react-vt-table

Demo

Here are some live examples.

Examples

Check out ./src/stories folder to find some code examples.

Styling

You can use built-in CSS style:

import 'react-vt-table/dist/style.css';

or create your own using existing one

API

<Table />

Props

Property Type Required? Description
width Number Table width.
height Number Table height.
headerHeight Number or Func Table header height (Default: 30).
rowHeight Number or Func Table row height (Default: 30).
Function params: (rowIndex).
data Immutable.Iterable Data list for table content.
rowClassName Func Row className determine function.
Function params: (rowIndex).
rowRenderer Func Personal row renderer function.
Function params: see <Row /> props.
sortIndicatorRenderer Func Sort indicator render function.
Function params: ({ dataKey, columnIndex }).
onHeaderClick Func Click Mouse action on header row.
Function params: (event, { dataKey, columnIndex }).
onHeaderDoubleClick Func Double Click Mouse action on header row.
Function params: (event, { dataKey, columnIndex }).
onHeaderMouseOver Func Mouse Over action on header row.
Function params: (event, { dataKey, columnIndex }).
onHeaderMouseOut Func Mouse Out action on header row.
Function params: (event, { dataKey, columnIndex }).
onHeaderRightClick Func Right Click Mouse action on header row.
Function params: (event, { dataKey, columnIndex }).
onRowClick Func Click Mouse action on table row.
Function params: (event, { dataKey, columnIndex }).
onRowDoubleClick Func Double Click Mouse action on table row.
Function params: (event, { dataKey, columnIndex }).
onRowMouseOver Func Mouse Over action on table row.
Function params: (event, { dataKey, columnIndex }).
onRowMouseOut Func Mouse Out action on table row.
Function params: (event, { dataKey, columnIndex }).
onRowMouseDown Func Mouse Down action on table row.
Function params: (event, { dataKey, columnIndex }).
onRowMouseUp Func Mouse Up action on table row.
Function params: (event, { dataKey, columnIndex }).
onRowRightClick Func Right Click Mouse action on table row.
Function params: (event, { dataKey, columnIndex }).
onScroll Func Action on table scroll.
Function params: See React-Window's docs.
onResizeColumn Func Action on change column width.
Function params: ({ dataKey, columnIndex, resizeDiff, newWidth }).
overflowWidth Number Width of vertical table overflow.
minColumnWidth Number Minimal column width.
maxColumnWidth Number Maximum column width.
dynamicColumnWidth Bool Dynamic width for columns that was not resized.
listProps Object Props for inner react-window list component. @see See React-Windows docs
noItemsLabel Node No items in data list label.
disableHeader Bool Hide table header row.
autoScroll Bool Auto scroll to list bottom.
className String Optional custom CSS class name to attach to root container element.
id String Optional custom id to attach to root container element.

Methods

scrollTo(scrollOffset: number): void

scrollToItem(index: number, align: string = "auto"): void

For more info see React-Window's docs

<Column />

Props

Property Type Required? Description
cellRenderer Func Content cell render function.
Function params: ({ dataKey, rowData, columnIndex }).
columnHeaderCellRenderer Func Column header cell render function.
Function params: ({ label, dataKey, columnIndex }).
dataKey String Field key containing data.
width Number Default column width in pixels.

<Row />

Use Row component only if you want to low modify your table rows. (See example ./srs/stories/rowRenderer.js)

Props

Property Type Required? Description
index Number Row number
style Object Row style
data Object Additional row data ({dataList, rowProps}) where dataList is table data and rowProps is additional row properties (see below)

Additional row properties

Additional row properties are contained in row's props.data.rowProps

Property Type Required? Description
columns array Table columns array
rowClassName Func Row className determine function.
Function params: (rowIndex).
getRowWidth Func Get row actual width.
getDataRowItem Func Function to get cell value.
Function params: ({rowData, dataKey}).
getColumnWidth Func Function to get column width.
Function params: (columnIndex).
getDataRow Func Function to get row data item.
Function params: (rowIndex).
onClick Func onClick row handler.
Function params: (event, { dataKey, columnIndex }).
onDoubleClick Func onDoubleClick row handler.
Function params: (event, { dataKey, columnIndex }).
onMouseOver Func onMouseOver row handler.
Function params: (event, { dataKey, columnIndex }).
onMouseOut Func onMouseOut row handler.
Function params: (event, { dataKey, columnIndex }).
onRightClick Func onRightClick row handler.
Function params: (event, { dataKey, columnIndex }).

License

MIT © avin

react-vt-table's People

Contributors

avin avatar stefanlazarevic 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

Watchers

 avatar  avatar  avatar  avatar

Forkers

thujone leesx

react-vt-table's Issues

rendering a custom row even if there are zero items to show

HI, I have a row of filters that I'm rendering immediately underneath the header row. It looks like this:

    if (index === 0) {
        return (
            <div
                {...{ style: { ...style, width: getRowWidth(), lineHeight: style.height + 'px' } }}
                className="CustomRow"
            >
              {filters.map( (filter, i) => {
                const filterProps = filter.props;
                const FilterComponent = filter.component;
                
                return (
                  <span {...{ style: { ...style, width: '100px', left: 100 * i + 'px', lineHeight: style.height + 'px' } }}>
                    <FilterComponent key={i} {...filter.props}>
                      {filter.props.children && filter.props.children}
                    </FilterComponent>
                  </span>
                )
                              
              })}
            </div>
        );
    }

The issue I have is that if I enter text into the filter that changes the number of items to render to 0, then the CustomRow I'm rendering also disappears. I'd like for that CustomRow to always stay put, even when there are no results to render. Is this possible?

how to define VTList height dynamically

Hi, I was wondering what the right way / best way is to modify the height of a VTList dynamically. My situation is that I never want to show the overflow-y scrollbar. In my table, the user can specify how many items they would like to see per page: 10, 25, 50, 100 per page. So if I have 10 items per page and each item is 50px in height, I can set the table height to ~550px (adding 50px for the header row). But if the user changes the items per page to 100, I don't the overflow-y scrollbar to appear. Instead, I want to change the height of the table to 5050px, and send the user back to page 1 if they weren't on it already. Should I do it programatically through the

component settings -- or is that even possible?

'Immutable' as a dependency

Not sure why it didn't install it when I installed the react-vt-table component, but 'Immutable' added as a dev dependency of this library. Or at least mentioned in the README.

Running react-vt-table on Reacat 17.x

Running react-tv-table on react 17.x throws the following warnings an errors:

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://reactjs.org/link/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://reactjs.org/link/derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 18.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: Draggable
Warning: componentWillUpdate has been renamed, and is not recommended for use. See https://reactjs.org/link/unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 18.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: Table
Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Draggable which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-node
div
DraggableCore@http://localhost:3000/static/js/bundle.js:199250:21
Draggable@http://localhost:3000/static/js/bundle.js:199628:21
ColumnResizer@http://localhost:3000/static/js/bundle.js:689849:35
div
div
Header@http://localhost:3000/static/js/bundle.js:689896:29
div
Table@http://localhost:3000/static/js/bundle.js:690228:30
div
AutoSizer@http://localhost:3000/static/js/bundle.js:689630:19
__WEBPACK_DEFAULT_EXPORT__@http://localhost:3000/static/js/bundle.js:22831:7
div
TryOut
Route@http://localhost:3000/static/js/bundle.js:682879:29
div
div
MainContent@http://localhost:3000/static/js/bundle.js:976:7
AppBox
Route@http://localhost:3000/static/js/bundle.js:682879:29
PrivateRoute@http://localhost:3000/static/js/bundle.js:1229:7
Switch@http://localhost:3000/static/js/bundle.js:683081:29
Router@http://localhost:3000/static/js/bundle.js:682510:30
BrowserRouter@http://localhost:3000/static/js/bundle.js:682132:35
App@http://localhost:3000/static/js/bundle.js:350:7
ConnectFunction@http://localhost:3000/static/js/bundle.js:678800:68
ConfirmProvider@http://localhost:3000/static/js/bundle.js:161744:18
InnerThemeProvider@http://localhost:3000/static/js/bundle.js:69986:70
ThemeProvider@http://localhost:3000/static/js/bundle.js:68831:7
ThemeProvider@http://localhost:3000/static/js/bundle.js:70008:7
StyledEngineProvider@http://localhost:3000/static/js/bundle.js:69016:7
Provider@http://localhost:3000/static/js/bundle.js:678512:15

Is there any chance of getting rid of this? Thanks, and the library is great :)

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.