GithubHelp home page GithubHelp logo

samrith-s / sticky-react-table Goto Github PK

View Code? Open in Web Editor NEW
14.0 7.0 5.0 2.12 MB

A sticky positioned table built for React

Home Page: http://samrith-s.github.io/sticky-react-table

License: MIT License

JavaScript 86.77% CSS 12.48% HTML 0.75%
react reactjs table component react16

sticky-react-table's Introduction

Sticky React Table

Travis npm package GitHub issues GitHub stars GitHub license

Many large-scale applications require the use of tables somewhere, if not everywhere. Many a times the requirements for these tables are quite complex and difficult to manage. Sticky React Table aims to solve all of these problems for React developers, with a host of features including customizable cells, rows, and headers, column switching, column filtering, sorting, virtualization, column resizing, etc. All of that, provided in a declarative manner, and built ground-up, especially for React!

The package is still under development. We are working actively to get this package to a stable release as soon as possible. Please do not use this package in any production application.

Table of Contents

Getting Started

Installing Sticky React Table is as simple as using your favourite package manager (ex. yarn or npm).

For NPM:

npm install sticky-react-table

For Yarn:

yarn add sticky-react-table

Basic Usage

The sticky-react-table package exposes two major components: Table and Column.

Consider a sample data set:

[
  {
    "name": "John Doe",
    "age": 24,
    "location": "Chicago",
    "occupation": "Research Analyst"
  },
  {
    "name": "Jane Delaney",
    "age": 22,
    "location": "London",
    "occupation": "Software Developer"
  },
  {
    "name": "Nishant Singh",
    "age": 28,
    "location": "Mumbai",
    "occupation": "Business Developer"
  }
]

The simplest implementation of the above data as an Sticky React Table would be like so:

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Table, Column } from 'sticky-react-table';

import data from './data.json';

class MyTable extends Component {
  render() {
    return (
      <Table data={data}>
        <Column title="Name" width={200} dataKey="name" />
        <Column title="Age" width={50} dataKey="age" />
        <Column title="Occupation" width={200} dataKey="occupation" />
        <Column title="Location" width={150} dataKey="location" />
        <Column title="Top Skill" width={150} dataKey="topSkill" />
      </Table>
    );
  }
}

const rootElement = document.getElementById('root');
ReactDOM.render(<MyTable />, rootElement);

From here on, you can customize the cell, row or header renderers, add custom classes, style it however you need.

If you use SASS as a pre-processor, two default themes are provided: light and dark. To use the themes, simply import the relevant theme.

  • Light Theme: sticky-react-table/lib/themes/light.scss
  • Dark Theme: sticky-react-table/lib/themes/dark.scss

Important Properties

Sticky React Table supports a host of properties which allow you to completely customize the look and feel of the table. You can find the properties supported by the two major components of the package.

Table

Properties:

Property Type Default Description
children Column undefined The Column component. It does not accept any other children.
fixed Number undefined The number of fixed columns in the table.
rowSelection Bool true This property determines whether checkbox column is rendered.
idKey String id A key used to uniquely identify data.
rowClassName String undefined Custom classes for a row.
headerClassName String undefined Custom classes for the header row.
selectedRows Array undefined An array of ids to make the table a controlled component.
infiniteScrollTotalCount Number undefined Total number of rows which can be loaded using infinite loader.
infiniteScrollLoadMore Function undefined Invoked when a new page is requested when using infinite loader.
infiniteScrollThreshold Number 10 The number of rows before the end of the table to trigger a call.
infiniteScrollLoaderRowCount Number 5 The number of additional rows to display at the bottom for loading.
infiniteScrollPageSize Number 30 A number of rows loaded with each portion.
infiniteScrollCellRenderer Node or Function undefined Custom content to display within cells of additional loader rows.

Callbacks:

Name Description Parameters
onSort Pass a custom sorting functionality. Array of column data
onRowCheck Handle checking of a row. Id of the checked row or "all" if all rows are checked.
checkboxRenderer Custom renderer for checkbox column. Cell Props
rowRenderer Custom row renderer Row Props
ref Get ref of inner component. Reference to inner component

Column

Properties:

Property Type Default Description
dataKey String undefined The data key for the value to be rendered into the cell
title String undefined The title to be displayed in the header if no renderer is specified.
width Number 0 The absolute width of the column.
className Array or String undefined A custom class for the cell.
alwaysVisible Bool false Defines whether the column should always be visible.
filterAlignment String left Whether the filter should be aligned to the left or right of header cell.

Callbacks:

Name Description Parameters
cellRenderer A custom cell renderer to modify the default rendering. Cell Props
headerRenderer A custom header cell renderer to modify the default rendering. Cell Props
filterRenderer A custom header filter renderer to add column filters. Filter Props
filterTrigger A custom header filter trigger renderer for showing the column filters. None

Cell Props

The cell props allow you to access the data for the entire row, and some additional information about the cell. This particularly helps in customizing the cell, based on the information or the data for that row.

