×

React Table

React Table

The table represents an arrangement that organizes the information in the form of rows and columns. The table is mainly used for storing and displaying the data within a structured format.

Features of React Table

There are several features of the react-table that are listed as follows:

  • It is lightly weighted as approx. 11 kb (it only requires 2kb more for styles).
  • It is customizable.
  • It is controllable by using optional props and callbacks.
  • It includes client-side and server-side pagination.
  • It also includes filters.
  • It has a minimal design, and it is also easily themeable.

Installation of React Table

First, we create the react app by using the following command. Now, open your command prompt and navigate to the react folder and run the following command:

Installation of React Table

npx create-react-app myreactapp

Installation of React Table

Now, we have to install the react-table. We can install the react-table by running the following npm command in the command prompt:

npm install react-table

npm install react-table

Once it gets installed, you have to import the react-table into the react-component. Now, open your src/App.js file and add the following:

importReactTablefrom"react-table";
Let’s understand the React-table by using the following example:
import React, { Component } from 'react'; 
import ReactTable from "react-table"; 
import "react-table/react-table.css"; 
class App extends Component { 
render() { 
const tableData = [{ 
name: 'Aman', 
age: 20,
course:'BCA'
},{ 
name: 'Anubhav', 
age: 21,
course:'MCA' 
},{ 
name: 'Akash', 
age: 22,
course:'MCA' 
},{ 
name: 'Amit', 
age: 20,
course:'BCA' 
},{ 
name: 'Keshav', 
age: 21,
course:'MCA' 
},{ 
name: 'Kailash', 
age: 20,
course:'B.sc' 
},{ 
name: 'Govind', 
age: 20,
course:'B.com' 
},{ 
name: 'Raghav', 
age: 21, 
course:'MCA' 
}] 
const columns = [{ 
Header: 'Name', 
accessor: 'name' 
},{ 
Header: 'Age', 
accessor: 'age' 
},{ 
Header: 'Course', 
accessor: 'course' 
}] 
return ( 
) } }

Output:

understand the React-table

On changing the dropdown, you will get the corresponding output, such as if we are selecting four rows, then the output will be:

On changing the dropdown

On selecting the six rows, the output will be:

On selecting the six rows

And on selecting eight rows, the output will be:

And on selecting eight rows

Related Topics

React Router

What is React Router? Routing is a process by which a user can direct to different pages based on their actions and requests. ReactJS router is generally used to develop single...

10 minutes read.

Difference Between State and Props in React

Comparison between State and Props State The state is an updatable structure which is used for containing data or information about the component. The state in a component can be changed over...

2 minutes read.

React Higher-Order Components

React Higher-Order Components In short form, Higher-Order Components are represented as HOC. The Higher-order component is an advanced technique to use component logic. HOC is a function that takes the component and returns the new...

2 minutes read.

React Component Life-Cycle

React Component Life-Cycle In ReactJS, the creation process of every component includes several lifecycle methods. These methods, together stated as component's lifecycle. Four phases of the component's life cycle are as...

4 minutes read.

Pros and Cons of ReactJS

Pros and Cons of ReactJS There are various advantages, and disadvantages of ReactJS are as follows: Benefits of ReactJS 1. Easy to Learn and Use: ReactJS is very easy to use and learn. It has a good...

3 minutes read.

ReactJS Versions

ReactJS Versions The Complete set of release history of ReactJS is elaborated as follows. The complete set of full documentation of recent releases is on GitHub. S.noVersionRelease DateExplanation1.0.3.029/05/2013Initially released for public.2.0.4.029/07/2013Supporting comments...

4 minutes read.

React Components

React Components Former, the developers used to write more than thousands of lines of code to develop a single-page application. These applications follow the structure of traditional DOM, and it was very challenging to make...

2 minutes read.

React Constructors

What is constructor? The constructor is a method that is used for initializing the state of the object in the class. It calls automatically during the creation of an object in...

4 minutes read.

React Portals

React Portals React portals were introduced by React 16.0 in September 2017. It gives you a way to render the element outside of the component hierarchy, i.e., within a separate component. Before React 16.0, it...

3 minutes read.

React Native vs ReactJS

Difference between React Native and ReactJS React Native React Native is also an open-source JavaScript framework that is used for the development of a mobile application for iOS Android and Windows. It...

6 minutes read.

React Lists

React Lists Lists are used for displaying the data in an ordered format and mainly used to display the menus on websites. The creating of lists in React is as similar...

2 minutes read.

React Map

React Map The map() is the standard function of JavaScript, which can be called at any array. The map() method is used for traversing and displaying a list of the similar objects of...

2 minutes read.

React Code Splitting

React Code Splitting React Code Splitting is the procedure of splitting the bundle files by which the files get easily loaded on the webpage. The react application bundles the files by using...

4 minutes read.

React Redux

How to Use Redux with React Hooks It is an open-source library of JavaScript which is used for managing the application state. React uses the Redux to build the user interface....

5 minutes read.

React Fragments

React Fragments The fragments in React are introduced from the 16.2 and above versions. Fragments allow you to group a list of child elements without adding any extra node in the DOM. In React,...

2 minutes read.

React Keys

React Keys A key can be defined as a unique identifier. In React, it is used for identifying the items that have changed, deleted, and updated from the lists. React Keys are helpful...

3 minutes read.

React Props

React Props A prop is an abbreviation of ‘properties.' State and props are mainly different from each other because props are immutable. Props are the read-only components. It is the object that stores the attribute...

3 minutes read.

React Hooks

React Hooks The Hooks were introduced in React 16.8. By using React Hooks, you can use the state and other features of the React without writing a class. Hooks do not work within the classes....

5 minutes read.

React Forms

React Forms Forms are the important part of any web application. It allows the interaction of the user with the app as well as the gathering of the information from the...

3 minutes read.

Difference between Controlled and Uncontrolled component in ReactJs

Controlled Component In the controlled component, the input of the form element is handled by the component rather than the DOM. Controlled components have the functions that govern the data, which...

2 minutes read.