How to use x-grid-data-generator Module in ReactJS ?
Whenever we want to generate some data and build demos for the grid Component, we can use the x-grid-data-generator module. It has a large variety of data set to play around. DataGrid Component helps in displaying the information in a grid-like format of rows and columns. We can use the following approach in ReactJS to use the x-grid-data-generator module.
Approach: Follow these simple steps in order to use the x-grid-data-generator module in ReactJS. In the following example, we have imported the useDemoData function from this module and then used a common data set from this function by passing the DataSet name along with rowLength and maxColumns attribute. And after that, we have passed the data object to our DataGrid Component for displaying it to the user.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
Step 3: After creating the ReactJS application, Install the material-ui module using the following command:
npm install @material-ui/data-grid npm install @material-ui/x-grid-data-generator
Project Structure: It will look like the following.
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
Step to Run Application: Run the application using the following command from the root directory of the project:
Output: Now open your browser and go to http://localhost:3000/, you will see the following output: