Most of the applications have data representation in tabular format with some 7 to 8 columns. But when we want to show the huge amount of data in table which has a columns more than 30 or N columns, some time we also get the scenario like sub-columns of one column, so write a code for such a table is really pain for developer cause if we go with the traditional HTML table then we have to handle all scenarios manually and it also a time consuming, and again if we want change in some column then again we have to follow so many steps.
Normal HTML tags also render the data slow, So in the article, we are going to see how we can overcome all these problems with AG-Grid.
This article assumes that you have practical knowledge about React JS and javascript. And working with npm libraries.
This article is going to be covering how to set-up and implement AG-Grid in reactJS and also how to customize columns.
We will follow the steps below in order :-
Now let’s start the integration process.
npm i ag-grid-react
We’ve installed a third party library ag-grid-react in our project. Now we are good at implementing tables.
npm i --save ag-grid-community ag-grid-react react-dom-factories
import { AgGridReact } from 'ag-grid-react'; import 'ag-grid-community/dist/styles/ag-grid.css'; import 'ag-grid-community/dist/styles/ag-theme-balham.css';
So first we need to declare the columns, it’s a totally key value pair. We have to declare a column name and field for that and then just assign the key of the JSON object that we want to display in the column. In the below code snippets columnDefs is the definition of the column and rowDefs is JSON data to display in the table.
(Note: Column can be defined in 3 ways, we are using a GridOptions way cause the most feasible way of definition.)
We will take two examples of displaying a normal column and display column with sub-column structure.
A. Normal column definition
constructor(props) { super(props); this.state = { columnDefs: [ { headerName: "Make", field: "make"}, { headerName: "Model", field: "model" }, { headerName: "Price", field: "price" } ], rowData: [ { make: "Toyota", model: "Celica", price: 35000 }, { make: "Ford", model: "Mondeo", price: 32000 }, { make: "Porsche", model: "Boxster", price: 72000 } ] } }
B. Sub-column structure
Make111, make222 are the sub columns of the Make column.
constructor(props) { super(props); this.state = { columnDefs: [ { headerName: "Make", children: [ { headerName: 'make 111', field: 'make111' }, { headerName: 'make 222', field: 'make222', }, { headerName: 'make 333', field: 'make333', } ] }, { headerName: "Model", field: "model" }, { headerName: "Price", field: "price" } ], rowData: [ { make: "Toyota", model: "Celica", price: 35000, make111: 'Japan', make222: '#kls3fd', make333: '88987' }, { make: "Ford", model: "Mondeo", price: 32000, make111: 'USA', make222: '#fgf64', make333: '009234' }, { make: "Porsche", model: "Boxter", price: 72000, make111: 'Germany', make222: '#jklkm67', make333: '57587' } ] } }
Now just simply use the AgGridReact component to render the table, pass the column definition and row data to the component as props.
render() { return ( <div className="ag-theme-balham" style={{ height: '500px', width: '100%' }} > <AgGridReact columnDefs={this.state.columnDefs} rowData={this.state.rowData}> </AgGridReact> </div> ) }
1. Normal column definition
2. Sub-column structure
We can also sort the data as per specific column, if we want to sort price columns then we just need to make price column sortable, we can do this by just passing props in the column definition, there so many features for ag-grid can check in documentation.
{ headerName: "Price", field: "price", sortable: true }
If we look, there are so many libraries like Ag-Grid SlickGrid, dhtmlxSpreadsheet, Handsontable and a lot more. Now the question is why Ag-Grid? Ag-Grid renders data faster as compared to others and also it’s very efficient with large data. Some libraries don’t provide some features like pagination, custom arrangement, etc. But Ag-Grid covers all those features that we required.
Ag-Grid provides so many features like filter, pagination, sorting a data, rearrange the columns by using drag and drop. We can customize the theme of the grid, and it’s also very easy to create our own UI for Ag-Grid. Ag-Grid is very easy to implement and understand. We can also export the data from Ag-Grid to spreadsheet.
When we have displayed a large amount of data in a table which has so many rows and columns. Don’t use Ag-Grid if you have just 2 to 4 columns with no sub-column structure and less number of rows this will be a bad programming practice.
Use an Ag-Grid when you have N number of columns with N number of rows or data which have sub-column structure like if we have 1 column name Participent and under that there are sub-columns name, language, country. Can see in the below example image or in the demo link. In an easy way when we have to display a complex data structure is table then use Ag-Grid.
From the above article, we covered how to integrate the ag-grid-react library into our react application and also cover how to customize the column for sorting the data. When we can use Ag-Grid and when not.
How to Effectively Hire and Manage a Remote Team of Developers.
Download NowMindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
Mindbowser has truly been foundational in my journey from concept to design and onto that final launch phase.
CEO, KickSnap
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork