Monday, February 13, 2012

Create a child component in a grid cell


This is a useful function that add an Ext component to a grid cell.
The function returns an HTML block and use a deferred function which add a Ext component to this div element.

/**
 * create a Ext component in a grid
 * @param
 *          - className {String}: the class name of the component to create
 *          - config (optional) {Object}: the configuration of the component to create
 */
addGridComponent: function(options){
      if (options.className){
            // create a unique ID
            var id = Ext.id();
            // create a function which the call will be defer
            Ext.defer(function(){
                  var config = {renderTo: id};
                  // add parameter options to render property
                  if (options.config){
                        Ext.apply(config, options.config);
                  }
                  Ext.create(options.className, config);
            }, 25);
            return (Ext.String.format('
', id));
      }
}


No comments: