1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    4
    Vote Rating
    0
    ElGranAzul is on a distinguished road

      0  

    Default Pre-selecting a row in a grid

    Pre-selecting a row in a grid


    Hi. I need to pre-select a row in a grid at load. I've tried with getView().focusRow, but it seems not to work. I've search all the forum and docs, but it seems the way to do it.

    I leave part the code above. If someone could help me, please.

    Code:
            init : function(){
            
                // Main layout
                var layout = new YAHOO.ext.BorderLayout(document.body, {
                    west: {
                        split:true,
                        initialSize: 200,
                        titlebar: true,
                        collapsible: true,
                        minSize: 100,
                        maxSize: 400,
                        animate: true,
                    },
                    center: {
                        autoScroll: false
                    }
                });
                layout.beginUpdate();           
                
                // Main client list grid
                var cl_schema = { tagName:'cliente', id:'ASIN', fields:['codigo', 'cifnif', 'nombre', 'anagra']};
                cl_dataModel = new $G.XMLDataModel(cl_schema);
                var cl_colModel = new $G.DefaultColumnModel([
        			{header: "Código", width: 70, sortable: true}, 
        			{header: "CIF/NIF", width: 70, sortable: true}, 
        			{header: "Nombre o Razón social", width: 250, sortable: true}, 
        			{header: "Anagrama", width: 200, sortable: true}
        		]);    	
        		cl_dataModel.load('/clientes/xml/');
                var cl_grid = new $G.Grid('cl_grid', cl_dataModel, cl_colModel);
                cl_grid.render();
                
                cl_grid.addListener('rowclick', this.cl_onRowClick);            
                
                // Layout client detail zone
                var innerLayout = new YAHOO.ext.BorderLayout('content', {
                    south: {
                        split:true,
                        initialSize: 500,
                        minSize: 400,
                        maxSize: 600,
                        autoScroll:true,
                        collapsible:true,
                        titlebar: true,
                        animate: true,
                      //  tabPosition: 'top',
                    },
                    center: {
                        autoScroll:true
                    }
                });
    
                // Main toolbar
                var cl_toolBar = new YAHOO.ext.Toolbar('cl_toolBar');
                cl_toolBar.addButton({text: 'Nuevo', className: 'toolbar-btn add'});
                cl_toolBar.addSeparator();
                cl_toolBar.addButton({text: 'Borrar', className: 'toolbar-btn delete', click: this.showDeleteDialog});
                cl_toolBar.addSeparator();
                var filterText = document.createElement('input');
                filterText.type = "text";
                filterText.id = "filterVal";
                cl_toolBar.add(filterText);
                cl_toolBar.addButton({text: "Buscar", className: 'toolbar-btn buscar',
                    click: function(){
                        cl_dataModel.load("/clientes/xml/?q="+filterText.value);}
                });
    
                // Main Data toolbar
                var cdata_toolBar = new YAHOO.ext.Toolbar('cdata_toolBar');
                cdata_toolBar.addButton({text: 'Editar', className: 'toolbar-btn edit', click: this.showDataEditDialog});
                
                // Layout detail zone
                innerLayout.add('center', new YAHOO.ext.GridPanel(cl_grid, {title: 'Clientes', closable: true, toolbar: cl_toolBar}));
                innerLayout.add('south', new YAHOO.ext.ContentPanel('datos', {title: 'Datos', toolbar: cdata_toolBar}));
                innerLayout.add('south', new YAHOO.ext.ContentPanel('almacen', "Almacenes"));
                innerLayout.add('south', new YAHOO.ext.ContentPanel('contacto', "Contactos"));
                innerLayout.add('south', new YAHOO.ext.ContentPanel('despacho', "Direcciones de despacho"));
                innerLayout.add('south', new YAHOO.ext.ContentPanel('factura', "Facturación"));
                
                // Layout Main Zone
                layout.add('west', new YAHOO.ext.ContentPanel('nav', {title: 'Navigation', fitToFrame:true, closable:false}));
                layout.add('center', new YAHOO.ext.NestedLayoutPanel(innerLayout));           
                layout.endUpdate();
                
                innerLayout.getRegion('south').showPanel('datos');
                
                
                cl_grid.getView().focusRow(1);
    
            },
    Thanks!

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Code:
    cl_dataModel.on('load', function(){
        cl_grid.getSelectionModel().selectFirstRow();
    });
    You will need to wait for the load event to do any selections since the rows won't actually be there to select. The object that handles selections is the DefaultSelectionModel in the docs (http://www.yui-ext.com/docs/index.ht...tionModel.html). It has a bunch of methods for doing selections, not just selectFirstRow.

Similar Threads

  1. Grid: Selecting multiple rows using checkbox
    By amitava in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 28 Jun 2012, 11:47 PM
  2. Tabpage content not displayed after selecting it
    By mhuibers in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 25 Mar 2007, 2:31 AM

Thread Participants: 1