jqGrid - 导航栏中的自定义按钮多次添加

时间:2013-12-03 13:02:44

标签: javascript jquery jqgrid

我在导航栏上添加了一个自定义按钮:

function myFunc(){
$("#grid").jqGrid({ 
    datatype: 'json',
    url: 'arquivo.jsp',
    jsonReader: {repeatitems: false, root: 'root'},
    pager: '#paginado',
    rowNum: 10,
    autoencode: true,
    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,
    width: 700,
    colNames:['Código','Nome', 'Ativo', 'Data Inclusão','Login','Senha','Confirma Senha','Email','Grupos'],
    colModel:[                                    
        {name:'codigo', width:80, sorttype:"int", editable: true, editrules: { edithidden: true }},
        {name:'nome', width:120, editable: true, editrules:{required:true}},
        {name:'ativo', width:80, gridview: true, editable: true, edittype:'select', editoptions:{value:{1:'Sim',2:'Não'}}, editrules:{required:true}},     
        {name:'dataInclusao', width:120, sorttype:"date", datefmt: 'd/M/Y', editable: true, editrules:{required:true, date:true}, editoptions: { dataInit: function(el) { setTimeout(function() { $(el).datepicker({ dateFormat: 'dd/mm/yy' }).val(); }, 200); }}},
        {name:'login', width:80, sortable:true, editable: true, editrules:{required:true}},  
        {name:'senha', width:80, sortable:true, editable: true, hidden:true, edittype:'password', editrules:{edithidden:true, required:true, custom:true, custom_func:validaSenha}},
        {name:'confirmaSenha', width:80, sortable:true, editable: true, hidden:true, edittype:'password', editrules:{edithidden:true, required:true}},
        {name:'email', width:150, sortable:true, editable: true, editrules:{required:true, email:true}} 
    ],
    multiselect: true,
    viewrecords: true,    
    editurl:"data?edit=true",
    caption: "Usuários"}
);              
$("#grid").jqGrid('navGrid','#paginado',{},
    {edit:true,url:"teste?acao=edit",closeAfterEdit:true,reloadAfterSubmit:true, 
        beforeShowForm: function(form) {                
            $('#tr_codigo', form).hide(); 
        }, 
        onClickSubmit: function(params, postdata) {
            validaSenha();
        }
    },
    {add:true,url:"teste?acao=teste",closeAfterAdd:true,reloadAfterSubmit:true, 
        beforeShowForm: function(form) { 
            $('#tr_codigo', form).hide(); 
        }, 
        onClickSubmit: function(params, postdata) {
            validaSenha();
        }
    },
    {del:true,reloadAfterSubmit:true, 
        onclickSubmit: function(url, postdata){
            url.url = 'teste?acao=del';
            return {codigo: $('#grid').getCell(postdata, 'codigo')};
        }
    },
    {search:true},
    {refresh:true}
).navButtonAdd('#paginado',{
    caption:"", 
    buttonicon:"ui-icon-suitcase", 
    onClickButton: function(){ 
        var dados = $("#grid").jqGrid('getGridParam','selrow');         
    }, 
    position:"last"
}); 

};

但每当我点击显示我的网格的页面时,会添加一个新按钮,如下图所示:

enter image description here

我不知道我的.jsp是否可以解决这个问题,但我绝对无法找到问题所在。希望你们能帮帮我

提前致谢,

卢卡斯。

2 个答案:

答案 0 :(得分:0)

我使用$('#grid')解决了问题.jqGrid('GridUnload');

答案 1 :(得分:0)

还有另一个线索谈论同样的问题。在较新的版本中,语法已更改。可以帮助别人。请参阅here

$.jgrid.gridUnload("#jqGridId");