Prime NG Table filter for nested Data

60 views Asked by At
const aa = [
    {
        "id":"1",
        "type":"type1",
        "created":{
            "createdDate":"day1",
            "createdVal":"val1"
        },
        "accountDetails":[{
            "userId":"user1",
            "userName":"userName1"
        }],
        "accountNumber":["1","11","111"]
    },
    {
        "id":"2",
        "type":"type2",
        "created":{
            "createdDate":"day2",
            "createdVal":"val2"
        },
        "accountDetails":[{
            "userId":"user2",
            "userName":"userName2"
        }],
        "accountNumber":["2","22","222"]
    },
    {
        "id":"3",
        "type":"type3",
        "created":{
            "createdDate":"day3",
            "createdVal":"val3"
        },
        "accountDetails":[{
            "userId":"user3",
            "userName":"userName3"
        }],
        "accountNumber":["3","33","333"]
    },
    {
        "id":"4",
        "type":"type4",
        "created":{
            "createdDate":"day4",
            "createdVal":"val4"
        },
        "accountDetails":[{
            "userId":"user4",
            "userName":"userName4"
        }],
        "accountNumber":["4","44","444"]
    },
    {
        "id":"48",
        "type":"type48",
        "created":{
            "createdDate":"day48",
            "createdVal":"val48"
        },
        "accountDetails":[{
            "userId":"user48",
            "userName":"userName48"
        },
        {
            "userId":"user49",
            "userName":"userName49"
        }],
        "accountNumber":["489","4849","4848489"]
    }
]

I have a data in above format. I am trying to use this data in prime ng table. table will have columns -type, createdDate,UserName and account Number. How to create columns with above data as data type is different for each column also for each column there will be input box to filter the data. for e.g in account number if I type 8 then it will display all records which contains account number with 8.

I tried filter logic but it doesnt work as there are different type of data

filterArray(event: any) { const val = event.target.value.trim().toLowerCase();

this.filteredArray = val === ""
  ? this.yourArray
  : this.yourArray.filter(item =>
      item.nestedProperty.nestedValue.toLowerCase().includes(val)
    );

}

0

There are 0 answers