2013-10-10 28 views
2

我正在使用jqgrid的inlineNav选项向工具栏添加“添加”选项。我也在使用动作格式化程序进行编辑和删除。 当我添加一个新行时,新添加的行有一个编辑图标和一个取消图标,而保存图标位于添加旁边的工具栏上。jqgrid inlineNav add - 在添加的行上显示保存图标

有没有办法指定新添加的行有保存和取消图标,而不是具有编辑图标?

回答

2

如果有人有类似的问题。

我结束了自己的格式化程序。

inlineNavAction = function(cellvalue, options, rowObject, isSavedRow){ 
     if(isSavedRow !== true){ 
      var rowid = options.rowId; 
      var ocl = "id='jSaveButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; 
      var str = "<div title='"+$.jgrid.edit.bSubmit+"' style='float:left;' class='ui-pg-div ui-inline-save' "+ocl+"><span class='ui-icon ui-icon-disk'></span></div>"; 
      ocl = "id='jCancelButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; 
      str += "<div title='"+$.jgrid.edit.bCancel+"' style='float:left;margin-left:5px;' class='ui-pg-div ui-inline-cancel' "+ocl+"><span class='ui-icon ui-icon-cancel'></span></div>"; 
      return "<div style='margin-left:8px;'>" + str + "</div>"; 

     }else{ 
      return $.fn.fmatter.actions(cellvalue, options, rowObject); 
     } 

    } 

isSavedRow为真在格式化的情况下,通过后一排已经被保存,由于被加入到被再次调用。我也默认rowId为0. 默认操作传递false。 我把标记为保存和GitHub上可用的源取消4.5版

用法:

formatter: function(cellvalue,options,rowObject) { 
    return inlineNavAction(cellvalue,options,rowObject, (options.rowId!='new_row')); 
} 

(options.rowId!='new_row') 

的NEW_ROW是不管你已经设置为默认的ROWID添加一行。 new_row是默认值。

0

更改actionformatter到:

formatter: function (cellvalue, options, rowObject) { 
       if (cellvalue === undefined && options.rowId === "_empty") { 
        // remove edit and del buttons 
        options.colModel.formatoptions.editbutton = false; 
        options.colModel.formatoptions.delbutton = false; 
       } 
      return $.fn.fmatter.actions(cellvalue, options, rowObject); 
     }, 

,然后在inlineNavaddParams我们:

  addParams: { 
       position: "last", 
       rowID: '_empty', 
       useDefValues: true, 
       addRowParams: { 
       url: '....', 
       key: true, 
       restoreAfterError: false, 
       oneditfunc: function(rowId) { 
        // display the save and cancel buttons 
        $("#jSaveButton_" + rowId).show(); 
        $("#jCancelButton_" + rowId).show(); 
       }, 
     // ... the rest 
      }, 
相关问题