我对jqGrid很新,这看起来很棒。这里有很多很棒的文档。 我在编辑方面遇到了困难。我有一个多行的网格,我不能编辑除第一行之外的所有行,当行ID为0时,方法'editGridRow'存在一些问题。当行ID为其他行时,它有效精细。像'getCell'这样的其他方法工作正常,即使Row id = 0。
我该如何解决这个问题?
感谢您的帮助。
$("#grid").jqGrid({
altRows: true,
datatype: 'local',
direction: 'rtl',
height: '100%',
mtype: 'POST',
hidegrid: false,
colNames: ['מספר הקלסר', 'שם השולח', 'מעגל', 'נושא ראשי', 'הגוף המשלם', 'מספר ארגז', 'תאריך שליחה', 'תאריך התחלה', 'תאריך סיום', 'תאריך גריסה', ''],
colModel: [
{ name: 'idFolders', index: 'idFolders', align: 'center', sorttype: 'int' },
{ name: 'SenderName', index: 'SenderName', align: 'center', editable: true },
{ name: 'Maagal', index: 'Maagal', align: 'center', editable: true },
{ name: 'MainSubject', index: 'MainSubject', align: 'center', editable: true },
{ name: 'PayerName', index: 'PayerName', align: 'center', editable: true },
{ name: 'BoxNumber', index: 'BoxNumber', align: 'center', sorttype: 'int', editable: true },
{ name: 'SentDate', index: 'SentDate', align: 'center', sorttype: 'date', datefmt: 'd,m,y', editable: true },
{ name: 'FolderStartDate', index: 'FolderStartDate', align: 'center', sorttype: 'date', datefmt: 'd,m,y', editable: true },
{ name: 'FolderEndDate', index: 'FolderEndDate', align: 'center', sorttype: 'date', datefmt: 'd,m,y', editable: true },
{ name: 'TrashDate', index: 'TrashDate', align: 'center', sorttype: 'date', datefmt: 'd,m,y', editable: true },
//A column for Buttons - edit, delete, with custom Formatter - "formattEdit"
{name: 'myac', align: 'right', sortable: false, resize: false, formatter: formattEdit }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30, 40, 50, 100],
sortname: 'idFolders',
sortorder: 'asc',
viewrecords: true,
gridview: true,
caption: 'תוצאות החיפוש',
editurl: 'SearchWebService.asmx/editFoldersTable',
.......
主网格
//formattEdit, creating 2 buttons - Del, Editform.
function formattEdit(cellvalue, options, rowObject) {
var del, edit, HoverString, htmlString = "";
var rowid = options.rowId;
//Creating the Commands in a Long String
//Edit
edit = "onclick=$('#grid').jqGrid('editGridRow'," + rowid + ",{editData:{idFolders:$('#grid').jqGrid('getCell'," + rowid + ",'idFolders')}});";
HoverString = " onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover');"
edit = edit + HoverString;
htmlString = htmlString + "<div title='" + $.jgrid.nav.edittitle + "' style='float:right;cursor:pointer;' class='ui-pg-div ui-inline-edit' " + edit + "><span class='ui-icon ui-icon-pencil'></span></div>";
//Delete
del = "onclick=alert('Deleteing');";
del = del + HoverString;
htmlString = htmlString + "<div title='" + $.jgrid.nav.deltitle + "' style='float:right;margin-right:5px;' class='ui-pg-div ui-inline-del' " + del + "><span class='ui-icon ui-icon-trash'></span></div>";
//Adding it as Html
return "<div style='align:center;'>" + htmlString + "</div>";
}
我的自定义格式化程序 - 在那里调用'editGridRow'方法
//Search Button - Ajax Call
$("#searchBtn").click(function () {
if ($("#searchBox").val() == "") {
alert("נא הקלד חיפוש");
}
else {
var grid = $("#grid")
grid.jqGrid("clearGridData", true).trigger("reloadGrid");
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'SearchWebService.asmx/getTablejQgrid',
data: CreateSearchString(),
dataType: "json",
success: function (data, textStatus) {
if (textStatus == "success") {
var recivedData = JSON.parse(data.d);
$.each(recivedData.rows, function (key, value) {
grid.jqGrid('addRowData', key, value);
});
grid.trigger('reloadGrid');
}
},
error: function (data, textStatus) {
alert('An error has occured retrieving data!');
}
});
}
});
Ajax调用填充网格
这也是我在Stack Overflow上的第一篇文章。希望我能以正确的方式完成它
答案 0 :(得分:0)
解决
似乎方法'editGridRow'有一个问题,0为值,我在创建网格时将行的键添加1,使得行Id从1开始而不是0.这现在有效。
...
//getting the data from the server
success: function (data, textStatus) {
if (textStatus == "success") {
var recivedData = JSON.parse(data.d);
$.each(recivedData.rows, function (key, value) {
grid.jqGrid('addRowData', 1+key, value);
});
grid.trigger('reloadGrid');
}
},