2013-08-22 119 views
0

我有一個jQgrid有兩列,名稱列和分數列。只有分數列是可編輯的。用戶從下拉列表中選擇一個分數。他們按下Enter鍵並保存樂譜。但是,用戶不想按回車。他們希望分數在下拉列表中選擇分數時保存(基本上,是一個onchange事件)。jQgrid內聯編輯替換回車鍵保存onchange

比分代碼看起來是這樣的:當用戶選擇從下拉菜單中的得分

{name:'RatersScore', index:'RatersScore', width:200, align:'center', sortable:true, search:false, editable: true, edittype: 'select', editoptions: { value: "6.0:6.0;6.5:6.5;7.0:7.0;7.5:7.5;8.0:8.0;8.5:8.5;9.0:9.0;9.5:9.5;10.0:10.0", dataEvents: [{ type: 'change', fn: function(e) {myfunction(); } },]}}, 

但是什麼也沒有發生。更改不會觸發myfunction()。

用戶在使用IE 8

回答

0

我懷疑這是一個完美的解決方案,但是這是對我工作。

{name:'RatersScore', index:'RatersScore', width:200, align:'center', sortable:true, search:false, editable: true, edittype: 'select', editoptions: { value: "6.0:6.0;6.5:6.5;7.0:7.0;7.5:7.5;8.0:8.0;8.5:8.5;9.0:9.0;9.5:9.5;10.0:10.0", dataEvents: [{ type: 'change', fn: function(e) { 
var thescore = $(e.target).val(); 
var row = $(e.target).closest('tr.jqgrow'); 
var thisid= row.attr('id'); 
var f = $("#frmscores"); 
var action = '/myController/MyAction?thescore='+thescore+'&theraterid='+thisid; 
var serializedForm = f.serialize(); 
$.post(action, serializedForm,checkscoreResponse,"json"); 
$('#mygrid').trigger('reloadGrid'); 
} },]}}, 

在這種情況下,序列化不是必需的,但我仍然無論如何都離開它。我猜測有比使用我這裏的AJAX代碼更好的方法。必須有一個更好的JQuery函數。

2

如果你看看他們的Documentation仔細一看,你可以找到方法(saveRow)被用於此目的,

{ name: 'Decision', width: 200, editable: true, formatter: 'select', edittype: 'select', editoptions: { 
         value: { 
          '1': 'First Option', 
          '2': 'Second Option', 
          '3': 'third Option' 
         }, 
         dataEvents: [ 
           { 
            type: 'change', 
            fn: function (e) { 
             var row = $(e.target).closest('tr.jqgrow'); 
             var rowId = row.attr('id'); 
             jQuery("#jQGridId").saveRow(rowId, false, 'clientArray'); 
            } 
           } 
          ] 
        } 
        }, 

的DataEvent火上改變事件的每個下拉列表中的函數, 希望它有助於。乾杯。