我用數據庫請求加載網格(在PHP中使用CodeIgniter abd jqgrid helper)。我沒有任何問題可以顯示帶有我的數據的漂亮網格。我想顯示一個帶有復選框的新列,以選擇一個或幾行。加載后無法添加新列。因此,我嘗試這樣做:-在創建網格時添加了列,-在創建時,我添加了帶有函數的'loadComplete'選項,-在播放時,函數被執行。這里是 :function ajoutCheckBox() { var grille = $("#users_grid"); // Construire les checkbox dans la colonne D grille.setColProp('Dest', {editable: true}); grille.setColProp('Dest', {edittype: 'checkbox'}); grille.setColProp('Dest', {editoptions: { value: "True:False" }}); grille.setColProp('Dest', {formatter: "checkbox"}); grille.setColProp('Dest', {formatoptions: { disabled: true}}); // Insérer la valeur false dans toutes les lignes de la colonne D var index = grille.jqGrid('getGridParam', '_index'); for(i in index) { grille.jqGrid('setCell', i, 'Dest', 'False', {}); }}如您所見,gris稱為“ #users_grid”,列名為“ Dest”。我的問題:沒有附加內容...謝謝您的幫助 !XB編輯:我發現以下解決方案:復選框列添加在colModel語句中,為了初始化該值并激活復選框(在創建!時將其禁用),我使用了"loadComplete"回調函數。代碼很簡單,但我很難找到...網格創建:loadComplete: function() { ajoutCheckBox() },colModel:[.... {"name":"Env","index":"Env","width":30,"hidden":false,"align":"left","edittype":"checkbox","formatter":"checkbox","formatoptions":"{ disabled: false}","editable":true,"editoptions":{"editoptions":"{ value: \"True:False\", defaultValue: \"False\" }}","size":10}}, ....]回調函數:function ajoutCheckBox() { var grille = $("#users_grid"); var index = grille.jqGrid('getGridParam', '_index'); for(i in index) { // Pour toutes les lignes du tableau grille.jqGrid('setCell', i, 'Env', 'False'); $('#'+i).find("input:checkbox").removeAttr('disabled'); }}它似乎沒有被優化,但是可以工作!
3 回答

呼如林
TA貢獻1798條經驗 獲得超3個贊
對不起,但我不完全了解您的工作。如果formatter: "checkbox"
用于某列,則復選框的值將根據輸入值自動設置(“ true”,“ yes”或“ 1”會在選中復選框后進行設置)。無需執行其他操作loadComplete
。如果希望不禁用復選框,則需要使用formatoptions: { disabled: false}
該列的屬性 。要檢測復選框狀態的更改,可以使用beforeSelectRow
回調。setCell
例如,可以使用它來保存復選框的新狀態

慕田峪7331174
TA貢獻1828條經驗 獲得超13個贊
我在創建時添加了列的屬性,它更加簡單并且有效。我正在使用loadComplete
回調函數來初始化復選框的布爾值。但是,盡管如此,它們還是不可編輯的editable:true
。我正在尋找原因。
添加回答
舉報
0/150
提交
取消