Filtering Array within a store record

192 Views Asked by At

I have a JSON object in a store that looks like the below. I am dynamically filtering values based on selections in a property grid. I am not filtering on the top level values (personName, primaryRole etc) but instead I want to drill down into the array of periods I have. For instance, I want to filter each record in the store for "periods" > "periodName".

I'm not sure how to do this, as it's not something I have come across before. Using combo.getStore().filter('periodName', gridvalues.periodName); does not work as it doesn't find the periodName, and I cannot simply use periods.periodName unfortunately.

"id": "531b0633-c9f5-4cbe-be69-5df4944b6e9b",
        "personName": "Ben",
        "primaryRole": "SWE",
        "secondaryRole": "SWE",
        "periods": [
            {
                "personName": "Ben",
                "periodName": "Week 24",
                "teamName": "Tango",
                "experience": 2,
                "periodNumber": 24,
                "id": "71d514c2-a39f-40b7-af9e-51fbf30b2a48"
            },
            {
                "personName": "Ben",
                "periodName": "Week 25",
                "teamName": "-",
                "experience": "-",
                "periodNumber": 25,
                "id": "49505fb2-97df-4f45-a11d-bb22c110a422"
            },
            {
                "personName": "Ben",
                "periodName": "Week 26",
                "teamName": "-",
                "experience": "-",
                "periodNumber": 26,
                "id": "97f2b272-c23c-4320-a1ce-09dadf0c6b5d"
            },
"id": "7037ad16-dcbe-4326-8547-65108c03c874",
        "personName": "Luke",
        "primaryRole": "Product Owner",
        "secondaryRole": "SWE",
        "periods": [
            {
                "personName": "Luke",
                "periodName": "Week 24",
                "teamName": "Tango",
                "experience": 3,
                "periodNumber": 24,
                "id": "e3184bef-c330-4219-ae21-8b65efcde77c"
            },
            {
                "personName": "Luke",
                "periodName": "Week 25",
                "teamName": "-",
                "experience": "-",
                "periodNumber": 25,
                "id": "f431af7b-8060-40d2-8464-af533d943363"
            },

This is a record from my store:

id: "531b0633-c9f5-4cbe-be69-5df4944b6e9b"periodNumber: 0periods: Array[16]0: Objectexperience: 2id: "71d514c2-a39f-40b7-af9e-51fbf30b2a48"periodName: "Week 24"periodNumber: 24personName: "Ben"teamName: "Tango"__proto__: Object1: Object2: Object3: Object4: Object5: Object6: Object7: Object8: Object9: Object10: Object11: Object12: Object13: Object14: Object15: Objectlength: 16__proto__: Array[0]personName: "Ben"primaryRole: "SWE"secondaryRole: "SWE"
1

There are 1 best solutions below

4
On BEST ANSWER

Use the addFilter function in your controller:

combo.getStore().addFilter({property: 'yourProperty', value: 'valueToFilter'});

For more info:

http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.data.Store-method-addFilter