jqgrid - how to add parameters to extraparam of saveRow in inline editing mode

好久不见. 提交于 2020-01-11 12:03:19

问题


I have a string:

var str = "it's a beautiful day";

I am passing this string to the function:

rowSave(id, str);

rowSave()

var rowSave = function(id, str){
    jQuery("#myjqgrid").jqGrid('saveRow',id,{
        "succesfunc": function(response) {              
            return true;                
        },                                  
        "url": "server.aspx",
        "mtype": "GET",
        "extraparam": {}
    });
}

What I want to do

I want to

  • split the string based on white space
  • every word in the string (after splitting it) should be passed as a parameter in extraparam so that it gets appended to the url.

I don't know how to do this.

As per Oleg's suggestion (see below), added in the ajaxRowOptions: {cache: false} in my jqgrid definition.

$("#myjqgrid").jqGrid({
   ajaxRowOptions: {cache: false}
});

回答1:


You can define a function similar to the following to build up the extra parameter object:

function encodeStr(str){
    var s = str.split(' '), i, result = {};

    for (i = 0; i < s.length; i++){
        result['param' + i] = s[i];
    }

    return (result);
}

jQuery.ajax is used internally by jqGrid and may ensure proper serialization. If you run into problems, use encodeURIComponent to encode each parameter.

Anyway, then just call into this object when you specify your parameters:

"extraparam": encodeStr(str)



回答2:


The code can be about the following:

var rowSave = function(id, str) {
    var strParts = str.split(' '), l = strParts.length, i, obj = {},
        codeStart = 'A'.charCodeAt(0); // 65

    for (i = 0; i < l; i++, codeStart++) {
        obj[String.fromCharCode(codeStart)] = strParts[i];
    }
    $("#myjqgrid").jqGrid('saveRow', id, {
        succesfunc: function(response) {
            return true;                
        },                                  
        url: "server.aspx",
        mtype: "GET",
        extraparam: obj
    });
}

First the obj will be filled as {A: "it\'s", B: "a", C: "beautiful", D: "day"} and then it will be used as the value of extraparam.



来源:https://stackoverflow.com/questions/9107258/jqgrid-how-to-add-parameters-to-extraparam-of-saverow-in-inline-editing-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!