Git Product home page Git Product logo

basictablenext's Introduction

Basic Table in NextJS

This is an example of very basic table component for NextJs. This demonstrates how to:

  • create a component
  • use a component
  • pass data to OnClick functions (on row or column click)
  • use simple get axios JSON API
  • use https://jsonplaceholder.typicode.com fake online REST API for testing
  • inline style jsx

Features

  • Choose which columns to display
  • Choose which columns to make sortable
  • No pagination
  • Specify which OnClick Function to execute for column header or row click

Idea

It started with the question, how to pass a row object in a table to onClick handler in NextJs? Couple of options :

<tr onClick={this.handleTheClick}>

Above code won't pass row object to handleTheClick.

But if you do something like this:

<tr onClick={() => this.handleTheClick(row)}> 

Then on every render of row a new function would be created.

Other option is

<tr onClick={this.handleTheClick} data-item='{row}'>

and then in handleTheClick function, get data-item like:

handleTheClick (e) {
    const row = e.target.getAttribute('data-item');
}

The better approach is what is used in this BasicTable component. Create a separate component and pass the row object as a property of Table component Look at BasicTable, TableHeader and TableBody components

How to use?

Setup

Install and Run

Install it and run:

npm install
npm run dev
# or
yarn
yarn dev

Configuration

Todos

  • External SCSS
  • Pagination

Contributing

Contributions are welcome

License

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.