Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*global Ext:false */
- Ext.onReady(function() {
- var store = Ext.create('Ext.data.TreeStore', {
- root: {
- expanded: true,
- children: [{
- text: "detention",
- leaf: true
- }, {
- text: "homework",
- expanded: true,
- children: [{
- text: "book report",
- leaf: true
- }, {
- text: "alegrbra",
- leaf: true
- }]
- }, {
- text: "buy lottery tickets",
- leaf: true
- }]
- }
- });
- Ext.define('TreeCellEditing', {
- alias: 'plugin.treecellediting',
- extend: 'Ext.grid.plugin.CellEditing',
- init: function(tree) {
- var tree_column = tree.headerCt.down('treecolumn');
- tree_column.editor = tree_column.editor ||
- { xtype: 'textfield' };
- this.callParent(arguments);
- },
- getEditingContext: function(record, columnHeader) {
- var me = this,
- grid = me.grid,
- store = grid.store,
- rowIdx,
- colIdx,
- view = grid.getView(),
- root = grid.getRootNode(),
- value;
- if (Ext.isNumber(record)) {
- rowIdx = record;
- record = root.getChildAt(rowIdx);
- } else {
- rowIdx = root.indexOf(record);
- }
- if (Ext.isNumber(columnHeader)) {
- colIdx = columnHeader;
- columnHeader = grid.headerCt.getHeaderAtIndex(colIdx);
- } else {
- colIdx = columnHeader.getIndex();
- }
- value = record.get(columnHeader.dataIndex);
- return {
- grid: grid,
- record: record,
- field: columnHeader.dataIndex,
- value: value,
- row: view.getNode(rowIdx),
- column: columnHeader,
- rowIdx: rowIdx,
- colIdx: colIdx
- };
- }
- });
- var tree_editor = Ext.create('TreeCellEditing', {clicksToEdit: 2});
- var tree = Ext.create('Ext.tree.Panel', {
- title: 'Simple Tree',
- width: 200,
- height: 150,
- store: store,
- rootVisible: false,
- renderTo: Ext.getBody(),
- plugins: [
- tree_editor
- ]
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement