Results 1 to 7 of 7

Thread: How to access getSelections()

  1. #1

    Default How to access getSelections()

    Hi , ive modified an editable grid , and it works fine apart from the edit and delete function
    as i get undefined back for the .getSelections();

    in an approach like this:

    Code:
    
    
    FamilyContentGrid
    .superclass.constructor.call(this,{
    title
    :'Family of suppliers',
    store
    : SimpleDataStore,
    cm
    : SimpleColumnModel,
    loadMask
    :true,
    //componen tbar
    tbar
    :[{
    //button edit
    text
    :'Edit',
    iconCls
    :'edit-grid',//create icon
    handler
    :function(){ // So how i access getSelections after calling it as above // var m = this.getSelections(); //nop // var m = FamilyContentGrid.getSelections();//nop
    var m = FamilyContentGrid.grid.selModel.getSelections();//nop PROBLEM
    how can i get the selected in var m

    thanks

  2. #2

  3. #3

    Default nop

    thanks but i get as error

    FamilyContentGrid.getSelectionModel is not a function

    var m =FamilyContentGrid.getSelectionModel().getSelections();//function select


  4. #4
    Sencha User BitPoet's Avatar
    Join Date
    Sep 2008
    Location
    Bavaria
    Posts
    277

    Default

    Maybe you need to give us more complete, runnable example code than the snippet above then. Though, for a button handler in a gridpanel's toolbar, you should be able say 'this.ownerCt.ownerCt.getSelectionModel().getSelections()'.

  5. #5

    Default hi

    Hi , sure , i just wanted to isolate it

    but here is the function completely:

    Code:
    FamilyContentGrid
    =function(){
    var expander =new Ext.grid.RowExpander({//compenen dari expander row
    tpl
    :new Ext.Template(////below is a field that will expand
    '<p><b>Name:</b> {family}</p><br>'
    ,'<p><b>Active:</b> {active}</p><br>')
    });
    function iconactive(value)
    {
    if(value ==1)return'<img src="icons/accept.png" border="0" >';
    elsereturn'<img src="icons/delete.png" border="0">'; }
    var SimpleDataStore =new Ext.data.Store({
    proxy
    :new Ext.data.HttpProxy({
    url
    :THEURL,
    method
    :'POST'
    }),
    reader
    :new Ext.data.JsonReader({
    root
    :'results',
    totalProperty
    :'total'
    },[{
    name
    :'family_id',
    type
    :'int'
    },{
    name
    :'family',
    type
    :'string'
    },{
    name
    :'active',
    type
    :'int'
    }]),
    sortInfo
    :{
    field
    :'family_id',
    direction
    :"ASC"
    }
    });
    SimpleDataStore
    .load({
    params
    :{
    start
    :0,
    limit
    :6
    }
    });
    var SimpleColumnModel =new Ext.grid.ColumnModel([expander,{
    header
    :'Id',
    readOnly
    :true,
    dataIndex
    :'family_id',
    width
    :40,
    hidden
    :false
    },{
    header
    :'Name',
    dataIndex
    :'family',
    width
    :200
    },{
    header
    :'Active',
    dataIndex
    :'active',
    renderer
    : iconactive,
    //vtype:'email',
    width
    :60
    }]);
    SimpleColumnModel
    .defaultSortable =true;
    var formEdit =new Ext.form.FormPanel({
    url
    :'family_of_content.php?act=edit',
    baseCls
    :'x-plain',
    labelWidth
    :90,
    defaultType
    :'textfield',
    reader
    :new Ext.data.JsonReader({
    root
    :'results',
    totalProperty
    :'total',
    id
    :'id',
    fields
    :['family_id','family','active']
    }),
    items
    :[new Ext.form.Hidden({
    name
    :'family_id'
    }),{
    fieldLabel
    :'Name',
    name
    :'name',
    anchor
    :'100%'
    },{
    fieldLabel
    :'Active',
    name
    :'active',
    width
    :220
    }],
    buttons
    :[{
    text
    :'SAVE',
    handler
    :function(){
    formEdit
    .getForm().submit({
    waitMsg
    :'Storing Data...',
    failure
    :function(form, action){
    Ext
    .MessageBox.alert('Error Message','Data Failure.....');
    formEdit
    .getForm().reset();
    },
    success
    :function(form, action){
    Ext
    .MessageBox.alert('Confirm','Success to storing data...');
    SimpleDataStore
    .load({
    params
    :{
    start
    :0,
    limit
    :6
    }
    });
    window
    .hide();
    formEdit
    .getForm().reset();
    }
    })
    }
    },{
    text
    :'Cancel',
    handler
    :function(){
    window
    .hide();
    }
    }]
    });
    var simpleAdd =new Ext.FormPanel({
    url
    :'family_of_content.php?act=add',
    xtype
    :'panel', // title: 'Add family',
    layout
    :'form', //frame: true,
    labelWidth
    :95,
    defaults
    :{
    allowBlank
    :false
    },
    items
    :[{
    xtype
    :'textfield',
    fieldLabel
    :'Name',
    anchor
    :'70%',
    name
    :'name'
    },{
    fieldLabel
    :'Active',
    anchor
    :'70%',
    name
    :'active',
    xtype
    :'checkbox'
    }],
    buttons
    :[{
    text
    :'Save',
    handler
    :function(){
    if(simpleAdd.getForm().isValid()){
    simpleAdd
    .getForm().submit({
    waitMsg
    :'Saving family into db...',
    success
    :function(simpleAdd, o){
    Ext
    .MessageBox.alert('Creation OK','Add family Success..');
    SimpleDataStore
    .reload();
    SimpleWindow
    .hide();
    },
    failure
    :function(simpleAdd, o){
    Ext
    .MessageBox.alert('Warning','Adding family Failure...');
    }
    });
    }
    }
    },{
    text
    :'Reset',
    handler
    :function(){
    simpleAdd
    .getForm().reset();
    }
    }]
    });
    var SimpleWindow =new Ext.Window({
    title
    :'Add a family for suppliers',
    closable
    :true,
    closeAction
    :'hide',
    width
    :340,
    height
    :160,
    layout
    :'fit',
    modal
    :true,
    items
    : simpleAdd });
    function displayFormWindow(){
    if(!SimpleWindow.isVisible()){
    SimpleWindow
    .show();
    }
    else{
    SimpleWindow
    .toFront();
    }
    }
    var window =new Ext.Window({
    title
    :'Edit Input',
    width
    :340,
    height
    :300,
    minWidth
    :300,
    minHeight
    :300,
    layout
    :'card',
    plain
    :true,
    bodyStyle
    :'padding:3px;',
    buttonAlign
    :'center',
    closeAction
    :'hide',
    modal
    :true,
    animCollapse
    :true,
    activeItem
    :0,
    items
    :[formEdit]
    });
    //function delete
    function del(btn){
    if(btn =='yes'){
    var m =this.getSelections();
    SimpleDataStore
    .load({
    params
    :{
    del
    : m[0].get("id"),
    start
    :0,
    limit
    :6
    }
    });
    }
    }
    FamilyContentGrid
    .superclass.constructor.call(this,{
    title
    :'Family of suppliers',
    store
    : SimpleDataStore,
    cm
    : SimpleColumnModel,
    loadMask
    :true,
    //componen tbar
    tbar
    :[{
    //button edit
    text
    :'Edit',
    iconCls
    :'edit-grid',//create icon
    handler
    :function(){
    var m =this.getSelectionModel().getSelections();//function select
    if(m.length >0){
    //get id
    formEdit
    .getForm().load({
    url
    :'family_of_content.php?act=get&id='+ m[0].get('id'),
    waitMsg
    :'Loading'
    });
    window
    .show();
    }
    else{
    Ext
    .MessageBox.alert('Message','please... Choose one field...!');
    }
    }
    },{
    //buttton delete
    text
    :'Delete',
    iconCls
    :'delete',//create icon
    handler
    :function(){
    var m =this.getSelections();
    if(m.length >0){
    Ext
    .MessageBox.confirm('Message','are you sure to delete this field?', del);
    }
    else{
    Ext
    .MessageBox.alert('Message','please... Choose one of the fields...!');
    }
    }
    },'-',{
    text
    :'Add',
    iconCls
    :'add',
    handler
    : displayFormWindow }],
    viewConfig
    :{
    forceFit
    :true
    },
    plugins
    : expander,
    frame
    :true,
    collapsible
    :true,
    animCollapse
    :true,
    width
    :480,
    height
    :220,
    bbar
    :new Ext.PagingToolbar({
    pageSize
    :6,
    store
    : SimpleDataStore,
    displayInfo
    :true,
    displayMsg
    :'Displaying data {0} - {1} of {2}',
    emptyMsg
    :"No data to display"
    })
    });
    }
    Ext.extend(FamilyContentGrid, Ext.grid.EditorGridPanel );

  6. #6
    Sencha User BitPoet's Avatar
    Join Date
    Sep 2008
    Location
    Bavaria
    Posts
    277

    Default

    I see. Aiming from the hip, though this is rather a kludge I have to admit, you could simply assign a 'grid' property to each button. I've highlighted my changes to your code in red.

    Code:
        FamilyContentGrid.superclass.constructor.call(this,{
            title:'Family of suppliers',
            renderTo: document.body,
            store: SimpleDataStore,
            cm: SimpleColumnModel,
            loadMask:true,
            sm: new Ext.grid.CellSelectionModel({singleSelect: true}),
            listeners:    {
                render:    function(grid) {
                    grid.getTopToolbar().items.each( function(item){ item.grid = grid; } );
                }
            },
            //componen tbar
            tbar:[{
                //button edit
                text:'Edit',
                iconCls:'edit-grid',//create icon
                handler:function(){
                    var m = this.grid.getSelectionModel().getSelectedCell();
                    //var m = this.getSelectionModel().getSelections();//function select
                    if(m.length >0){
                        var row = m[0];
                        var rowid = SimpleDataStore.getAt(row).get('id');
                        //get id
                        formEdit.getForm().load({
                            url:'family_of_content.php?act=get&id='+ rowid,
                            waitMsg:'Loading'
                        });
                        window.show();
                    }
                    else{
                        Ext.MessageBox.alert('Message','please... Choose one field...!');
                    }
                
                }
            },{
                    ...

  7. #7

    Default hi

    At the same time!

    thanks very much

    i did it like this ,i gave an id to the grid and then with getCmp i could manage to get it along with reading somewhere
    over getSelectedCell() the pieces fell together

    Code:
    handler
    
    :function(){
    // s var m = Ext.getCmp('longshot').getSelectionModel().getSelectedCell();
    if(m !=null){ var record = SimpleDataStore.getAt(m[0]); //get id formEdit
    .getForm().load({
    url
    :'family_of_content.php?act=get&id='+ record.get('family_id'),
    waitMsg
    :'Loading'
    }); window
    .show();}


Posting Permissions

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