海水正藍

          面朝大海,春暖花開
          posts - 145, comments - 29, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          【轉】Extjs學習總結---Ext.Grid回車控制

          Posted on 2012-12-06 23:14 小胡子 閱讀(2215) 評論(0)  編輯  收藏 所屬分類: Ext
          原先的EditGrid無法解決回車控制問題,它的回車控制是向下跑的。而我想讓它橫著走。搞了半天終于實現了。

           1 Ext.override(Ext.grid.RowSelectionModel, {
           2                 onEditorKey : function(field, e) {
           3                     // alert('go');
           4                     var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
           5                     var shift = e.shiftKey;
           6                     Ext.log('k:' + k);
           7                     if (k == e.ENTER) {
           8                         e.stopEvent();
           9                         ed.completeEdit();
          10                         if (shift) {
          11                             newCell = g.walkCells(ed.row, ed.col - 1-1,
          12                                     this.acceptsNav, this);
          13                         } else {
          14                             // alert('go');
          15                             newCell = g.walkCells(ed.row, ed.col + 11,
          16                                     this.acceptsNav, this);
          17                         }
          18                     } else if (k == e.TAB) {
          19                         e.stopEvent();
          20                         ed.completeEdit();
          21                         if (this.moveEditorOnEnter !== false) {
          22                             if (shift) {
          23                                 newCell = g.walkCells(ed.row - 1, ed.col, -1,
          24                                         this.acceptsNav, this);
          25                             } else {
          26                                 // alert('go');
          27                                 newCell = g.walkCells(ed.row + 1, ed.col, 1,
          28                                         this.acceptsNav, this);
          29                             }
          30                         }
          31                     } else if (k == e.ESC) {
          32                         ed.cancelEdit();
          33                     }
          34                     if (newCell) {
          35                         g.startEditing(newCell[0], newCell[1]);
          36                     }
          37                 }
          38             });
          39     var sm2 = new Ext.grid.RowSelectionModel({
          40         moveEditorOnEnter : true,
          41         singleSelect : true,
          42         listeners : {
          43             rowselect : function(sm, row, rec) {
          44                 centerForm.getForm().loadRecord(rec);
          45             }
          46         }
          47 
          48     });

          原文出自:
          http://erichua.iteye.com/blog/234698

          2.

          默認extjs中editorgrid編輯單元格的時候按回車是將焦點向下移動,按照一般的邏輯應該是向右移動。

          其實只要將原先rowSelectionModel中onEditorKey方法override一下即可。

          代碼如下:


           1 Ext.override(Ext.grid.RowSelectionModel, {
           2 
           3  onEditorKey : function(field, e) {
           4   var k = e.getKey(), newCell, g = this.grid, last = g.lastEdit, ed = g.activeEditor, shift = e.shiftKey, ae, last, r, c;
           5 
           6   if (k == e.TAB) {
           7    e.stopEvent();
           8    ed.completeEdit();
           9    if (shift) {
          10     newCell = g.walkCells(ed.row, ed.col - 1-1this.acceptsNav,
          11       this);
          12    } else {
          13     newCell = g.walkCells(ed.row, ed.col + 11this.acceptsNav,
          14       this);
          15    }
          16   } else if (k == e.ENTER) {
          17    if (this.moveEditorOnEnter !== false) {
          18     if (shift) {
          19      newCell = g.walkCells(last.row, last.col - 1-1,
          20        this.acceptsNav, this);
          21     } else {
          22      newCell = g.walkCells(last.row, last.col + 11,
          23        this.acceptsNav, this);
          24     }
          25    }
          26   }
          27   if (newCell) {
          28    r = newCell[0];
          29    c = newCell[1];
          30 
          31    this.onEditorSelect(r, last.row);
          32 
          33    if (g.isEditor && g.editing) { // *** handle tabbing while
          34            // editorgrid is in edit mode
          35     ae = g.activeEditor;
          36     if (ae && ae.field.triggerBlur) {
          37      // *** if activeEditor is a TriggerField, explicitly call
          38      // its triggerBlur() method
          39      ae.field.triggerBlur();
          40     }
          41    }
          42    g.startEditing(r, c);
          43   }
          44  }
          45 })

           

          主站蜘蛛池模板: 武邑县| 万山特区| 永康市| 米易县| 鹰潭市| 中宁县| 梨树县| 祁阳县| 垦利县| 桑植县| 朝阳区| 尚志市| 韶关市| 宿州市| 东兰县| 昌吉市| 阜城县| 潼关县| 江川县| 余姚市| 辽中县| 临西县| 广平县| 鄱阳县| 上栗县| 常熟市| 徐水县| 南丹县| 介休市| 福建省| 中卫市| 湖口县| 武鸣县| 二手房| 洛宁县| 通江县| 杭锦后旗| 古蔺县| 惠东县| 汕尾市| 麻城市|