2012-07-06 110 views
0

我有這樣用行動格式一起添加自定義按鈕的jqGrid

colNames: ['Name','Actions'], 

colModel: [ 

     { name: 'name', index: 'name', align: 'right', editable: true}, 
{ name: 'act', index: 'act', width: 75, align: 'center', sortable: false, formatter: 'actions',formatoptions: {keys: true,delbutton:false}} 
], 

一個jqGrid的現在我想用行動格式的編輯按鈕一起添加自定義按鈕。

我試過這個,似乎沒有工作,任何猜測爲什麼?

gridComplete: function(){ 
    var ids = $("#grid").jqGrid('getDataIDs'); 
    for(var i=0;i < ids.length;i++){ 
     var cl = ids[i]; 
     alert(cl); 
     be = "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cl+"'\" />"; 

     $("#grid").jqGrid('setRowData',ids[i],{act:be}); 
    } 
}, 
+0

我認爲你應該編寫自己的格式化程序,因爲你不使用刪除操作,並且你想定製編輯按鈕。 – jbrtrnd 2012-07-06 12:22:27

+0

不,我想讓我的編輯按鈕保持原樣,再加上我想添加一個按鈕以及編輯。那麼你能給我一些例子嗎? – 2012-07-06 14:40:35

回答

2

如果我理解正確的您的要求,您將在thisthis舊答案中找到有關您的問題的答案。

+0

謝謝先生,你是救命恩人......那正是我一直在尋找的......並且相信我或者沒有,我在等你回答..謝謝你.. :) – 2012-07-07 17:38:01

1

這是自定義格式的例子(假設你設置的「操作」欄與您的項目ID值):

<script> 
    var myCustomFormatter = function(cellVal,options,rowObject) { 
     return "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cellVal+"'\" />"; 
    }; 

    $("#yourTableID").jqGrid({ 
     .... 
     colNames: [....,'Actions'], 
     colModel: [ 
      .... 
      { name: 'act', index: 'act', width: 75, align: 'center', sortable: false, formatter:myCustomFormatter} 
     ], 
     .... 
    }); 

</script> 

閱讀jqGrid documentation有關自定義格式。

+0

只是想問這個問題,行動格式化程序和自定義格式化程序都可以一起?當我獲得代碼訪問權限時,我會執行此操作... – 2012-07-06 15:19:54

+0

@PiyushSardana,我不認爲,您可以在jqGrid源代碼中擴展動作格式器。 – jbrtrnd 2012-07-06 15:32:09

+0

你確定嗎?因爲如果你是真的,那麼我認爲我會實施這些變化,但你確定沒有其他方法? – 2012-07-06 15:40:41

相關問題