+ -
当前位置:首页 → 问答吧 → extjs中,gird的rowediting插件,如何获取cancel事件

extjs中,gird的rowediting插件,如何获取cancel事件

时间:2011-10-25

来源:互联网



如图 我想点击cancel时候 删除该行内容 求指导

作者: langjian305   发布时间: 2011-10-25

有木有高手指导一下啊

作者: langjian305   发布时间: 2011-10-25

另外的插件应该看它API文档就知道了吧?或者看源码,楼主发rowediting这个源码看看?

作者: liangws   发布时间: 2011-10-25


Ext.define('Ext.grid.plugin.RowEditing', {
  extend: 'Ext.grid.plugin.Editing',
  alias: 'plugin.rowediting',

  requires: [
  'Ext.grid.RowEditor'
  ],

  editStyle: 'row',
   
  autoCancel: true,
   
  errorSummary: true,
   
  constructor: function() {
  var me = this;
  me.callParent(arguments);

  if (!me.clicksToMoveEditor) {
  me.clicksToMoveEditor = me.clicksToEdit;
  }

  me.autoCancel = !!me.autoCancel;
  },

  
  destroy: function() {
  var me = this;
  Ext.destroy(me.editor);
  me.callParent(arguments);
  },

   
  startEdit: function(record, columnHeader) {
  var me = this,
  editor = me.getEditor();

  if (me.callParent(arguments) === false) {
  return false;
  }

  // Fire off our editor
  if (editor.beforeEdit() !== false) {
  editor.startEdit(me.context.record, me.context.column);
  }
  },

  // private
  cancelEdit: function() {
  var me = this;

  if (me.editing) {
  me.getEditor().cancelEdit();
  me.callParent(arguments);
  }
  },

  // private
  completeEdit: function() {
  var me = this;

  if (me.editing && me.validateEdit()) {
  me.editing = false;
  me.fireEvent('edit', me.context);
  }
  },

  // private
  validateEdit: function() {
  var me = this;
  return me.callParent(arguments) && me.getEditor().completeEdit();
  },

  // private
  getEditor: function() {
  var me = this;

  if (!me.editor) {
  me.editor = me.initEditor();
  }
  return me.editor;
  },

  // private
  initEditor: function() {
  var me = this,
  grid = me.grid,
  view = me.view,
  headerCt = grid.headerCt;

  return Ext.create('Ext.grid.RowEditor', {
  autoCancel: me.autoCancel,
  errorSummary: me.errorSummary,
  fields: headerCt.getGridColumns(),
  hidden: true,

  // keep a reference..
  editingPlugin: me,
  renderTo: view.el
  });
  },

  // private
  initEditTriggers: function() {
  var me = this,
  grid = me.grid,
  view = me.view,
  headerCt = grid.headerCt,
  moveEditorEvent = me.clicksToMoveEditor === 1 ? 'click' : 'dblclick';

  me.callParent(arguments);

  if (me.clicksToMoveEditor !== me.clicksToEdit) {
  me.mon(view, 'cell' + moveEditorEvent, me.moveEditorByClick, me);
  }

  view.on('render', function() {
  // Column events
  me.mon(headerCt, {
  add: me.onColumnAdd,
  remove: me.onColumnRemove,
  columnresize: me.onColumnResize,
  columnhide: me.onColumnHide,
  columnshow: me.onColumnShow,
  columnmove: me.onColumnMove,
  scope: me
  });
  }, me, { single: true });
  },

  startEditByClick: function() {
  var me = this;
  if (!me.editing || me.clicksToMoveEditor === me.clicksToEdit) {
  me.callParent(arguments);
  }
  },

  moveEditorByClick: function() {
  var me = this;
  if (me.editing) {
  me.superclass.startEditByClick.apply(me, arguments);
  }
  },

  // private
  onColumnAdd: function(ct, column) {
  if (column.isHeader) {
  var me = this,
  editor;
   
  me.initFieldAccessors(column);
  editor = me.getEditor();
   
  if (editor && editor.onColumnAdd) {
  editor.onColumnAdd(column);
  }
  }
  },

  // private
  onColumnRemove: function(ct, column) {
  if (column.isHeader) {
  var me = this,
  editor = me.getEditor();
   
  if (editor && editor.onColumnRemove) {
  editor.onColumnRemove(column);
  }
  me.removeFieldAccessors(column);  
  }
  },

  // private
  onColumnResize: function(ct, column, width) {
  if (column.isHeader) {
  var me = this,
  editor = me.getEditor();
   
  if (editor && editor.onColumnResize) {
  editor.onColumnResize(column, width);
  }
  }
  },

  // private
  onColumnHide: function(ct, column) {
  // no isHeader check here since its already a columnhide event.
  var me = this,
  editor = me.getEditor();

  if (editor && editor.onColumnHide) {
  editor.onColumnHide(column);
  }
  },

  // private
  onColumnShow: function(ct, column) {
  // no isHeader check here since its already a columnshow event.
  var me = this,
  editor = me.getEditor();

  if (editor && editor.onColumnShow) {
  editor.onColumnShow(column);
  }
  },

  // private
  onColumnMove: function(ct, column, fromIdx, toIdx) {
  // no isHeader check here since its already a columnmove event.
  var me = this,
  editor = me.getEditor();

  if (editor && editor.onColumnMove) {
  editor.onColumnMove(column, fromIdx, toIdx);
  }
  },

  // private
  setColumnField: function(column, field) {
  var me = this;
  me.callParent(arguments);
  me.getEditor().setField(column.field, column);
  }
});

作者: langjian305   发布时间: 2011-10-25