海水正藍

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

          日歷

          <2012年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          文章檔案

          搜索

          •  

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

          Posted on 2012-12-06 23:14 小胡子 閱讀(2216) 評論(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 })

           

          主站蜘蛛池模板: 金塔县| 赤峰市| 固阳县| 蕉岭县| 南郑县| 株洲市| 珠海市| 潞城市| 阜新市| 宜昌市| 连州市| 类乌齐县| 张家口市| 铜陵市| 方正县| 图木舒克市| 陇南市| 开远市| 卫辉市| 商丘市| 正蓝旗| 泽普县| 原阳县| 喀喇沁旗| 陇西县| 长兴县| 印江| 新野县| 屯门区| 宜城市| 陕西省| 呼玛县| 三门峡市| 方正县| 池州市| 南部县| 思南县| 彰化市| 陈巴尔虎旗| 五华县| 高唐县|