Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconSoftware Developmentbreadcumb forward arrow iconHow to Make Ant Design Table (AntD) in React JS

How to Make Ant Design Table (AntD) in React JS

Last updated:
22nd Jun, 2023
Views
Read Time
7 Mins
share image icon
In this article
Chevron in toc
View All
How to Make Ant Design Table (AntD) in React JS

Introduction to Ant Design Table (AntD)

Ant Design Table, or AntD Table, is a powerful and feature-rich component that the Ant Design framework provides for ReactJS. Its comprehensive functionalities make it an excellent choice for displaying and manipulating tabular data in web applications. 

Enhance your skills with Ant Design Table by signing up for a Full Stack Software Development Bootcamp.

Setting Up an Ant React Table

Follow these steps to set up an Ant Design Table in a ReactJS project:

  • Install Ant Design: npm install antd
  • Import necessary components: import { Table } from ‘antd’;
  • Use the <Table> component, providing data and column configuration as props.
  • Customise the dataSource and columns arrays.
  • Render the Table component in your React component hierarchy.

Check out our free technology courses to get an edge over the competition.

Ads of upGrad blog

Creating a Basic Ant Table

Follow these steps to create a basic React Ant Design Table:

  • Install Ant Design and import the components and styles required.
  • Define the Table’s data source and column configuration:
  • Render the Table component in your React component:
  • Use the <MyTable /> component to display the Table wherever you want.
  • Explore additional Ant Design (React) features and options to customise it further.

Customising Table Columns and Rows

Customise Ant Design Tables and rows with ReactJS using various AntD properties and components. Follow the steps below:

  • Install Ant Design and import the components and styles required.
  • Create a custom Table component with columns and data.
  • Customise the Table appearance using properties like rowClassName.
  • Define custom CSS styles for Table rows.

Sharpen your AntD skills with a comprehensive course like the Master of Science in Computer Science from LJMU.

Sorting and Filtering Data in AntD Table

Use the library’s built-in features and properties to enable sorting and filtering in an Ant Design (AntD) Table by following the given steps:

  • Import the necessary components and styles from Ant Design.
  • Create a state variable to store the filtered data.
  • Define your Table’s columns and add the sorter and filter properties.
  • Define the data for your Table.
  • Render the Table component with the defined columns, data, and filtering properties.
  • Implement the onChange event handler to sort and filter.
  • When sorting is triggered, use the sorter object to determine the column key and sorting order. Sort the data accordingly and update the state with the sorted data.
  • Use the filter object to determine the column key and filter value once filtering is triggered. Filter the data based on the provided value and update the state with the filtered data.
  • If no sorting or filtering is applied, reset the filtered data state to an empty array.
  • Render the custom Table component in your application.

Paginating and Grouping Data in AntD Table

Use the pagination and row grouping features provided by AntD to paginate and group data in an Ant Design (AntD) Table using ReactJS. 

  • Import the necessary components and styles from AntD
  • Define the columns and data for your Table.
  • Set up pagination:
  • Define a state variable to store the current page number and items per page.
  • Implement an onChange event handler to update the state when the page changes or the items per page are modified.
  • Render the Pagination component, passing the current page and the total number of items as props.
  • Group rows in the Table:
  • Define a rowKey for each row to ensure uniqueness.
  • Use the rowSpan property to specify the number of rows a particular cell should span within a group.
  • Render the Table:
  • Pass the columns and data to the Table component as props.
  • Use the pagination prop to enable pagination, passing the current page and items per page state variables.
  • For row grouping, use the rowSpan property within columns where grouping is required.

Adding Selections and Actions to AntD Table

To add selections and actions to an Ant Design (AntD) Table using ReactJS:

  • Import the necessary components and styles from AntD.
  • Define a state variable to store the selected row keys.
  • Use the rowSelection property in the Table component to enable row selection, passing the selected row keys and an onChange event handler.
  • Implement the onChange event handler to update the selected row keys state.
  • Add additional columns to the Table component to display actions or checkboxes for each row.
  • Implement action or checkbox event handlers to perform desired actions based on the selected rows.
  • Customise the actions or checkboxes display using the render or customRender property in the columns.
  • Optionally, customise the appearance of selected rows using the rowClassName property.
  • Render the Table component in your application.

Implementing Search and Highlighting in AntD Table

To implement search functionality and highlighting in an Ant Design (AntD) Table using ReactJS:

  • Define a state variable to store the search input value and a filtered data state variable.
  • Implement an onSearch event handler to update the search input value state and filter the data based on the input value.
  • Render a search input component and bind it to the onSearch event handler.
  • Display the filtered rows in the Table using the filtered data state variable.
  • Implement a highlighting mechanism in the Table:
  • Define a function that takes the search input value and cell data as arguments and returns the highlighted text.
  • In the column’s render or customRender property, apply the highlighting function to the cell data using JSX.
  • Render the Table component in your application.

Adding Loading and Error States to AntD Table

To add loading and error states to an Ant Design (AntD) Table using ReactJS:

  • Define a state variable to track the loading state and an error state variable.
  • Set the initial loading state to true and the error state to false.
  • Use an asynchronous function or API call to fetch the data for the Table.
  • Within the function or API call, update the loading state accordingly.
  • If an error occurs during the data fetching process, update the error state to true.
  • Render the Table component with the loading prop set to the loading state variable.
  • Optionally, handle the error state in the component’s rendering logic by displaying an error message or taking appropriate actions.
  • Customise the loading state appearance using the Spin component or other AntD-provided loading indicators.
  • Render the Table component and handle your application’s error and loading states.

