我升級到4.14的jqGrid addRowData不火afterInsertRow
從4.7.1我的jqGrid這是我對初始化腳本電網
jQuery("#detFlex62_1").jqGrid({
url: root + mod + '/detaillistview',
datatype: "local",
colNames:[' ', '<?=lang("users_company_code")?>', '<?=lang("users_company_name")?>', ' ', ' '],
colModel:[
{name:'myac', width:50, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true, editbutton : false, delbutton : false, delOptions: {reloadAfterSubmit:false},editOptions: {reloadAfterSubmit:false}}},
{name:'company_code',index:'company_code', width:100},
{name:'company_name',index:'company_name', width:100},
{name:'company_id',index:'company_id', width:100,hidden:true},
{name:'company_access_id',index:'company_access_id', width:100,hidden:true}
],
width: $('.body').width()-40,
height: 120,
pager: '#pagerFlex62_1',
sortname: 'user_id',
sortorder: "desc",
editurl: root + mod + '/detailpost',
caption:"<?=lang("users_title")?>",
onSelectRow: function(id){
activedf = "#detFlex62_1";
},
afterInsertRow: function (rowid) {
var grid = $(this),
iCol = getColumnIndexByName(grid,'myac'); // 'act' - name of the actions column
grid.find(">tbody>tr[id=" + rowid + "].jqgrow>td:nth-child(" + (iCol + 1) + ")")
.each(function() {
$("<div>",
{
title: "Edit",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click: function(e) {
df_edit_1($(e.target).closest("tr.jqgrow").attr("id"));
/*alert("'Custom' button is clicked in the rowis="+
$(e.target).closest("tr.jqgrow").attr("id") +" !");*/
}
}
).css({float:"left"})
.addClass("ui-pg-div ui-inline-edit")
.append('<span class="ui-icon ui-icon-pencil"></span>')
.prependTo($(this).children("div"));
$("<div>",
{
title: "Delete",
mouseover: function() {
$(this).addClass('ui-state-hover');
},
mouseout: function() {
$(this).removeClass('ui-state-hover');
},
click: function(e) {
df_delete_1($(e.target).closest("tr.jqgrow").attr("id"));
/*alert("'Custom' button is clicked in the rowis="+
$(e.target).closest("tr.jqgrow").attr("id") +" !");*/
}
}
).css({float:"left"})
.addClass("ui-pg-div ui-inline-edit")
.append('<span class="ui-icon ui-icon-trash"></span>')
.prependTo($(this).children("div"));
});
}
});
jQuery("#detFlex62_1").jqGrid('navGrid','#pagerFlex62_1',{edit:false,del:false,search:false, addfunc: df_add_1, editfunc: df_edit_1});
而且這裏是我添加新行到grid
function df_addToJSON_1(form)
{
var idx = $('input[name=index]',form).val();
var id = $('input[name=id]',form).val();
var totalRows = jQuery("#detFlex62_1").jqGrid('getGridParam', 'records');
var data = {
company_code: $('input[name=company_code]',form).val(),
company_name: $('input[name=company_name]',form).val(),
company_id: $('input[name=company_id]',form).val(),
company_access_id: $('input[name=company_access_id]',form).val()
};
if (idx=='')
{
idx = getMaxRowId($('#detFlex62_1'));
$('#detFlex62_1').jqGrid("addRowData", idx + 1, data, "last");
}
else
{
$('#detFlex62_1').jqGrid("setRowData", idx, data);
}
//pCheckShow();
return false;
}
新行被添加,但沒有觸發afterInsertRow事件。這是爲什麼發生?我的代碼中有錯誤嗎?
很榮幸能夠得到您的回覆。我嘗試了你的第一個建議,把afterInsertRow改爲afterAddRow。它不起作用。稍後我會閱讀增強的格式化程序操作。我同意代碼很慢,我將在不久的將來應用增強的格式化程序操作。但是看到AddRow/afterInsertRow之後的事件對我來說不是很奇怪。 (兩者都試過) –
@strike_noir:如果你提供**演示**,一切都會更加簡單。我在[文章](https://free-jqgrid.github.io/getting-started/index.html)中獲得了第一個演示,並對其進行了修改,以測試'afterAddRow'回調。您可以在https://jsfiddle.net/OlegKi/r4xo7ncr /上看到該回調調用。 – Oleg