2011-04-09 55 views
0

我遵循jqgrid文檔中創建的規範,但在嘗試保存行時發生錯誤。 這裏的示例代碼:有關在jqgrid中插入自定義元素的問題

<script> 
function myelem (value, options) { 
    var el = document.createElement("input"); 
    el.type="text"; 
    el.value = value; 
    return el; 
} 

function myvalue(elem, operation, value) { 
    if(type=='get') { 
     return $(elem).find("input").val(); 
    } else if(type == 'set') { 
     $('input',elem).val(stringvalue); 
    } 
} 
jQuery("#grid_id").jqGrid({ 
... 
    colModel: [ 
     ... 
     {name:'price', ..., editable:true, edittype:'custom', 
     editoptions:{custom_element: myelem, custom_value:myvalue} }, 
     ... 
    ] 
... 
}); 
</script> 
下面一行在調試,我發現這種類型的未定義

是否有其他方法,這一點要知道,如果它是一組或值的獲取。

... 
if(type=='get') { 
... 

回答

2

您應該使用當然operation代替typevalue,而不是stringvalue。這似乎是jqGrid文檔中的一個錯誤。您還應該在jQuery(document).ready(function() {/*place your code here*/});處理程序中放置jQuery("#grid_id").jqGrid({...});的代碼。

如果您使用表單編輯,我建議您也閱讀this answer並使用recreateForm:true

修訂:因爲jqGrid的的文檔wiki文檔,每個人都可以修改它,我這你可能使用的文檔中修改剛纔the corresponding place

+0

我看到了操作數的值,但它包含單元格的名稱而不是操作的類型 – eKelvin 2011-04-10 07:03:50

+0

@ZeroAbsolute:我試圖幫助你,但是你發佈的信息太少。例如,您不清楚使用哪種編輯模式(表單編輯,內聯編輯或單元格編輯)。每個編輯模式都有自己的代碼。例如[這裏](https://github.com/tonytomov/jqGrid/blob/v4.0.0/js/grid.formedit.js#L341)和[這裏](https://github.com/tonytomov/jqGrid /blob/v4.0.0/js/grid.formedit.js#L575),您可以在表單編輯中看到'get'和'set'。第二個參數在這裏是正確的。你應該發佈更多你使用的代碼。 – Oleg 2011-04-10 10:09:39

+0

@ZeroAbsolute:在內聯編輯或單元格編輯的情況下,您只需實現'custom_value'的簡化形式,其中第二個參數始終爲'get'。可能[一個​​工作示例](http://www.ok-soft-gmbh.com/jqGrid/Ranking.htm)我準備[答案](http://stackoverflow.com/questions/4842262/jqgrid- custom-cell-integration-of-raty-plugin/4842450#4842450)會幫助你更多。 – Oleg 2011-04-10 10:21:43