Results 1 to 4 of 4

Thread: Selected records from json stream fro store model

  1. #1
    Ext JS Premium Member
    Join Date
    Dec 2010
    Posts
    2
    Vote Rating
    0
      0  

    Arrow Selected records from json stream fro store model

    Hi,

    I am in a migration of an app from ExtJS 3 to 6... I know, hell. But now I'm stucked in a problem transferring function which is a reading from a JSON data source.
    The old app works as:
    - a json store created with an url to the json data source
    - the data source provides more data than I need
    - the json store has the fields config value, which limits what fields are in the resulted record

    It worked as it described above. I see the fields parameter still exists in extjs 6, i use it, but the record i get after the store loads, contains all the unnecessary fields. It is wrong for me beause i populate a form using that record and it overwrites fields that i don't want.

    An example:

    JSON:
    Code:
    {data:[{field1:val1,field2:val2,field3:val3,field4:val4}]}
    The old code, where rec has only field1 and field2:

    Code:
    var store = new Ext.data.JsonStore({
        url: 'datasource.php',    
        root: "data",
        autoLoad: true,
        fields: ['field1', 'field2'],
        listeners: {
            load: function(ds, rec){
                console.log(rec);
            }
        }
    });
    The new ExtJS 6 code where unfortunetly rec has field1, field2, field3, field4:

    Code:
    var store = new Ext.data.JsonStore({
                proxy: {
                    type: 'ajax',
                    method: 'POST',
                    url: 'datasource.php',
                    reader: {
                        rootProperty: "data",
                        type: 'json'
                    }
                },
                fields: ['field1', 'field2'],
                autoLoad: true,
                listeners: {
                    load: function(ds, rec){
                        console.log(rec);
                    }
                }
            });
    Can anybody help me solve this problem? Thanks.

  2. #2
    Sencha Premium User
    Join Date
    Jan 2009
    Posts
    424
    Answers
    18
    Vote Rating
    240
      1  

    Default

    According to the docs for the fields config option -

    Fields will automatically be created at read time for any for any keys in the data passed to the Model's proxy's Ext.data.reader.Reader whose name is not explicitly configured in the fields config.
    So this is now the expected behavior. I didn't see a built-in way to turn it off. If you need this, I think your best option would be to create your own subclass of the json reader (or override it for all json readers) and override the getResponseData method to only return the data you want.

    https://docs.sencha.com/extjs/6.6.0/...etResponseData

    I feel your pain in that I still have 2.x apps running. If you're looking at upgrading from such an old version, you might also look at the MVC and MVVM architecture they've introduced. Redoing the architecture is a pain, but it can save you code. For example, if you bind attributes in the view model to the values in form fields, you have no need to load them explicitly.

  3. #3
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,145
    Answers
    741
    Vote Rating
    985
      1  

    Default

    Here's a naive example of how you might do it:

    https://fiddle.sencha.com/#view/editor&fiddle/2mkh
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #4
    Ext JS Premium Member
    Join Date
    Dec 2010
    Posts
    2
    Vote Rating
    0
      0  

    Default

    Thanks for all the answers. I already have workaround, but i hoped there is a built-in solution what i may missed.
    evant's reader workaround is better than mine, i may implement it - you have an extra thank you!

Similar Threads

  1. Replies: 5
    Last Post: 16 Mar 2017, 11:39 AM
  2. [FIXED] Selected records are unbound of store after store is refreshed
    By ragzovskii in forum Ext:Bugs
    Replies: 1
    Last Post: 21 Aug 2014, 1:59 PM
  3. Replies: 11
    Last Post: 31 Oct 2012, 3:31 AM
  4. Replies: 3
    Last Post: 25 Oct 2012, 9:29 PM
  5. Possible to store selected records between pages with grid?
    By lagos.tout in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 10 Mar 2008, 10:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •