【问题标题】:jQGrid dynamic URI on 'formatoptions' of formatter actions格式化程序操作的“格式选项”上的 jQGrid 动态 URI
【发布时间】:2013-11-19 21:51:25
【问题描述】:

实际上,我已经实现了一个 REST 解决方案,用于从 jQGrid 上的 NavGrid POST、PUT 和 DELETE 数据。

现在在每一行的操作按钮中,我尝试做同样的事情,但我不知道如何在默认格式化程序操作上生成动态 url。

我试试这个:

colModel : [
          {name:'actions', index:'', width:80, fixed:true, sortable:false, resize:false,
              formatter:'actions', 
              formatoptions:{ 
                  url: function(cellValue, rowId, rowData){
                      return restPutURL + '/' + rowId ;
                  },
                  mtype: 'PUT',
                  keys:true,
                  delOptions:{
                      url: restDelURL,
                      recreateForm: true, 
                      beforeShowForm:beforeDeleteCallback,
                      onclickSubmit :function(params, postdata) {
                        params.url += '/' + postdata;
                      }
                  }
              }
          },
          { ...my cols.. }
       ]

删除操作没问题,但编辑不起作用。当保存一行时,jQGrid 发送函数作为 URI 的一部分:

system/function%20(cellValue,%20rowId,%20rowData)%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20console.log(cellValue);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20/system/function%20(cellValue,%20rowId,%20rowData)%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

如何创建动态 URI?或者,如何将已编辑行的 id 添加到 URI?

【问题讨论】:

    标签: jqgrid formatter


    【解决方案1】:

    如果您使用当前版本的 jqGrid,您可以使用beforeSaveRow 回调来执行一些操作,例如修改 URL,然后保存行。不幸的是formatter: "actions" 不允许你设置beforeSaveRow 回调,但你仍然可以使用$.jgrid.inlineEdit 来执行此操作。相应的代码可能类似于

    $.extend(true, $.jgrid.inlineEdit, {
        beforeSaveRow: function (option, rowId) {
            option.url = restPutURL + '/' + rowId;
        }
    });
    

    $.extend(true, $.jgrid.inlineEdit, {
        beforeSaveRow: function (option, rowId) {
            option.url = this.p.editurl + '/' + rowId;
        }
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 2012-07-12
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多