Open In App

ReactJS UI Ant Design Table Component

Ant Design Library has this component pre-built, and it is very easy to integrate as well. ReactJS UI Ant Design Table Component is used to display rows of data. It is used to display data in the form of table format. We can use the following approach in ReactJS to use the Ant Design Table Component.

Table Props:



Column Props:

ColumnGroup Props:



 

Creating React Application And Installing Module:

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.




import React from 'react'
import "antd/dist/antd.css";
import { Table } from 'antd';
  
export default function App() {
  
    // Sample Data for the table
    const dataSource = [
        { key: '1', username: 'Gourav', age: 10 },
        { key: '2', username: 'Kartik', age: 20 },
        { key: '3', username: 'Madhu', age: 30 },
        { key: '4', username: 'Karu', age: 40 },
        { key: '5', username: 'Dinesh', age: 50 },
    ];
  
    // Sample Columns data
    const columns = [
        {
            title: 'Username',
            dataIndex: 'username',
            key: 'username',
        },
        {
            title: 'Age',
            dataIndex: 'age',
            key: 'age',
        },
    ];
  
    return (
        <div style={{
            display: 'block', width: 700, padding: 30
        }}>
            <h4>ReactJS Ant-Design Table Component</h4>
            <Table dataSource={dataSource} columns={columns} />
        </div>
    );
}

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://ant.design/components/table/


Article Tags :