简体   繁体   中英

inline editing in jqGrid add button not working. while pressing add it calls edit.do url in controller

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);

My controller code is:

@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);
    }

}

You are right. jqGrid have some bugs in inlineNav . Last time I posted the following bug reports: this one , this one , this one , this one and another one . The corresponding changes are already done in the main code on the github . See the commits: this , this , this this and this . So you can for example get fixed code from github or make the corresponding changes in your copy of jquery.jqGrid.src.js .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM