I am using a DevExtreme React Grid Tree. My initial call only populates the root row, each additional sub row is applied on click. I am having issues while applying the sub row data when there are many nested table rows. I need an efficient way to find the correct parent row and add the next nested array. Here is the table data with one nested row I have already added.
[
{
"area": "Artesia",
"list_id": 45,
"rowId": 158324175700860960,
"parentRowId": 0,
"items": [
{
"area": "Other",
"list_id": 15003,
"rowId": 158324179061139520,
"parentRowId": 158324175700860960
}
]
},
{
"area": "Corpus Christi",
"list_id": 60,
"rowId": 158324175700847800,
"parentRowId": 0,
"items": []
},
{
"area": "Midland",
"list_id": 10,
"rowId": 158324175700867700,
"parentRowId": 0,
"items": [
{
"area": "Delaware Basin",
"list_id": 11001,
"rowId": 158324181266273440,
"parentRowId": 158324175700867700,
"items": []
}
]
},
{
"area": "San Antonio",
"list_id": 63,
"rowId": 158324175700814050,
"parentRowId": 0,
"items": []
}
]
After clicking on the Midland row I applied the API return data as a nested array item.
[
{
"area": "Delaware Basin",
"list_id": 11001,
"rowId": 158324181266273440,
"parentRowId": 158324175700867700,
"items": []
}
]
I need a function that can loop through the table data from the root level to unlimited nested rows. I match the data now by using the parentId to match the rowId.
// root table data with one nested row applied to Midland
const tableData = [
{
"area": "Artesia",
"list_id": 45,
"rowId": 158324175700860960,
"parentRowId": 0,
"items": [
{
"area": "Other",
"list_id": 15003,
"rowId": 158324179061139520,
"parentRowId": 158324175700860960
}
]
},
{
"area": "Corpus Christi",
"list_id": 60,
"rowId": 158324175700847800,
"parentRowId": 0,
"items": []
},
{
"area": "Midland",
"list_id": 10,
"rowId": 158324175700867700,
"parentRowId": 0,
"items": [
{
"area": "Delaware Basin",
"list_id": 11001,
"rowId": 158324181266273440,
"parentRowId": 158324175700867700,
"items": []
}
]
},
{
"area": "San Antonio",
"list_id": 63,
"rowId": 158324175700814050,
"parentRowId": 0,
"items": []
}
]
// return data from API after clicking on Delaware Basin
const returnData = [
{
"area": "Delaware Basin Nm",
"list_id": 11007,
"rowId": 158324182577224580,
"parentRowId": 158324181266273440
},
{
"area": "Delaware Basin Tx",
"list_id": 11002,
"rowId": 158324182577248960,
"parentRowId": 158324181266273440
}
]
function applyNestedData (tableData, returnData) {
}
applyNestedData(tableData, returnData)