1. #1
    Sencha User
    Join Date
    Feb 2008
    Location
    Palu, Indonesia
    Posts
    7
    Vote Rating
    0
    xp743 is on a distinguished road

      0  

    Default Simple Ext.Direct-Combobox plugin --- with Ext.Direct.Store for reuse

    Simple Ext.Direct-Combobox plugin --- with Ext.Direct.Store for reuse


    Ext.Direct.Combo

    this combobox plugin code for reuse with Ext.Direct + Ext.data.DirectStore
    Code :
    PHP Code:
    Ext.DirectCombo Ext.extend(Ext.form.ComboBox, {
        
    triggerAction'all',
        
    forceSelectiontrue,
        
    mode:'local',
        
    initComponent: function() {
            var 
    id this.idcol this.displayField;
            
    this.valueField id;
            
    this.store = new Ext.data.DirectStore(Ext.apply({
                
    storeId:this.name+'-store',
                
    paramOrder: ['table','key','field'],
                
    baseParams:{table:this.name,key:id,field:col},
                
    api:{read:this.action || Ext.php.Combo.load},            
                
    fields:[
                    {
    name:idtype:'int'},
                    {
    name:col}
                ],
                
    autoLoadtrue
            
    }));
            
    Ext.DirectCombo.superclass.initComponent.call(this);
        }
    });
    Ext.reg('combo-direct'Ext.DirectCombo); 
    Sample to Use :
    PHP Code:
    var cb = new Ext.DirectCombo({
            
    renderToExt.getBody(),
            
    displayField'nama'//column/field name
            
    id:'user_id'//primary key (MySQL)
            
    name:'users'//table name
            
    width:150
        
    });
    var 
    cb1 = new Ext.DirectCombo({
            
    renderToExt.getBody(),
            
    displayField'job_name'//column/field name
            
    id:'employee_id'//primary key (MySQL)
            
    name:'employee'//table name
            
    width:150
        
    });

    etc ... 
    or
    PHP Code:
    var cb = {xtype:'combo-direct',id:'user_id',name:'users'displayField'nama'
    and JSON response must like :
    PHP Code:
    {"type":"rpc","tid":2,"action":"Combo","method":"load","result":[{"user_id":1,"nama":"ari"},{"user_id":2,"nama":"ana"}]} 
    sample PHP backend return JSON :
    PHP Code:
    class Combo
    {
        public function 
    load($table$pkey$field) {//select ".$pkey.",".$field." from ".$table." 
            
    $arr = array(
                array(
    'user_id' => 1'nama' => 'ari'),
                array(
    'user_id' => 2'nama' => 'ana')
            );
            return 
    $arr;
        }

    threre are 3 variable required :
    1. id = this item used for initials valueField and table primary Key (Mysql)
    2. name = used for initials table name to send param
    3. displayField = used for initials displayField in comboBox Field and column name param to send

  2. #2
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    582
    Vote Rating
    9
    Dumas will become famous soon enough

      0  

    Default


    To be honest I don't see a big value in this, what's the purpose?
    Why do you force to define an id which you then use as valueField instead of just defined valueField when instanciating.

    I think that's only for your own use, cause you force many conventions, like the store id name or how the data is loaded from server. Or that the combobox name must be the same as the table name.

    I wouldn't try to override the meaning of already in combobox used properties, instead I would recommand you to use a new config, like makeStore, so a config could look like:
    {xtype:'combo-direct',makeStore:{id:'user_id',name:'users'}, displayField: 'nama'}
    and in the initComponent, you make an if(typeof this.makeStore === 'object') { /* create Store */ }

    Best regards,
    Roland

Similar Threads

  1. Ext.Direct Struts 2 plugin: extdirectj-s2-plugin
    By stefanorg in forum Ext.Direct
    Replies: 4
    Last Post: 12 Oct 2011, 3:39 AM
  2. Ext.Direct and GridFilters plugin
    By twaindev in forum Ext.Direct
    Replies: 5
    Last Post: 3 Mar 2010, 5:38 AM
  3. Simple Ext.Direct PHP apps
    By pkristiana in forum Community Discussion
    Replies: 1
    Last Post: 11 Feb 2010, 1:12 AM
  4. Ext.Direct Simple Yet Confusing... HELP!
    By cgountanis in forum Ext.Direct
    Replies: 2
    Last Post: 16 Nov 2009, 1:56 PM
  5. Simple Question AJAX vs. Ext.Direct for JSON
    By cgountanis in forum Ext.Direct
    Replies: 1
    Last Post: 7 Oct 2009, 2:26 PM

Thread Participants: 1