2011-02-13 62 views
1

我正在做點什麼similar to this question我有一個複選框列表作爲自定義編輯控件。不同的是,我想從服務器(沒有硬編碼在客戶端上檢查1,CHECK2,Check3得到我的名單。在jqGrid中,是否有使用Ajax來獲取custom_element的數據?

有什麼辦法無論是在列設置或custom_element做到這一點功能?

好像我需要類似於您使用選擇項目,但似乎只適用於選擇項目(不定製的)的dataUrl屬性的東西。

有什麼建議?

回答

2

你可以使用任何list選項(要準確editoptions)網格初始化過程中,然後覆蓋從服務器加載的真實數據值:

$("#list").jqGrid({ 
    colModel: [ 
     {name:'MyMultiCheck',edittype:'custom', 
     editoptions:{custom_element:MultiCheckElem, 
         custom_value:MultiCheckVal,list:''} 
     } 
     ... 
    ] 
    ... 
}); 
$.ajax({ 
    url:"getMultiCheckList", 
    // any other parameters like dataType:'json', 
    // type: 'POST' (default type is 'GET') which depend on the server 
    success: function(data){ 
     // the code here depend on the format of data returned from the server 
     // in the simplest situation we have as data already the comma-separated 
     // string which we need as a value for the list parameter so we can do 
     jQuery("#list").setColProp('MyMultiCheck',{editoptions:{list:data}}); 
    } 
}); 
+1

感謝你的幫助。這是非常接近正確的答案,但我想到的一個問題是,如果你只設置列表,它會刪除custom_element和custom_value設置,所以你必須包含這些選項(只需在初始化中重複什麼)以及它工作。 – leora 2011-02-14 01:36:48