inovua / reactdatagrid

Empower Your Data with the best React Data Grid there is
https://reactdatagrid.io
Other
3.45k stars 57 forks source link

Nested object's properties map to columns #352

Closed robozb closed 1 year ago

robozb commented 1 year ago

Dear Developers,

How can I map a nested object's properies to data grid colums?

For example this:

{
    "id": 65,
    "employee": {
        "id": 24,
        "name": "Van Jast",
        "email": "freddy.beatty@hotmail.com",
        "address": "37204 Toni Islands",
        "city": "Blaketown",
        "state": "Massachusetts",
        "zipCode": "03395-2948",
        "phone": "035.260.8830",
    },
    "hotel": {
        "id": 491,
        "companyName": "Treutel Group",
        "address": "535 Sonya Wall",
        "city": "Lake Basil",
        "state": "Wisconsin",
        "zipCode": "59389-9353",
        "firstWorkDay": "MONDAY"
    },
    "hourlyRate": 45.3127,
    "overTime": 67.969,
    "beginning": "2023-01-21",
    "ending": "2023-03-09",
    "commitmentSignedUp": true,
    "commitmentAmount": 126.836,
    "commitmentDays": 42
}

Thank you so much!

robozb commented 1 year ago

OK, I could solve it :) on this way:

{ 
    name: "employee_id", header: "Employee ID", visible: true, width: 200, 
    render: ({data}) => {
        return data.employee.id;
    }
},

{ 
    name: "employee_name", header: "Employee NAME", visible: true, width: 200, 
    render: ({data}) => {
        return data.employee.name;
    }
},   

{ 
    name: "hotel_id", header: "Hotel ID", visible: true, width: 200, 
    render: ({data}) => {
        return data.hotel.id;
    }
},     

{ 
    name: "hotel_companyName", header: "Hotel Company Name", visible: true, width: 200, 
    render: ({data}) => {
        return data.hotel.companyName;
    }
},

image

robozb commented 1 year ago

May I ask, is there any simpler way to do this than using render methods?