2

I have a group of filters that is an Reactive Forms Object. I’ve taken the property values of the object and pushed it into an array.

// original filters object {claim_number: null, status: "Approved", patient: null, service_date: null}

let filterArr = []
Object.keys(this.filtersForm.value).forEach(filter => {
    filterArr.push(this.filtersForm.value[filter])
    // filterArr [null, “Approved, null, null]
})

I have a table that is comprised of an array of objects like the following:

"claims":[  
        {  
            "billed_amount":141.78,
            "claim_number": "6596594-0",
            "location":"University Hospital",
            "member_id":"A1234567890",
            "status":{  
                "label":"Approved",
                "value": "Approved"
            }
        },
        {  
            "billed_amount":341.70,
            "claim_number": "2196524-3",
            "location":"Springfield Hospital",
            "member_id":"B1234567890",
            "status":{  
                "label":"Pending",
                "value":"Pending"
            }
        },
        {  
            "billed_amount":111.70,
            "claim_number": "1233514-5",
            "location":"Springfield Hospital",
            "member_id":"C1234567890",
            "status":{  
                "label":"Pending",
                "value":"Pending"
            }
        },
        {
            // ...etc
        }
    ]

I am trying to loop through each row and put the property values in an array, one for each row so I can filter them against filterArr. How can I do that?

My question is similar to this post (From an array of objects, extract value of a property as array ), with the key difference being that I'm trying to create an array per object.

Each object represents a row in a table that I am trying to dynamically filter. So I can't have values from different rows being put into one array.

4
  • 2
    What are expected results? Commented Nov 29, 2018 at 21:25
  • yeah, would be good to see an example of desired output Commented Nov 29, 2018 at 21:31
  • I want the values of each row to be in it's own array. So I can filter each row against the filterArr. Something like claimArr[1]=[141.78, 6596594-0, "University Hospital", etc], claimArr[2]=[341.70, 2196524-3, "Springfield Hospital", etc], Commented Nov 29, 2018 at 21:51
  • I believe I need to use a for loop. for( var i = 0; i < this.rows.length; i++ ) {} I'm trying to filter the table now. Commented Nov 29, 2018 at 21:52

2 Answers 2

2

According to your desired result, I think you can use ES6 functions.

const result = yourTable.map(element => Object.values(element));

Using map() function, you go through all elements, and extract from each object its values.

Sign up to request clarification or add additional context in comments.

7 Comments

Yes, this along with the for loop I put in my comments works, thank you. Do you have any idea how to take this a step further and filter the filterArr by the claimArr?
Do you mean that that for every element "Approved" in filterArr, we should extract the claimArr element of a corresponding index? Please clarify on simple examples if I'm wrong.
We don't need to extract it just flag it. Also for any values for patient, claim_number, or service_date. I'm building a dynamic filter so I'm trying to match the values from the first array in any of the other arrays. If there is a match I want to flag it and update the view to just show those arrays.
Please show some quick examples of the desired result. What do you mean by 'flagging' them?
tablefilter.com/case-sensitive.html Please look at this URL. My first array is the filters up top. Each row below is in an array. When I type something and hit enter if the text I typed in the filter matches any of the text in the row items they are returned. Is that clear?
|
0

Unsure what you want to include in your output but the below will loop through an array and return an array to the filter function

const output = claimTable["claims"].map((claim) => {
    return claim
}).filter((claim) => {
    return claim.billed_amount > 100
})

The above will loop through the claims and 'convert' to an array. The filter will return that claim for all true conditions (in this case, if the billed amount is greater than 100).

This article goes over this and adds a bit more to it.

1 Comment

I'm filtering a table. I have a working version, but I need it to be dynamic because I have several tables with different filter options. FilterArr is the values of the filter. ClaimArr is the value of the table rows. I want to filter ClaimArr by FilterArr and return the rows that match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.