2017-05-22 24 views
0

enter image description here如何在jqGrid的

我有一個jqGrid的添加新的行,我想通過點擊「+」鈕,這是紅色標記添加一行。但模板是空白的。

以下是JavaScript中的腳本。

$("#table_list_1").jqGrid({ 
    url: "usermanage/getMainTableJson", 
    datatype:"json", 
    mytype:"GET", 
    height: 250, 
    autowidth:true, 
    colNames:['id','username','realname','email','createtime','updatetime'], 
    colModel:[ 
     {name:'id',index:'id', width:'10%',align:'center'}, 
     {name:'username',index:'username', width:'15%',align:'center'}, 
     {name:'realname',index:'realname', width:'20%', align:"center"}, 
     {name:'email',index:'email', width:'25%', align:"center"}, 
     {name:'createdate',index:'createdate', width:'15%', align:"center", sortable:false}, 
     {name:'updatedate',index:'updatedate', width:'15%',align:"center", sortable:false} 
    ], 
    rownumbers:false, 
    sortname:'id', 
    sortorder:'asc', 
    viewrecords:true, 
    rowNum:10, 
    rowList:[10,20,40], 
    pager:$('#pager_list_1'), 
    add:true, 
    edit:true, 
    addtext:'Add', 
    edittext:'Edit' 

}); 

$("#table_list_1").jqGrid('navGrid', '#pager_list_1', 
    {edit: true, add: true, del: true, search: true}, 
    {height: 200, reloadAfterSubmit: true} 
); 

回答

0

您應該將editable: true屬性添加到您希望允許編輯的列。您可以使用cmTemplate屬性爲任何屬性指定默認值值。因此,你可以使用例如選項

cmTemplate: { editable: true } 

,並editable: false添加到列id。因此,所有屬性例外id將在添加/編輯對話框中看到。

+0

爲item添加{editable:true}後,它可以工作!謝謝奧列格! – Lisa

+0

@Lisa:不客氣!如果問題現在得到解決,您應該[「接受」](https://meta.stackexchange.com/a/5235/147495)答案。 – Oleg

+0

我是一個新的成員在stackoverflow。非常感謝您的提醒。我接受了你的答案。謝謝〜 – Lisa