如何添加jqGrid自定义错误消息?

时间:2012-10-22 17:02:34

标签: php jquery codeigniter jqgrid

我正在使用CodeIgniter和JQuery Grid。我已经看到你在这里就这个话题做出的回答,但是我没能用它们来解决我的问题。
事实是我有一个jqGrid,我需要显示插入数据库服务器返回的几种错误类型的对话框。

例如,在一种情况下我有这个错误:

  

关键'user_store_turn_index'的重复条目'18 -2-1-2012-10-25'

我需要得到这个并显示自定义消息而不是当前消息:

  

错误状态:'内部服务器错误'。错误代码:500

我尝试过aftersubmit事件。我已经阅读了文档,并看到了可用的示例,但没有任何作用。

在我的JavaScript代码中,我有一个处理jqGrid的提交后事件的函数:

afterSubmit : function(response, postdata){ 
    test_validate
           return false;
    },
}

然后,我编写了应该获得后提交事件响应的函数:

function test_validate(response,postdata) {
    alert('test');
    if(response.responseText == '') {
        success = true;
    } else {
        success = false;
    }
    return [success,response.responseText]
}

但没有任何反应......这是几乎完整的jquery网格代码

$(document).ready(function() {

           var grid = jQuery("#newapi_1351189510").jqGrid({
                    ajaxGridOptions : {type:"POST"},
                      jsonReader : {
                      root:"data",
                      repeatitems: false
                   },
                    rowList:[10,20,30],
                    viewrecords: true
                   ,url:'http://localhost/sp/index.php/turn_open/getData'
,editurl:'http://localhost/sp/index.php/turn_open/setData'
,datatype:'json'
,rowNum:'20'
,width:'600'
,height:'300'
,pager: '#pnewapi_1351189510'
,caption:'Apertura de caja'
,colModel:[
{name:'username',index:'username',label:'Usuario' ,align:'center',width:180,editable:false  }
,{name:'TurnName',index:'TurnName',label:'Turno' ,align:'center',width:180,editable:false  }
,{name:'date',index:'date',label:'Fecha' ,width:100,editable:true,edittype:'text',editrules:{required:false,date:true}  ,editoptions: {size: 10, maxlengh: 10,dataInit: function(element) { $(element).datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,changeYear: true,yearRange: '1982:2022'})}},searchoptions: {size: 10, maxlengh: 10,dataInit: function(element) { $(element).datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,changeYear: true,yearRange: '1982:2022'})}}}

]       })
            jQuery("#newapi_1351189510")
            .jqGrid('navGrid',
            '#pnewapi_1351189510',
            {view:false,
            edit:'1',
            add:'1',
            del:'1',
            close:true,
            delfunc: null
        },
         afterSubmit : function(response, postdata)
          { test_validate
           return false;
         },
        }, 
        {mtype: 'POST'} /*delete options*/,
        ).navButtonAdd('#pnewapi_1351189510',
                { caption:'', buttonicon:'ui-icon-extlink', onClickButton:dtgOpenExportdata, position: 'last', title:'Export data', cursor: 'pointer'}
                );
        ;

             function test_validate(response,postdata){
             alert('test');
               if(response.responseText == ''){
                 success = true;
                }else{
                success = false;
                }
                return [success,response.responseText]
             }

        });

0 个答案:

没有答案
相关问题