Every custom render function you use across the table, ex. headerRenderer and cellRenderer, get these props as the parameters of the renderer.

propTypes = {
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
  rowData: PropTypes.object,
  cellData: PropTypes.any,
  isChecked: PropTypes.bool
  isCheckbox: PropTypes.bool,
  style: PropTypes.object,
  title: PropTypes.string, // Only available in headerRenderer
  isAllSelected: PropTypes.bool // Only available in headerRenderer
}

Filter Props

The filter props allows you to access the data for the table and the dataKey of a column. This helps in creating a custom filters in any column, based on the data of the table.

propTypes = {
  data: PropTypes.array,
  dataKey: PropTypes.string
};

Row Props

The row props allow you to access the data for the row, and some additional methods to help you render the defaults. Only the rowRenderer function gets access to row props.

propTypes = {
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
  rowIndex: PropTypes.number,
  rowData: PropTypes.object,
  columns: PropTypes.array,
  isChecked: PropTypes.bool,
  renderColumns: PropTypes.func,
  defaultRowRenderer: PropTypes.func
}

Gotchas

  • While using headerRenderer, always render an inline element if you have either sorting or column filters in the cell. Otherwise the alignment will break.

Contributing

Since we are still developing and this is a fairly large project, we would ❤️ contributions! We are looking for people who echo our sentiments and share the same idea about Sticky React Table.

Check out the CONTRIBUTING.md file for details.

Issues

For any issues or queries you might have about the table, please feel free to create one in the issues section.

Roadmap

We started developing Sticky React Table due to a lot of issues we faced while implementing tables in our application, with React. Leading up to 1.0.0, we plan on supporting the following features:

  • ✅ Fixed Columns
  • ✅ Fixed Header
  • ✅ Column Resizing
  • ✅ Column Switching
  • ✅ Column Reordering
  • ✅ Column Sorting
  • ✅ Column Filtering
  • ✅ Cell Renderer
  • ✅ Row Renderer
  • ✅ Header Renderer
  • ✅ Row Selection
  • ✅ Infinite Scrolling
  • ✅ Column resizing based on length of value (a la Excel)
  • ❌ Keyboard Navigation (as per Gmail)
  • ❌ More events:
    • Key Up
    • Key Down
    • Focus
    • Blur
    • Scroll

In the future, we plan on implementing the following:

  • Virtualization
  • Better support for custom classes

Features at no point will we build:

  • Row resizing or native subrow rendering (both of these can be achieved using a custom row renderer)

License

This project is under the MIT License. You can checkout the LICENSE file for info.

Copyright © 2018.

sticky-react-table's People

Contributors

dmitriy-kudelko avatar samrith-s avatar sonandrew avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sticky-react-table's Issues

Help: Documentation

What help is needed?
The project is massively lacking in documentation. We would love it if the community contributed to writing the documentation of this project, as it can be quite complicated.

What is the timeline for completion?
No timeline for the documentation to be completed, ideally all of it should be in sync with the first production release of the project.

How to go about it?
Just create PRs referencing this issue and update parts of the documents. Do not worry about conflicts as we will resolve them and merge it.

Documentation structure:

The structure of the document should include the following:

  • Getting started
  • Basic Usage
  • Options to customize
  • Renderers
    • Cell Renderers
    • Header Renderers
    • Row Renderers
  • Props
  • Advanced Usage Examples (using renderers and async data loading)

Rewrite column selection, visibility and sorting functions

Which part of the code do you think needs an improvement?
The defaultSort, handleColumnVisibilityChange and handleRowCheck could improvements.

Why do you think it needs to be improved?

  • Right now the problem with these functions is that they are cluttering the main Table component.
  • We should ideally avoid this and move these functions to the utils folder.
  • The transformations undertaken by these functions are very difficult to read and have multiple iterations. We should try and reduce these iterations and optimise their performance.

How critical is this improvement?
8. Primarily because of how it is sub-optimal. Secondly, over-populating the Table components makes it reading a bit difficult.

What will this help us achieve?
This will help us achieve a better performing table, where the above mentioned actions are standard interactions performed by a user.

Help: Tests

What help is needed?
We need to write tests for some default behaviour expected of the table. Also need code coverage and integrating coveralls.

What is the timeline for completion?
No specific timeline. Ideally, though, should be completed by the time the v1 hits the shelves.

Infinite scroll loader being displayed when table data filtered

Describe the bug
With the Column Filter feature built in #8, we can now filter table data by selecting values from a dropdown. This results in infiniteLoader being displayed indefinitely.

To Reproduce
Steps to reproduce the behaviour:

  1. Click on F on any column.
  2. Select a filter value

Expected behavior
If filtered data does not require scroll, we should not show loading data.

Screenshots
image

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome, Safari, Firefox
  • Version: latest

Additional context
I think we should redo the infinite loading logic and make it simpler.

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.