Mastering the integration of an array of objects with the ej2 Syncfusion data grid

Trying to figure out how to map a complex array of objects into the ej2 Syncfusion React data grid.

Here is an example of my array:

[
{
    "id_team": "1",,
    "team_name": "Testing",
    "adviser": "Dummy"
    "causes": [
        {
            "cause_id": "01.55",
            "cause_name": "Testing 1"
        },
        {
            "cause_id": "01.57",
            "cause_name": "Testing 2"
        },
        {
            "cause_id": "01.59",
            "cause_name": "Testing 3"
        }
    ],
    "controls": [
        {
            "control_id": "01.444",
            "control_name": "Tested 1",
            "control_level": "Strong"
        },
        {
            "control_id": "01.445",
            "control_name": "Tested 2",
            "control_level": "Weak"
        },
        {
            "control_id": "01.446",
            "control_name": "Tested 3",
            "control_level": "Weak"
        }
    ]
}
]

I would like to display this table format in the ej2 Syncfusion Data Grid for React:

Table Preview:
https://i.stack.imgur.com/w6G6S.png

Answer №1

uncertain about whether to use object.property or object["property"]

array.map(object => (
    <p>{object["id_team"]}</p>
    ......
    {object["penyebab"].map(penyObj => (
        <p>{penyObj["id_penyebab"]} - {penyObj["nama_penyebab"]}</p>
    )
    {object["kontrol"].map(idKontrol => (
        <p>{idKontrol["id_kontrol"]}</p>
    )
    {object["kontrol"].map(namaKontrol => (
        <p>{namKontrol["nama_kontrol"]}</p>
    )
    {object["kontrol"].map(lvlKontrol => (
        <p>{lvlKontrol["lvl_kontrol"]}</p>
    )
))

how it is displayed in a grid/flex is left to your discretion

Answer №2

The default functionality of the EJ2 Grid column is limited to supporting number, string, date, dateTime, Boolean, and checkbox type values. It does not have built-in support for array type values. For more information, please refer to the documentation found at .

To display an array of values in a Grid column, you can utilize the columnTemplate/valueAccessor features. However, keep in mind that this is purely for visual representation purposes only. You will not be able to perform standard Grid actions such as Sorting, Filtering, Searching, Grouping, etc., on columns with array type values due to the limitations of EJ2 Grid.

Do you specifically need to display arrays of values in penyebab and control columns solely for visual purposes? Or are you looking to actively manipulate and interact with these columns (penyebab and control) through data actions like Sorting, Filtering, Searching, Grouping, etc.?

Answer №3

To efficiently map your array of objects, utilize the columns and dataSource attributes within the Syncfusion React Data Grid.

Start by defining the necessary columns for the grid. Each object representing a column should be included in an array of column objects using the columns property. Specify columns for id_team, nama_team, advisor, penyebab, and kontrol.

// Define the columns
const columns = [
  { field: 'id_team', headerText: 'ID Team' },
  { field: 'nama_team', headerText: 'Nama Team' },
  { field: 'adviser', headerText: 'Adviser' },
  { field: 'penyebab', headerText: 'Penyebab', cellTemplate: (rowData: any) => {
      return rowData.penyebab.map((penyebab: any) => penyebab.nama_penyebab).join(', ');
  }},
  { field: 'kontrol', headerText: 'Kontrol', cellTemplate: (rowData: any) => {
      return rowData.kontrol.map((kontrol: any) => kontrol.nama_kontrol).join(', ');
  }},
];

Once defined, render the grid with:

// Render the grid
return (
  <Grid dataSource={dataSource} allowPaging={true} pageSettings={{ pageSize: 10 }}>
    <ColumnsDirective>
      {columns.map((column) => <ColumnDirective {...column} key={column.field} />)}
    </ColumnsDirective>
  </Grid>
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty retrieving user information from the backend because of a blank screen

Utilizing ReactJs in the frontend, I have been attempting to retrieve logged-in user data from the backend (PHP) using axios.get. A condition is set that if nothing is returned from the backend, the user will be redirected back to the login page. This redi ...

Using React-Router-Native to send an image as a parameter

I am encountering an issue while attempting to pass an image as a parameter in react-router-native and retrieve the data from location.state. Typically, I use the following code to display an image: import Icon from '../image/icon.png'; <Vie ...

Setting a random number as an id in the constructor in Next JS can be achieved by generating a

What steps can be taken to resolve the error message displayed below? Error: The text content does not match the HTML rendered by the server. For more information, visit: https://nextjs.org/docs/messages/react-hydration-error Provided below is the code i ...

Difficulty in making Materialize.css column match the height of the entire row

Utilizing React.js, Materialize.css, and certain MaterialUI components in collaboration to build a website. Developed a header (React component, basic div with title and logout button) for the site using a Materialize.css "grid". Issue: The react compone ...

How to clear input fields in Ant Design ReactJS components

Utilizing the form list component from antd in my react.js project https://ant.design/components/form/#Form.List I have a basic form list set up where I can easily add or remove fields. At times, I need to reset the form and remove any additional items t ...

The size of my React Native app is significantly larger than expected once installed

I recently developed a React Native app, and while the release APK size is only 28 MBs, I was shocked to see that the storage size is a whopping 62 MBs. I am desperately looking for a solution as I need to deliver this project soon. Please help me resolv ...

Error Alert: React Native object cannot be used as a React child within JSON, leading to an Invariant Violation

When using React-Native: To start, here is the example code of a json file: Any placeholders marked with "..." are for string values that are not relevant to the question. [ { "id": "question1" "label": "..." "option": [ { "order": 1, "name": "..."}, ...

Display a component inside a Drawer using Material-UI Lists

It seems like the information should be self-explanatory in the documentation, but a key part of the List code is abstracted to another file without explanation. This leaves me with questions and that's why I'm reaching out for help. My goal is ...

No contains operator found in Material UI Datagrid

While working on a project, I utilized Material UI's datagrid and successfully implemented filters such as contains and isEmpty. However, I am struggling to find information on how to create a notContains filter. Does Material UI natively support this ...

react doesn't display any content on the render

After creating a navbar component in React, I imported it into my app.js as shown below: import react from "react"; const NavBar = import('./NavBar') function App() { return <NavBar /> } export default App Then, I imported ...

Is there a way to remove the ring shadow in TailwindCSS?

Here is a visual representation of the issue I'm facing (refer to the image): Check out the Image After inspecting with Chrome, it seems like the problem is connected to --tw-ring-shadow. I attempted to use classes like ring-0 and ring-offset-0 (men ...

React: Remove a particular row from the table

I am currently working on a project that involves building a table component. Each row in this table is also a separate component. class FormulaBuilder extends Component { constructor(props) { super(props); this.state = ...

Eliminate choices in one SELECT menu based on the option selected in another SELECT

const data = [ { "id":1, "name":"Type X", "description":"Description Type X" }, { "id":2, "name":"Type Y", "description": ...

Determining the installation duration of the React Native screen

Several questions have been asked about this topic, but none of them seem to have a definitive answer. What I am looking to do is calculate the time it takes to navigate to a screen. The timer will start here: navigation.navigate("SomePage") Essentially, ...

Variations of a particular software package are necessary

My current project requires Expo, React, and React-Native as dependencies. The configuration in the package.jason file looks like this: "main": "node_modules/expo/AppEntry.js", "private": true, "dependencies": { "expo": "^28.0.0", "expo-three": "^ ...

Experiencing difficulties while trying to showcase a PDF within the Expo Go app

I am currently developing a React Native application that requires the display of PDF files. I have tried two different methods, one using react-native-webview and the other with react-native-pdf, but both approaches are presenting challenges. This is how ...

Steps to incorporate multiple line selections in a select dropdown using Material UI

I am trying to create a Material UI Select where the options (MenuItem's) can accommodate long texts. For example, here is what one option may look like: "A new building or one that has undergone a major renovation within the last two years, which on ...

Steps for unit testing a component with a ref property

Is there a way to perform unit testing on a component with a ref prop? I am encountering the following error message: ● Should render › should render TypeError: Cannot add property current, object is not extensible I tried referencing another que ...

An issue occurred during the hydration process, causing the entire root to switch to client rendering since the error occurred outside of a Suspense boundary

I've started seeing some errors and warnings: Error: An error occurred while hydrating. Since it happened outside of a Suspense boundary, the entire root will switch to client rendering. Error: Hydration failed due to initial UI not matching what was ...

What is the best way to move the Grid upward when the above content is not visible?

Let me demonstrate what I have been working on. Currently, I am creating a weather application to explore the functionalities of https://material-ui.com/. I am attempting to prototype an animation inspired by Google Flights, which can be seen here: https: ...