Results 1 to 7 of 7

Thread: Ext.data.JsonReader & Ext.data.Record

  1. #1
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    North Italy
    Posts
    114
    Vote Rating
    1
      0  

    Question Ext.data.JsonReader & Ext.data.Record

    Hi people!
    A simple question (I'm falling in glass of water..)...how to recurse to the PK of Ext.data.JsonReader from a Ext.data.Record?
    I need to set disabled and readonly pk fields in a FormPanel when editing data...

    PHP Code:
    ...
        
    show: function(record){
          var 
    basicForm this.contForm();
          
    basicForm.loadRecord(record);
          
    this.record record;
          
    this.setBehavior();
          
    Ext.Window.prototype.show.apply(thisarguments);
        },
        
    setBehavior: function(){
          if (!
    this.record.phantom) {
            var 
    this.contForm().items;
            
    i.each(function(itemi){
              if (
    item.name in this.record.store.reader.jsonData.items[0].id) {
                
    item.disabled true;
                
    item.readOnly true;
              }
            }, 
    this);
          }
        }
    ... 
    Tnx All!
    Seek

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    119
      0  

    Default

    1. You should be using BasicForm.findField instead of iterating through the items collection (your solution doesn't work if you would use nested containers, e.g. a fieldset).
    2. Changing the disabled and readOnly properties doesn't make a component disabled or readOnly. You need to use the setDisabled and setReadOnly method!

  3. #3
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    North Italy
    Posts
    114
    Vote Rating
    1
      0  

    Default

    Thanks for your precious suggestions!
    What about finding the names/name of key field/fields directly from record data?

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    119
      0  

    Default

    You could use:
    Code:
    record.prototype.fields.each(function(field){
      var isPrimaryKey = <field is part of primary key>,
          comp = form.findField(field.name);
      if (comp) {
        comp.setDisabled(isPrimaryKey);
        comp.setReadOnly(isPrimaryKey);
      }
    });
    But you need some way to define what a primary key field is.

  5. #5
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    North Italy
    Posts
    114
    Vote Rating
    1
      0  

    Default

    Quote Originally Posted by Condor View Post
    But you need some way to define what a primary key field is.
    It's the idProperty the reader

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    119
      0  

    Default

    There is no easy way to determine which field was used as idProperty (idProperty can be a function, field can have a function as mapping etc.).
    I suggest you simply mark fields as being part of the primary key, e.g.
    Code:
    fields:[
      {name: 'field1', primary: true},
      {name: 'field2', primary: true},
      {name: 'field3'},
      ...
    ]
    and then use it in the code above:
    Code:
    var isPrimaryKey = field.primary,

  7. #7
    Sencha Premium Member seek's Avatar
    Join Date
    Sep 2008
    Location
    North Italy
    Posts
    114
    Vote Rating
    1
      0  

    Default

    Thanks Condor!!
    I use this piece of code:
    PHP Code:
    var tf this.contForm();
    var 
    pk this.record.store.reader.meta.idProperty||this.record.store.reader.meta.idProperty();
    this.record.constructor.prototype.fields.each(function(field){
      var 
    isPrimaryKey;
      if (
    field.mapping){ 
        
    isPrimaryKey=(field.mapping.match(/^[Ii][Dd]./)!=null);
      }else{
        
    isPrimaryKey=(field.name==pk);
      }
      var 
    comp tf.findField(field.name);
      if (
    comp) {
        
    comp.setDisabled(isPrimaryKey);
        
    comp.setReadOnly(isPrimaryKey);
      }
    }); 

Similar Threads

  1. Is Ext.Data.JSONReader invoked when add method is called on Ext.Data.Store
    By nagavasantha in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 9 Sep 2009, 7:34 AM
  2. Replies: 1
    Last Post: 17 Apr 2009, 3:04 PM
  3. Replies: 1
    Last Post: 17 Apr 2009, 3:04 PM
  4. Ext.ux.data.JsonCsvReader - consumes a lightweight form of record data
    By danh2000 in forum Ext 2.x: User Extensions and Plugins
    Replies: 6
    Last Post: 4 Nov 2008, 3:23 AM
  5. Replies: 3
    Last Post: 30 Dec 2007, 11:57 PM

Posting Permissions

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