当我点击导航器上的图标时,我正在尝试添加/删除/编辑行。例如,如果我单击"添加"按钮,我想显示带有我在colNames中设置的列的表单,但我不知道如何做到http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator但我找不到如何指定具有所需列的表单。这是我的代码:
customGrid.js
function criaGrid(){
$("#grid").jqGrid({
datatype: 'json',
url: 'dadosGrid.jsp',
jsonReader: {repeatitems: false, root: 'root'},
pager: '#paginado',
rowNum: 10,
rowList: [10,20,30],
emptyrecords: "Não há registros.",
recordtext: "Registros {0} - {1} de {2}",
loadtext: "Carregando...",
pgtext: "Página {0} de {1}",
height: 250,
colNames:['Código','Nome', 'Ativo', 'Data Inclusão','Login','Email'],
colModel:[
{name:'codigo',index:'codigo', width:80, sorttype:"int"},
{name:'nome',index:'nome', width:120},
{name:'ativo',index:'ativo', width:80, sorttype:"boolean"},
{name:'dataInclusao',index:'dataInclusao', width:120, sorttype:"date", datefmt: 'd-M-Y'},
{name:'login',index:'login', width:80, sortable:false},
{name:'email',index:'email', width:150, sortable:false}
],
multiselect: true,
viewrecords: true,
editurl:"someurl.php",
caption: "Área"
});
$("#grid").jqGrid('navGrid','#paginado',{id:'edit',id:'add',id:'del',search:false,refresh:false})
$('edit').click(function(){
$("#grid").jqGrid('editGridRow',"new",{height:250,reloadAfterSubmit:true});
});
};
您只需要在colModel
中为要编辑的列添加可编辑:true属性。$('edit').click
事件句柄需要删除,因为navGrid
将完成所有工作。
我建议您另外从colModel
中删除所有index
属性,删除不存在的属性sorttype:"boolean"
(请参阅文档)。相反,最好将选项gridview: true
和autoencode: true
添加到jqGrid选项列表中,并考虑将height: 250
替换为height: "auto"
。