我升级到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