×

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 Error Boundaries

React Error Boundaries In the past, the errors of JavaScript within the components were used to corrupt the internal state of react and cause it to emit the cryptic errors on the next...

3 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 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 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.

Features of ReactJS

ReactJS Features As of now, within the developers, ReactJS is gaining much popularity as the best JavaScript framework. It is crucial for the front-end ecosystem. There are some of the crucial features of ReactJS that are...

2 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.

How to use React Context

React Context React Context is used to pass the data through the component tree without passing the props down manually at the every level. In React Application, the data is passed in a top-down approach...

4 minutes read.

React Refs

React Refs The word ‘Refs’ is an abbreviation of ‘References’ in React. It is as similar as Keys in React. Refs are a function in React which is used for accessing the DOM element and...

7 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.

React JSX

React JSX As we know, all of the React components include a render function. The Render function specifies the HTML output of a React component. JSX is an acronym of JavaScript extension that...

3 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 State

React 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 time. The change...

3 minutes read.

React Bootstrap

React Bootstrap React has a widely used JavaScript framework for creating web applications, and Bootstrap has become the most popular CSS framework. Single-page apps have become popular from the last few...

9 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.

React Component API

React Component API It is a top-level API. It provides reusability to the code in the application and makes it completely individual. It has several methods for: Creating Elements.Transforming Elements.Fragments. Now, we are explaining the three...

2 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 Environment Setup Step by Step

React Environment Setup This section will provide you the information about how to set up an environment for the successful development of ReactJS application: Pre-Requisite for ReactJS NodeJS and NPMReact and React DOMWebpackBabel There are two...

5 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 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 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.