我试图在免费的jggrid版本4.13.5中添加一行内联新行,但我无法让它工作。 内联编辑有效,但内联添加行没有。这是内联编辑的代码。我试图在子网格内进行编辑和添加选项。此外,不会显示添加,删除和编辑图标。有参考文献。
<link href="~/Content/ui.jqgrid.min.css" rel="stylesheet" />
<link href="~/Content/jquery.custom/jquery-ui-1.12.1.custom-jquery- ui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.2.4.js"></script>
<script src="~/Scripts/jquery-ui-1.8.11.min.js"></script>
<script src="~/Scripts/free-jqGrid/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/free-jqGrid/jquery.jqgrid.min.js"></script>
<script src="~/Scripts/cashjqgridinternal.js"></script>
Cashjggridinternal.js
$(function () {
debugger;
var eXids = [];
function RefreshGridData() {
var num;
eXids = new Array();
$("#grid tr:has(.sgexpanded)").each(function () {
num = $(this).attr('OutputcashID');
eXids.push(num);
});
$("#grid").trigger("reloadGrid");
};
$("#grid").jqGrid({
url: "/OutputCashInternal/GetValues",
datatype: 'json',
mtype: 'Get',
//table header name
colNames: ['OutputcashID', 'Level1', 'Level2', 'LoadID', 'ServerName', 'GroupID', 'InternalAccountRef', 'ExternalAccountRef', 'InternalLocalAmt', 'ExternalLocalAmt', 'TotalRecitems', 'TotalReconcilingItems', 'LocalDifference', 'UnreconcileDifference'],
//colModel takes the data from controller and binds to grid
colModel: [
{ key: true, hidden: true, name: 'OutputcashID', index: 'OutputcashID', editable: false },
{ key: false, name: 'Fund', index: 'Fund', editable: false },
{ key: false, name: 'Custodian', index: 'Custodian', editable: false },
{ key: false, hidden: true, name: 'LoadID', index: 'LoadID', editable: false },
{ key: false, hidden: true, name: 'ServerName', index: 'ServerName', editable: false },
{ key: false, hidden: true, name: 'GroupID', index: 'GroupID', editable: false },
{ key: false, name: 'InternalAccountRef', index: 'InternalAccountRef', editable: false },
{ key: false, name: 'ExternalAccountRef', index: 'ExternalAccountRef', editable: false },
{ key: false, name: 'InternalLocalAmt', index: 'InternalLocalAmt', editable: false },
{ key: false, name: 'ExternalLocalAmt', index: 'ExternalLocalAmt', editable: false },
{ key: false, name: 'TotalRecitems', index: 'TotalRecitems', editable: false },
{ key: false, name: 'TotalReconcilingItems', index: 'TotalReconcilingItems', editable: false },
{ key: false, name: 'LocalDifference', index: 'LocalDifference', editable: false },
{ key: false, name: 'UnreconcileDifference', index: 'UnreconcileDifference', editable: false },
],
loadonce: true,
pager: $('#pager'),
rowNum: 20,
rowList: [10, 20, 30, 40],
height: '100%',
viewrecords: true,
caption: 'OutputCash For Internal User',
emptyrecords: 'No records to display',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
Id: "0"
},
autowidth: true,
scrollerbar: true,
height: 200,
multiselect: false,
subGrid: true,
subGridRowExpanded: function (subgrid_id, row_id) {
// we pass two parameters
// subgrid_id is a id of the div tag created whitin a table data
// the id of this elemenet is a combination of the "sg_" + id of the row
// the row_id is the id of the row
// If we wan to pass additinal parameters to the url we can use
// a method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the flowing
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id + "_t";
pager_id = "p_" + subgrid_table_id;
var pLoadID = $("#grid").jqGrid('getCell', row_id, 'LoadID');
var pGroupID = $("#grid").jqGrid('getCell', row_id, 'GroupID');
var pEditData = { "LoadID": pLoadID, "GroupID": pGroupID };
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + pager_id + "' class='scroll'></div>");
$("#" + subgrid_table_id).jqGrid({
url: "/OutputCashInternal/GetData?sid=" + row_id,
datatype: 'json',
mtype: 'Get',
//table header name
colNames: ['OutputCashUpdatedID', 'LoadID', 'GroupID', 'ExternalAccountRef', 'InternalLocalAmtAdded', 'ExternalLocalAmtAdded', 'TransactionComments', 'InternalComments', 'ClientCommnets'],
//colModel takes the data from controller and binds to grid
colModel: [
{ key: true, hidden: true, name: 'OutputCashUpdatedID', index: 'OutputCashUpdatedID', editable: true },
{ key: false, hidden: true, name: 'LoadID', index: 'LoadID', editable: false },
{ key: false, hidden: true, name: 'GroupID', index: 'GroupID', editable: false },
{ key: false, name: 'ExternalAccountRef', index: 'ExternalAccountRef', editable: false },
{ key: false, name: 'InternalLocalAmtAdded', index: 'InternalLocalAmtAdded', editable: true },
{ key: false, name: 'ExternalLocalAmtAdded', index: 'ExternalLocalAmtAdded', editable: true },
{ key: false, name: 'Comments', index: 'Comments', editable: true },
{ key: false, name: 'Comment1', index: 'Comment1', editable: true },
{ key: false, name: 'Comment2', index: 'Comment2', editable: true, editoptions: { readonly: "readonly" } },
],
//loadonce: false,
rowNum: 20,
pager: pager_id,
sortname: 'Fund',
sortorder: "asc",
height: '100%',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
Id: "0"
}
});
$("#" + subgrid_table_id).jqGrid('navGrid', '#' + pager_id, {
edit: false,
add: false,
del: false,
search: false,
}
);
var editparameters = {
keys: false,
oneditfunc: null,
url: '/OutputCashInternal/Edit',
successfunc: function (val) {
if (val.responseText != "") {
alert(val.responseText);
}
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
},
extraparam: {
rowid: function () {
var sel_id = $("#" + subgrid_table_id).jqGrid('getGridParam', 'selrow');
var value = $("#" + subgrid_table_id).jqGrid('getCell', sel_id, '_id');
return value;
}
},
aftersavefunc: null,
errorfunc: null,
afterrestorefunc: null,
restoreAfterError: true,
mtype: "POST"
}
var saveparameters = {
useDefValues: true,
url: '/OutputCashInternal/Create',
extraparam: {},
mtype: "POST"
}
var parameters = {
edit: true,
editicon: "ui-icon-pencil",
add: true,
addicon: "ui-icon-plus",
save: true,
saveicon: "ui-icon-disk",
cancel: true,
cancelicon: "ui-icon-cancel",
addParams:{ addRowParams: saveparameters },
editParams: editparameters
};
$("#" + subgrid_table_id).jqGrid('inlineNav', '#' + pager_id, parameters);
},
subGridRowColapsed: function (subgrid_id, row_id) {
// this function is called before removing the data
//var subgrid_table_id;
//subgrid_table_id = subgrid_id+"_t";
//jQuery("#"+subgrid_table_id).remove();
},
//pager-you have to choose here what icons should appear at the bottom
//like edit,create,delete icons
gridComplete: function () {
for (var j = 0; j < eXids.length; j = j + 1) {
$("#grid").jqGrid('expandSubGridRow', eXids[j]);
}
},
}).navGrid('#pager', { edit: false, add: false, del: false, search: true, refresh: true })
});
这是控制器:
public string Create(OutputCashUpdated obj)
{
string msg;
try
{
//if (ModelState.IsValid)
//{
//db2.Entry(newOCU).State = EntityState.Modified;
OutputCashUpdated newOCU = new OutputCashUpdated();
OutputCash newOC = db2.OutputCashes.Single(s => s.LoadID == obj.LoadID && s.GroupID == obj.GroupID); // && c.AsOfDate == newOCU.AsOfDate);
db2.OutputCashUpdateds.Add(newOCU);
newOCU.LoadID = newOC.LoadID;
newOCU.GroupID = newOC.GroupID;
newOCU.AsOfDate = newOC.AsOfDate;
newOCU.AppClientID = newOC.AppClientID;
newOCU.InternalLocalAmtAdded = obj.InternalLocalAmtAdded;
newOCU.ExternalLocalAmtAdded = obj.ExternalLocalAmtAdded;
newOCU.Comments = obj.Comments;
newOCU.Comment1 = obj.Comment1;
newOCU.Comment2 = obj.Comment2;
db2.SaveChanges();
var CountReconcileItems = db2.OutputCashUpdateds.Count(w => w.LoadID == newOC.LoadID && w.GroupID == newOC.GroupID && w.AsOfDate == newOC.AsOfDate);
var SumReconcileExternalItems = db2.OutputCashUpdateds.Where(w => w.LoadID == newOC.LoadID && w.GroupID == newOC.GroupID && w.AsOfDate == newOC.AsOfDate).Sum(s => s.ExternalLocalAmtAdded).GetValueOrDefault(0);
var SumReconcileInternalItems = db2.OutputCashUpdateds.Where(w => w.LoadID == newOC.LoadID && w.GroupID == newOC.GroupID && w.AsOfDate == newOC.AsOfDate).Sum(s => s.InternalLocalAmtAdded).GetValueOrDefault(0);
var SumReconcileItems = SumReconcileExternalItems + SumReconcileInternalItems;
newOC.TotalRecitems = CountReconcileItems;
newOC.TotalReconcilingItems = SumReconcileItems;
newOC.UnreconcileDifference = newOC.LocalDifference - newOC.TotalReconcilingItems;
db2.SaveChanges();
msg = "Saved Successfully";
//}
//else
//{
// msg = "Validation data not successfull";
//}
}
catch (Exception ex)
{
msg = "Error occured:" + ex.Message;
}
return msg;
}
我得到的错误是没有序列元素,但在调试时我可以看到元素被传递。所以我无法找出它出错的地方。任何想法都表示赞赏。谢谢!