1. #1
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Mumbai, India
    Posts
    191
    Answers
    10
    Vote Rating
    0
    bomslang has a little shameless behaviour in the past

      0  

    Exclamation Unanswered: Dynamically setting fields[ ] array for List Component

    Unanswered: Dynamically setting fields[ ] array for List Component


    Hi,

    I have a list component, which has a store, model and it's corresponding fields[ ] array.

    I am trying to read the data values from a nested json, so I am using custom reader and trying to access data[ ] for store and fieldArray[ ] for fields of model via custom Accessor function.

    I have 2 buttons, clicking on each button changes the data of list dynamically ( & of course will change it's fields[ ] as well)

    So, basically I need to design a list component for whom data[ ] and fields[ ] will change according to certain actions performed.

    Sample Json:-

    data[ ] => Actual List Data
    fieldArray[ ] => fields for Model of List Store

    Code:
    {
        "success": true,
        "total": 2,
        "data": [
            {
                "id": 1,
                "company": "3m Co",
                "price": 71.72,
                "change": 0.02,
                "pct": 0.03,
                "updated": "9/1/2012"
            },
            {
                "id": 2,
                "company": "Alcoa Inc",
                "price": 29.01,
                "change": 0.42,
                "pct": 1.47,
                "updated": "9/1/2012"
            },
        ],
        "fieldArray": [
            'id',
            'company',
            'price',
            'pct',
            'updated'
        ]
    }
    PS : One thing that I tried was setting fields returned from custom accessor function on load( ) of list store, but list wasn't getting updated. But at console.log( ) I could see the new fields[ ] array being set.

    How to achieve this ?

  2. #2
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    Maybe try refreshing the list that's associated with the store?

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Mumbai, India
    Posts
    191
    Answers
    10
    Vote Rating
    0
    bomslang has a little shameless behaviour in the past

      0  

    Default


    That doesn't help.

    First of all - Can I do like this ? I mean, I am setting new fields[ ] array for list inside list load( ) event.

    Is this correct ? If not, what is the alternative ?

  4. #4
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    An alternative would be to use two Models, I think. I've never done what you are explaining here.

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Mumbai, India
    Posts
    191
    Answers
    10
    Vote Rating
    0
    bomslang has a little shameless behaviour in the past

      0  

    Default


    Ok, but what if I had several sets of data.

    According to your answer, I could have then hundred's of different model.

    What could be the optimal solution ?

    Note : I want to have fields[ ] dynamically set at any cost, I can't hard-code them.

  6. #6
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    You would need to refill the model with the new records, or use the set method, if you change the fields and reload the store. Changing the fields only changes whats available to use for a record, but it doesn't change any of the instances already created.

    I don't know any optimal way of doing this. Maybe someone else does.

    I found a link that could help, but its all I could find:
    http://stackoverflow.com/questions/10789433/extend-ext-data-model-add-fields-dynamically


Thread Participants: 1

Tags for this Thread