From f6a4bfd67582894380a46b6c108a001314ce830a Mon Sep 17 00:00:00 2001 From: Anil Bhat Date: Mon, 24 Jun 2013 09:43:05 +0530 Subject: [PATCH] Create ButtonColumn.js modified I was struggling to show Dynamic text on buttons, so found a way here in this file by adding setText method at line number 81, the value is passed to addButton. You can reach me at anilbhat21@gmail.com or +919811706514 --- ButtonColumn.js modified | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 ButtonColumn.js modified diff --git a/ButtonColumn.js modified b/ButtonColumn.js modified new file mode 100644 index 0000000..617e4c0 --- /dev/null +++ b/ButtonColumn.js modified @@ -0,0 +1,116 @@ +/** + * ButtonColumn extension + * + * @author Chris Ramakers + * @copyright (c) 2011, by Inventis BVBA + * @date 8 march 2011 + * @version $Id$ + * + * @license ButtonColumn.js is licensed under the terms of the Open Source + * LGPL 3.0 license. Commercial use is permitted to the extent that the + * code/component(s) do NOT become part of another Open Source or Commercially + * licensed development library or toolkit without explicit permission. + * + * License details: http://www.gnu.org/licenses/lgpl.html + * + * @class Ext.ux.grid.ButtonColumn + * @extends Ext.grid.Column + */ +Ext.ns('Ext.ux.grid'); + +// Required overrides for buttoncolumn to work +Ext.grid.GridView.prototype.rowSelectorDepth = 20; +Ext.grid.GridView.prototype.cellSelectorDepth = 10; + +Ext.ux.grid.ButtonColumn = Ext.extend(Ext.grid.Column, { + + header: ' ', + menuDisabled: true, + + buttons: new Ext.util.MixedCollection(), + + constructor: function(cfg) { + var me = this, + items = cfg.items || (me.items = [me]), + l = items.length, + i, + itemId, + item; + + Ext.ux.grid.ButtonColumn.superclass.constructor.call(me, cfg); + + me.renderer = function(value, meta, record){ + + meta.css += 'x-button-col-cell'; + + v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : ''; + + for (i = 0; i < l; i++) { + + item = items[i]; + + itemId = Ext.id(); + placeholderId = itemId + '-placeholder'; + + v += String.format('', itemId); + + Ext.lib.Event.onAvailable(placeholderId, this.addButton.createDelegate(this, [itemId, item, record, value])); + + } + + return v; + } + }, + + addButton: function(itemId, item, record, value){ + + var config = Ext.apply({ + renderTo: itemId + '-placeholder', + handler: Ext.emptyFn, + id: itemId + }, item); + + // Detach handler and add it as an handler alias so the button click is not triggered + // but the handler function is triggered manually in the processEvent method + config.buttonColumnHandler = config.handler; + config.handler = Ext.emptyFn; + + // Add button to the internal button storage + var button = new Ext.Button(config); + this.buttons.add(itemId, button); + button.setText(value); + if(Ext.isFunction(config.afteradd)) { + config.afteradd.apply(button, [button, record]); + } + + }, + + destroy: function() { + delete this.items; + delete this.renderer; + return Ext.ux.grid.ButtonColumn.superclass.destroy.apply(this, arguments); + }, + + processEvent : function(name, e, grid, rowIndex, colIndex){ + var t = Ext.get(e.getTarget()), + p = t.findParent('table.x-btn'), + itemIndex, + item, + fn; + + itemIndex = p.id; + item = this.buttons.get(itemIndex); + handler = item.buttonColumnHandler; + + if (p && item) { + if (name == 'click') { + (fn = handler || this.handler) && !item.disabled && fn.call(item.scope||this.scope||this, grid, rowIndex, colIndex, item, e); + } else if ((name == 'mousedown') && (item.stopSelection !== false)) { + return false; + } + } + return Ext.ux.grid.ButtonColumn.superclass.processEvent.apply(this, arguments); + } +}); + +Ext.grid.Column.types.buttoncolumn = Ext.ux.grid.ButtonColumn;