0

我在 SO 上四处寻找有关此问题的任何线索,发现Jqgrid 在编辑操作中发送“add”为 oper=“add” 为什么?. Oleg 说这是一个错误并且已修复,但我在使用内联编辑时遇到了同样的问题。我正在使用 jqGrid 4.4.1。

就我而言,当我添加一行,保存它然后尝试编辑它时会发生这个问题。单击保存以保存更改后,查询字符串具有oper=add

这是我的脚本供参考。我不认为它漂亮,因为我还在第二天学习这个美妙的插件。

  $(function () {
  var grid = $("#list");

  grid.jqGrid({
      url: "@Url.Action("GetClassList", "Setup")",
      datatype: "json",
      height: 220,
      width: 800,
      colNames: ["Code", "Name", "Duration"],
      colModel: [
            { name: "Code",     index: "Code",      width: 120, editable: true, key: true },
            { name: "Name",     index: "Name",      width: 250, editable: true },
            { name: "Duration", index: "Duration",  width: 120, editable: true }
      ],
      rowNum: 10,
      rowList: [10, 20, 30],
      pager: '#listPager',
      sortname: "Code",
      viewrecords: true,
      sortorder: "desc",
      multiselect: false,
      subGrid: true,
      editurl: "@Url.Action("UpdateClass", "Setup")",
      caption: "Class Information",
      subGridRowExpanded: function(subgrid_id, row_id) {
          var subgrid_table_id, pager_id;
          subgrid_table_id = subgrid_id+"_t";
          pager_id = "p_"+subgrid_table_id;
          $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");

          var classCode = grid.jqGrid("getCell", row_id, "Code");
          var http_get_url = "@Url.Action("GetClassScheduleList", "Setup", new { id = "_CC_PH_" })";
          http_get_url = http_get_url.replace("_CC_PH_", classCode);

          var http_post_url = "@Url.Action("UpdateClassSchedule", "Setup", new { id = "_CC_PH_" })";
          http_post_url = http_post_url.replace("_CC_PH_", classCode);

          jQuery("#"+subgrid_table_id).jqGrid({
              url: http_get_url,
              datatype: "json",
              prmNames: {id: "rid"},
              colNames: ["", "Day", "Start Time", "Block", "Room", "Is Selected"],
              colModel: [
                          { name: "Num",          index: "Num",         width:0,     hidden: true,   key: true },
                          { name: "Day",          index: "Day",         width: 120,                  editable: true, edittype: "select", editoptions: { value: "Sunday:Sunday;Saturday:Saturday;Monday:Monday;Tuesday:Tuesday;Wednesday:Wednesday;Thursday:Thursday;Friday:Friday" }},
                          { name: "Start Time",   index: "Start Time",  width: 120,  align: "right", editable: true},
                          { name: "Block",        index: "Block",       width: 70,   align: "right", editable: true},
                          { name: "Room",         index: "Room",        width: 70,   align: "right", editable: true},
                          { name: "Is Selected",  index: "Is Selected", width: 100,  align: "right", editable: true, edittype: "checkbox", editoptions: { value:"Yes:No" }}
              ],
              rowNum:20,
              pager: pager_id,
              sortname: 'Num',
              sortorder: "asc",
              multiselect: false,
              editurl: http_post_url,
              height: '100%',
          });
          jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit: false, add: false, del: false, search: false },{reloadAfterSubmit: true})
          jQuery("#"+subgrid_table_id).jqGrid('inlineNav',"#"+pager_id)
        },
        subGridRowColapsed: function(subgrid_id, row_id) {
            // this function is called before removing the data
            //var subgrid_table_id;
            //subgrid_table_id = subgrid_id+"_t";
            //jQuery("#"+subgrid_table_id).remove();
        }
  });
  jQuery("#list").jqGrid('navGrid', "#listPager", { edit: false, add: false, del: false, search: false },{reloadAfterSubmit: true});
  jQuery("#list").jqGrid('inlineNav', "#listPager");

});

4

1 回答 1

2

试试这个代码

  serializeRowData: function(postData){

    // new row id is "new_row"
    postData.oper = postData.id == "new_row" ? "add" : "edit";
    return postData;
}
于 2012-10-05T15:03:47.527 回答