Integrating AntD Table with Backend APIs

To integrate an Ant Design (AntD) Table with backend APIs in ReactJS:

  • Define a state variable to store the data fetched from the backend API.
  • Use a lifecycle method (e.g., useEffect) or an event handler to make an API request to fetch the data from the backend.
  • Within the API request, update the state variable with the fetched data.
  • Render the Table component with the data obtained from the backend API.
  • Customise the columns based on the data structure received from the API.
  • Optionally, handle error scenarios and loading states while fetching data from the backend.
  • Customise the Table appearance and behaviour using AntD’s properties, such as pagination, sorting, and filtering, to match the API response and user requirements.
  • Implement event handlers or callback functions to handle actions performed on the Table, such as editing or deleting data.
  • Make API requests to update the backend data based on the user’s actions.

Explore our Popular Software Engineering Courses

Best Practices and Tips for Working with AntD Table

Follow these best practices and tips when working with Ant Design (AntD) Table:

  • Assign unique keys to columns for improved performance and to avoid rendering issues.
  • Implement server-side pagination and filtering to reduce the amount of data fetched and improve loading times.
  • Use memorisation techniques like React.memo or useMemo to optimise rendering for column cells or custom components.
  • Employ virtual scrolling or lazy loading techniques for Tables with many rows to enhance performance.
  • Use built-in row selection and action features to handle bulk operations efficiently.
  • Leverage AntD’s APIs and styling options to customise Table appearance and behaviour to match your design and requirements.
  • Ensure the Table’s accessibility by providing appropriate labels, keyboard navigation, and ARIA attributes.

Future Updates and Developments in AntD Table

Ads of upGrad blog

Since its inception, AntD has been periodically optimised with regular updates, bug fixes and new features. With the latest update of AntD version 5.6.2 released on 19th June 2023, this Table component has received many features, style addons, bug fixes and Table fixes. 

As for future updates, AntD is set to receive weekly bug fixes and minor version monthly releases. 

Conclusion

Creating an Ant Design (AntD) Table in ReactJS is a powerful way to display and manage tabular data in your applications. Follow the provided steps and leverage the extensive features and customisation options offered by AntD to create interactive and efficient Tables, enhancing user experience and streamlining data presentation. 

Register for upGrad’s Executive PG Programme in Full Stack Development from IIITB and start building your feature-rich Tables with AntD.

Profile

Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.

Frequently Asked Questions (FAQs)

1How to add filters to an AntD Table?

To add filters to an AntD Table, define the filter options for each column and use the filter property in the Table's columns configuration.

2How can an Ant design Table be made responsive?

An Ant Design Table can be made responsive using CSS media queries and responsive design techniques.

3How to style an AntD Table?

To style an AntD Table, customise the Table's appearance by using the provided styling options.

Explore Free Courses

Suggested Blogs

Top 14 Technical Courses to Get a Job in IT Field in India [2024]
90952
In this Article, you will learn about top 14 technical courses to get a job in IT. Software Development Data Science Machine Learning Blockchain Mana
Read More

by upGrad

15 Jul 2024

25 Best Django Project Ideas &#038; Topics For Beginners [2024]
143863
What is a Django Project? Django projects with source code are a collection of configurations and files that help with the development of website app
Read More

by Kechit Goyal

11 Jul 2024

Must Read 50 OOPs Interview Questions &#038; Answers For Freshers &#038; Experienced [2024]
124781
Attending a programming interview and wondering what are all the OOP interview questions and discussions you will go through? Before attending an inte
Read More

by Rohan Vats

04 Jul 2024

Understanding Exception Hierarchy in Java Explained
16879
The term ‘Exception’ is short for “exceptional event.” In Java, an Exception is essentially an event that occurs during the ex
Read More

by Pavan Vadapalli

04 Jul 2024

33 Best Computer Science Project Ideas &#038; Topics For Beginners [Latest 2024]
198249
Summary: In this article, you will learn 33 Interesting Computer Science Project Ideas & Topics For Beginners (2024). Best Computer Science Proje
Read More

by Pavan Vadapalli

03 Jul 2024

Loose Coupling vs Tight Coupling in Java: Difference Between Loose Coupling &#038; Tight Coupling
65177
In this article, I aim to provide a profound understanding of coupling in Java, shedding light on its various types through real-world examples, inclu
Read More

by Rohan Vats

02 Jul 2024

Top 58 Coding Interview Questions &amp; Answers 2024 [For Freshers &amp; Experienced]
44560
In coding interviews, a solid understanding of fundamental data structures like arrays, binary trees, hash tables, and linked lists is crucial. Combin
Read More

by Sriram

26 Jun 2024

Top 10 Features &#038; Characteristics of Cloud Computing in 2024
16289
Cloud computing has become very popular these days. Businesses are expanding worldwide as they heavily rely on data. Cloud computing is the only solut
Read More

by Pavan Vadapalli

24 Jun 2024

Top 10 Interesting Engineering Projects Ideas &#038; Topics in 2024
43094
Greetings, fellow engineers! As someone deeply immersed in the world of innovation and problem-solving, I’m excited to share some captivating en
Read More

by Rohit Sharma

13 Jun 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon