2012-03-05 27 views
2

我有如何隱藏在ExtJS的行動列4

columns: [ 
    ... 
    { xtype:'actioncolumn', 
     width:40 } 
    ... 
] 

initComponent: function() { 

    var callback=function(hasPerm) { 
     if(!hasPerm) { 
      // I want the action column go away here :) 
     } 
    } 
    isGranted("users.delete",callback); 


} 

isGranted網格是一個全球性的功能,發送一個Ajax請求來檢查給定權限和成功事件調用給定函數返回布爾參數。

isGranted=function(perm, fv) { 
    Ext.Ajax.request({ 
     url: "/isgranted?perm="+perm, 
     method: 'POST', 
     success: function(result) { 
      var res=new Object(); 
      res=Ext.JSON.decode(result.responseText); 
      fv(res.success); 
     } 
    }); 
} 

如何獲得對列的引用以隱藏它們在給定的回調函數中? this.columns沒有工作。

回答

1

更新:合併@DmitryB建議。好多了。

知道,initComponent不會等待您的ajax調用完成,它會繼續並完成構建組件。

columns: [ 
    ... 
    { xtype:'actioncolumn', 
    action: 'someaction', 
    hidden: true, 
    width:40 } 
    ... 
] 

initComponent: function() { 
    var callback=function(hasPerm) { 
    if(hasPerm) { 
     this.down('[action=someaction]').show(); 
    } 
    } 
    isGranted("users.delete",callback, this); 
} 

isGranted=function(perm, fv, scope) { 
    Ext.Ajax.request({ 
    url: "/isgranted?perm="+perm, 
    method: 'POST', 
    success: function(result) { 
     var res=new Object(); 
     res=Ext.JSON.decode(result.responseText); 
     fv.call(scope, res.success); 
    } 
    }); 
} 
+0

對此的一個警告詞:我已經看到列ID在IE8上導致嚴重的渲染問題。 – dbrin 2012-03-06 01:28:07

+2

我不想從賈斯汀的回答中減損,因爲他有正確的想法,但這裏有一些更正:1.默認情況下啓動隱藏的操作列。 2.使用show()來取消隱藏列。 3.不要調用doLayout - 這是從extjs3中擱置而不再需要的。 4(而不是列ID)使用此方法來定位特定列grid.down('[text = MyColumn]')。show() - 這裏'text'是在我的列上定義的屬性,但您可以使用您的ANY屬性選擇,甚至定製的。 – dbrin 2012-03-06 01:51:36

+0

感謝DmitryB,非常好的一點。我已經更新了我的答案。 – Justin 2012-03-06 07:13:08