2016-07-14 63 views
1

我们可以通过获得正常的HTML文本框的默认值:得到默认值文本框的同时在线编辑

$("#textboxId").prop("defaultValue"); 

但是里面的jqGrid(在线编辑),而编辑行,如果选择该文本框并检查defaultValue,它总是空的。

我想在编辑模式时获取文本框的原始值,以检查文本框的值是否真的发生了变化。

请帮忙。谢谢。

+0

的可能的复制[jqGrid的默认值不起作用?](http://stackoverflow.com/questions/10186343/jqgrid-default-value-does-not-work) – Kinetic

+0

感谢响应,但没有。html - defaultValue属性和你提到的文章是一样的吗?没有。 –

回答

1

你需要做的是使用jqGrid选项的onSelectRow函数,当用户单击内联编辑中的行时,获取旧的rowdata,然后使用beforeSaveRow检查更改。

这是它的代码和一个 jsFiddle的链接。

var lastSel = 0; 
      var mydata = [ 
        {id:"1", name: "abc",desc: "desc 11"}, 
        {id:"2", name: "def",desc: "hello there"}, 
        {id:"3", name: "xyz",desc: "desc 44"} 
       ]; 
      $("#list").jqGrid({ 

       datatype: "local", 
       data: mydata, 
       height: "auto", 

       colModel :[ 
       {name:'id',key:true, index:'idcustomers', width:55}, 
        {name:'name', width:100,editable: true}, 
        {name:'desc', width:100,editable: true}     
       ], 
       pager: '#pager', 
       rowNum:10, 
       rowList:[10,20,30], 
       sortname: 'idcustomers', 
       sortorder: 'asc', 
       viewrecords: true, 
       gridview: true, 
       caption: 'Customers', 

       cellsubmit: 'clientArray', 
       onSelectRow: function (id) { 
      var currentRow = $('#list').jqGrid("getRowData",id); 

      if (id && id !== lastSel) { 
      lastSel=id; 
      } 
      else 
      { 
      return; 
      } 
      jQuery('#list').editRow(id, 
      { 
       "keys": true,   
       oneditfunc: function() { 


       }, 
       "successfunc": null, 
       "url": null, 
       "extraparam": {}, 
       "aftersavefunc": null, 
       "errorfunc": null, 
       "afterrestorefunc": null, 
       "restoreAfterError": true, 
       "beforeSaveRow": function (options, rowid) { 
        // jqGrid calls its own SaveRow when the user hits 'Enter'. We need it to call ours. 
        // Note, the 'beforeSaveRow' is undocumented, but it gets invoked before jqGrid calls its own SaveRow method. 

       var newName = jQuery('#' + rowid + '_' + 'name').val();   
        var oldName = currentRow.name; 

       if(newName!=oldName) 
       { 
        alert('changed');    
       } 
        return true; 

       }, 
      }); 
      } 

      });