2
var parameters = {
    addtext: "Add",
    edittext: "Edit",
    savetext: "Save",
    canceltext: "Cancel",
    edit: true,
    editicon: "ui-icon-pencil",
    add: true,
    addicon:"ui-icon-plus",
    save: true,
    saveicon:"ui-icon-disk",
    cancel: true,
    cancelicon:"ui-icon-cancel",

    editParams : {
        url: "edit.do", 
        mtype: "POST",
        editData: {},
        closeAfterEdit: true,
        reloadAfterSubmit:true,
        aftersavefunc : function(rowid, response) { 
            alert(rowid);
            alert(response);
            var result = eval('(' + response.responseText + ')');
            var errors = "";

            if (result.success == false) {
                for (var i = 0; i < result.message.length; i++) {
                    errors +=  result.message[i] + "<br/>";
                }
            }  else {
                jQuery("#dialog").text('Entry has been edited successfully');
                jQuery("#dialog").dialog({  
                    title: 'Success',
                    modal: true,
                    buttons: {"Ok": function()  {
                        jQuery(this).dialog("close");} 
                    }
                });
            }
            return [result.success, errors, null];
        }
    },

    addParams : {
        useFormatter : false,
        url: "add.do", 
        mtype: "POST",
        closeAfterAdd: true,
        reloadAfterSubmit: true,

        aftersavefunc : function(rowid, response) {
            alert(rowid);
            alert(response); 
            var result = eval('(' + response.responseText + ')');
            var errors = "";

            if (result.success == false) {
                for (var i = 0; i < result.message.length; i++) {
                    errors +=  result.message[i] + "<br/>";
                }
            }  else {
                jQuery("#dialog").text('Entry has been added successfully');
                jQuery("#dialog").dialog({  
                    title: 'Success',
                    modal: true,
                    buttons: {"Ok": function()  {
                        jQuery(this).dialog("close");} 
                    }
                });
            }
            return [result.success, errors, null];
        } 
    }

};
jQuery("#grid").jqGrid('inlineNav',"#pager", parameters);   

//jQuery("#grid").jqGrid('addRow',addParameters);

我的控制器代码是:

@RequestMapping(value = "/add.do", method = RequestMethod.POST)
public @ResponseBody String add(@RequestParam("script_name") String script_name,
        @RequestParam("script_loc") String script_loc,
        @RequestParam("host_url") String host_url,
        @RequestParam("protocol") String protocol,
        @RequestParam("rampup_time") long rampup_time,
        @RequestParam("noof_users") long noof_users,
        @RequestParam("loops") int loops, @RequestParam("delay") long delay) {
    logger.debug("Received request to add a new user");

    String s = script_loc;

    int l = loops;

    System.out.println("loops" + s);

    int max_srno = userService.getMaxSerielNo();
    int new_sr_no = max_srno + 1;

    Boolean success = userService.add(new_sr_no, script_name, script_loc,
            host_url, protocol, rampup_time, noof_users, loops, delay);
    System.out.println("success" + success);
    Gson myGson = new Gson();
    // Check if successful
    if (success == true) {

        // Success. Return a custom response
        CustomGenericResponse response = new CustomGenericResponse();
        response.setSuccess(true);

        response.setMessage("Action successful!");

        // Serialize the List of books into JSON
        return myGson.toJson(response);

    } else {
        // A failure. Return a custom response as well
        CustomGenericResponse response = new CustomGenericResponse();
        response.setSuccess(false);

        response.setMessage("Action failure! ");
        return myGson.toJson(response);
    }

}

@RequestMapping(value = "/edit.do", method = RequestMethod.POST)
public @ResponseBody
String edit(

        @RequestParam("script_name") String script_name,
        @RequestParam("script_loc") String script_loc,
        @RequestParam("host_url") String host_url,
        @RequestParam("protocol") String protocol,
        @RequestParam("rampup_time") long rampup_time,
        @RequestParam("noof_users") long noof_users,
        @RequestParam("loops") int loops,
        @RequestParam("delay") long delay, @RequestParam("id") String id) {

    int seriel_number = Integer.parseInt(id);

    System.out.println("id--------------" + seriel_number);
    logger.debug("Received request to update a new user");
    Boolean success = userService.edit(script_name, script_loc, host_url,
            protocol, rampup_time, noof_users, loops, delay, seriel_number);

    Gson myGson = new Gson();

    if (success == true) {

        // Success. Return a custom response
        CustomGenericResponse response = new CustomGenericResponse();
        response.setSuccess(true);

        response.setMessage("Action successful!");

        return myGson.toJson(response);

    } else {
        // A failure. Return a custom response as well
        CustomGenericResponse response = new CustomGenericResponse();
        response.setSuccess(false);

        response.setMessage("Action failure!");
        return myGson.toJson(response);
    }

}
4

1 回答 1

1

你说的对。jqGrid 在inlineNav. 上次我发布了以下错误报告:this onethis onethis onethis one and another onegithub上的主代码已经做了相应的改动。查看提交:thisthisthis thisthis。因此,您可以例如从github获取固定代码或在您的jquery.jqGrid.src.js.

于 2013-04-03T07:11:49.613 回答