Git Product home page Git Product logo

react_table_package's Introduction

david-mi-react-table v3.6.1

Description

A react package to create a table with integrated functionalities

Functionalities

Sorting data

When clicking on a column heading, you can arrange data in 3 ways

  • Sorting in ascending order
  • Sorting in descending order
  • default (non sorted, like it was originally)

Filtering data

When writing text on the search input, only rows who have cells that includes written text will be displayed

  • Sorting state is being kept after filtering

Paginating data

A pagination system is being used to navigate through the pages and limiting amount of displayed data on the screen

  • Go to next page
  • Go to previous page
  • Go to page specified by button (if there is a lot of data, limiting amount of displayed page buttons)
  • Go to page specified in "Go to" input

Retrieving data information

A section is made on the bottom left to display informations about the data being processed

  • You can visualize the entries range of the current page (Example : Showing 41 to 50 of 500 entries)
  • You can see the number of total entries, ignoring filtering

Installation

npm i david-mi-react-table

Example

import "david-mi-react-table/style.css";
import { Table } from "david-mi-react-table";

const columns = [
  { title: "Title", accessor: "title" },
  { title: "Rating (/20)", accessor: "rating" },
];

const rows = [
  { title: "ARK: Survival Evolved", rating: 12 },
  { title: "Trials Fusion", rating: 17 },
  { title: "Counter-Strike: Source", rating: 18 },
  { title: "Dungeon Defenders", rating: 16 },
  { title: "Trials Evolution Gold Edition", rating: 18 },
  { title: "Borderlands 2", rating: 18 },
  { title: "Portal 2", rating: 19 },
  { title: "Deep Rock Galactic", rating: 15 },
  { title: "Counter-Strike 2", rating: 15 },
  { title: "Borderlands GOTY", rating: 13.5 },
  { title: "Fallout 4", rating: 16 },
  { title: "Orcs Must Die! 2", rating: 16 },
  { title: "Borderlands: The Pre-Sequel", rating: 15 },
];

function App() {
  return (
    <Table 
      columns={columns}
      rows={rows} 
     />
  );
}

Result

img

Typescript Example

You can import Row and Column types to reinforce typing They accept a generic wich are keys of a row data schema

You can avoid using Row and Column types aswell, is it not required but recommended as you will get more precise warnings

import "david-mi-react-table/style.css";
import { Table, Row, Column } from "david-mi-react-table";

interface Game {
  title: string;
  rating: number;
}

const columns: Column<keyof Game>[] = [
  { title: "Title", accessor: "title" },
  { title: "Rating (/20)", accessor: "rating" },
];

const rows: Row<keyof Game>[] = [
  { title: "ARK: Survival Evolved", rating: 12 },
  { title: "Trials Fusion", rating: 17 },
  { title: "Counter-Strike: Source", rating: 18 },
  { title: "Dungeon Defenders", rating: 16 },
  { title: "Trials Evolution Gold Edition", rating: 18 },
  { title: "Borderlands 2", rating: 18 },
  { title: "Portal 2", rating: 19 },
  { title: "Deep Rock Galactic", rating: 15 },
  { title: "Counter-Strike 2", rating: 15 },
  { title: "Borderlands GOTY", rating: 13.5 },
  { title: "Fallout 4", rating: 16 },
  { title: "Orcs Must Die! 2", rating: 16 },
  { title: "Borderlands: The Pre-Sequel", rating: 15 },
];

function App() {
  return <Table columns={columns} rows={rows} />;
}

Props

Props type Description Required
rows Array rows to display on table true
columns Array columns heads true
classNames Object custom class names to apply on table container and it's elements false
colors Object custom colors to apply on table false

Column

Key name Type Description Required
title string title to display on column head true
accessor string accessor to target the correct cells true
{ 
  /* title that will be displayed at column head*/
  title: "First name",
  /* reference to a row key */
  accessor: firstName
}

Row

Key name Type Description Required
< key > string or number row value true
{ 
  /* row key with it's value */
  firstName: "David"
}

classNames

Key Type Description Required
container string main container false
tableContainer string table wrapper false
table string table element false
pageSelect string select page menu on top left false
search string search menu on top right false
informations string informations part on bottom left false
navigation string navigation menu on bottom right false
footer string informations and navigation menus wrapper false

colors

Key Type Description Required
hover string Table hover (heading, rows and buttons) false
button string Table buttons false
buttonCurrentPage string Table button matching the current page number false
buttonDisabled string Table disabled buttons false
sortArrow string sorting arrows on heading false
sortArrowActive string the arrow representing the direction of current sorted column, if chosen (asc or desc. ) false
head string table heading false

Types

interface Column<T> {
  title: string,
  accessor: T
}

type Row<T extends string> = {
  [key in T]: string | number
}

interface ClassNames {
  container?: string
  tableContainer?: string
  table?: string
  pageSelect?: string
  search?: string
  informations?: string
  navigation?: string
  footer?: string
}

interface Colors {
  hover?: string,
  button?: string
  buttonCurrentPage?: string
  buttonDisabled?: string
  sortArrow?: string
  sortArrowActive?: string
  head?: string
}

export interface TableProps<T extends string> {
  columns: Column<T>[],
  rows: Row<T>[]
  classNames?: ClassNames
  colors?: Colors
}

CodeSandbox demos

React : Link

React Typescript : Link

NextJs : Link

react_table_package's People

Contributors

david-mi avatar

Watchers

 avatar

react_table_package's Issues

add filtering logic

  • add search component
  • Handle filter logic in useTable
  • show message if no data has been found

initialize my package

  • add Employee interface
  • install my employees-generator package
  • generate fake empolyees datas from package
  • prepare Table to receive columns and rows

Add tests

  • Setup test configuration with vitests and react-testing-library
  • Add tests for displaying data
  • Add tests for sorting
  • Add tests for Table props errors
  • Add tests for filtering
  • Add tests for Pagination
  • Add tests for classNames Table props
  • Add unit tests for Tbody
  • Add unit tests in SortIcon
  • Add utils in tests to share utility test functions

add Pagination

  • add button to get on next page
  • add button to get back to previous page
  • add input to write a page to go
  • add Infos about displayed data / pages
  • add select menu to change page size

Improve README

  • show full example with all functionnalities
  • Talk about classNames in table props

Add mock files

  • remove dataTable file
  • add columns mock file
  • add rows mock file

Change no results div postion

  • noResults condition should be used to display no result message or Tbody
    change from this
    <div>
      <Search setSearchInput={setSearchInput} />
      {noResults
        ? <h1>No results found.</h1>
        : (
          <table>
            <Thead sort={sort} setSort={setSort} columns={columns} />
            <Tbody rowsData={rowsData} columns={columns} />
          </table>
        )
      }
    </div>

to this

<div>
  <table>
    <Search setSearchInput={setSearchInput} />
    <Thead sort={sort} setSort={setSort} columns={columns} />

    {noResults 
    ? <h1>No results found.</h1>
    : <Tbody rowsData={rowsData} columns={columns} />
    }
  </table>
</div>;

React-Table API

  • Install React Table package
  • Implement basic table with data from jQuery app

Optimize hooks performances

  • call usePagination inside useTable to avoid unnecessary rerender
  • Instead of using useEffects to watch userInput/sort, use callback functions to update all needed states at once

add classNames

  • add classNames props to Table, to give user the possibility to add custom classNames on Table elements

configure setup for building

  • configure package.json for lib
  • configure tsconfig.json
  • add Table component in index file
  • modify build command in root package.json

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.