1. #1
    Sencha User
    Join Date
    Jan 2009
    Posts
    61
    Vote Rating
    1
    bartonjd is on a distinguished road

      1  

    Default Autosize Grid Columns to Fit Contents & Header Text

    Autosize Grid Columns to Fit Contents & Header Text


    This is just a simple plugin that ensures that all grid columns are wide enough for their header text and their contents.

    Code:
    Ext.ns('Ext.plugins');
    Ext.plugins.GridAutoWidths = function(config) {
        Ext.apply(this, config);
    };
    
     Ext.extend(Ext.plugins.GridAutoWidths, Ext.util.Observable, {
        init: function (cmp) {
            cmp.store.on('load', function(g){
                var numCol = cmp.getColumnModel().getColumnCount();    
                for(var i=0;i<numCol;i++){
                    var header = cmp.colModel.getColumnHeader(i);
                    var id = cmp.getView().mainHd.dom.getElementsByTagName('a')[i];
                    var width = Ext.util.TextMetrics.createInstance(Ext.get(id)).getWidth(header) + 10;
                    cmp.getColumnModel().setColumnWidth(i,width);
                    var data = Ext.get(cmp.getView().getRow(0).getElementsByTagName('div')[i]).dom.textContent;
                    dataWidth = Ext.util.TextMetrics.createInstance(Ext.get(cmp.getView().getRow(0).getElementsByTagName('div')[i])).getWidth(data)+10;
                    if (width < dataWidth){
                    cmp.getColumnModel().setColumnWidth(i,dataWidth)
                    }
                }
            });
        }
    });

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2013
    Posts
    4
    Vote Rating
    0
    romankuzmik is on a distinguished road

      0  

    Default


    this is what I have for Ext 4.2:

    PHP Code:
    Ext.define('CUI.ux.plugin.GridAutoWidths', {  
    extend'Ext.AbstractPlugin',


      
    init: function (grid) {
        
    grid.store.on('load', function(){
          var 
    columnsManager grid.getView().getHeaderCt();
          var 
    columnsCount columnsManager.getColumnCount();
          for (var 
    headerIndex=0headerIndex<columnsCountheaderIndex++){
            var 
    column columnsManager.getHeaderAtIndex(headerIndex);
            
    columnsManager.autoSizeColumn(column);
            
    column.setSize(column.getSize().width 5column.getSize().height);
          }
        });
      }
    }); 

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar