I have a JSON array of objects that looks like this:
[{
"vehicleid": 3,
"name": "Teste2VDD",
"brand": "Scania",
"model": "6x2",
"class": "class1",
"region": "Curitiba",
"customer": "Cliente A",
"customerid": 1
},
{
"vehicleid": 1,
"name": "Teste1",
"brand": "Volkswagen",
"model": "5x3",
"class": "class1",
"region": "Curitiba",
"customer": "Cliente A",
"customerid": 1
},
{
"vehicleid": 2,
"name": "Teste3VDD",
"brand": "Volkswagen",
"model": "6x2",
"class": "class2",
"region": "Curitiba",
"customer": "Cliente A",
"customerid": 1
},
{
"vehicleid": 5,
"name": "Teste4VDD",
"brand": "Scania",
"model": "6x4",
"class": "class2",
"region": "Curitiba",
"customer": "Novo",
"customerid": 2
},
{
"vehicleid": 6,
"name": "Teste5VDD",
"brand": "Scania",
"model": "5x5",
"class": "class2",
"region": "Curitiba",
"customer": "Novo",
"customerid": 2
},
{
"vehicleid": 7,
"name": "veiculo",
"brand": "Scania",
"model": "5x4",
"class": "class1",
"region": "Porto Alegre",
"customer": "Cliente3",
"customerid": 3
},
{
"vehicleid": 8,
"name": "veiculo65",
"brand": "Volkswagen",
"model": "5x4",
"class": "class3",
"region": "Porto Alegre",
"customer": "Cliente3",
"customerid": 3
},
{
"vehicleid": 11,
"name": "Veiculo de teste h",
"brand": "Scania",
"model": "5x3",
"class": "class3",
"region": "Belo Horizonte",
"customer": "Cliente de teste h",
"customerid": 10
},
{
"vehicleid": 13,
"name": "Nome 3",
"brand": "Volkswagen",
"model": "6x3",
"class": "class3",
"region": "Belo Horizonte",
"customer": "Cliente de teste h",
"customerid": 10
},
{
"vehicleid": 12,
"name": "Nome",
"brand": "Volvo",
"model": "6x3",
"class": "class3",
"region": "Belo Horizonte",
"customer": "Cliente de teste h",
"customerid": 10
}]
I am looking to create a tree hierarchy based on certain filter parameters.
The first level will always be the customer, and the last level will always be the vehicle.
For example:
1 - Filtering the tree by Customer would result in the tree being ordered by Customer, with each customer's children representing their associated Vehicles:
[{
"attr": {
"type": "customer"
},
"text": "Cliente A",
"children": [
{
"id": 1,
"text": "Teste1",
"attr": {
"type": "vehicle",
"title": "Teste1"
}
},
{
"id": 2,
"text": "Teste3VDD",
"attr": {
"type": "vehicle",
"title": "Teste3VDD"
}
},
{
"id": 3,
"text": "Teste2VDD",
"attr": {
"type": "vehicle",
"title": "Teste2VDD"
}
}
]
},
{
"attr": {
"type": "customer"
},
"text": "Novo",
"children": [
{
"id": 5,
"text": "Teste4VDD",
"attr": {
"type": "vehicle",
"title": "Teste4VDD"
}
},
{
"id": 6,
"text": "Teste5VDD",
"attr": {
"type": "vehicle",
"title": "Teste5VDD"
}
}
]
},
{
"attr": {
"type": "customer"
},
"text": "Cliente3",
"children": [
{
"id": 7,
"text": "veiculo",
"attr": {
"type": "vehicle",
"title": "veiculo"
}
},
{
"id": 8,
"text": "veiculo65",
"attr": {
"type": "vehicle",
"title": "veiculo65"
}
}
]
},
{
"attr": {
"type": "customer"
},
"text": "Cliente",
"children": [
{
"id": 11,
"text": "Veiculo de teste h",
"attr": {
"type": "vehicle",
"title": "Veiculo de teste h"
}
},
{
"id": 12,
"text": "Nome",
"attr": {
"type": "vehicle",
"title": "Nome"
}
},
{
"id": 13,
"text": "Nome 3",
"attr": {
"type": "vehicle",
"title": "Nome 3"
}
}
]
}]
2 - Filtering the tree by Brand would result in the tree being ordered by Customer, with each customer's children representing their associated Brands, followed by the Vehicles under each Brand.
3 - Filtering the tree by both Brand and Model would lead to the tree being ordered by Customer, with each customer's branches showing the respective Brands they own, then the Models under those Brands, and finally the Vehicles for each Model.
4 - If filtering by Brand, Model, and Region", the hierarchy would start at Customer, then show the Brands they are associated with, followed by Models, Regions, and finally Vehicles.
This pattern continues based on different combinations of filters chosen.
If anyone has an idea or solution for implementing this, I would greatly appreciate it!
Thank you in advance!