我的代码......
public string ConstructButtonEvents(string buttonid, string gridID, string GridControlId, string ActionUrl)
{
StringBuilder sbButtonEvents = new StringBuilder();
GridControlId = GridControlId.Trim();
sbButtonEvents.Append(" $('#" + buttonid + "').die().live('click', function () { ");
sbButtonEvents.Append("var SelectedArtifactDetails = new Array();");
sbButtonEvents.Append(" var CurrentArtifactDetails = new Array();");
sbButtonEvents.Append("for (var i = 0; i < $('#" + gridID + " tbody tr').length; i++) {");
sbButtonEvents.Append(" var rowId = jQuery('#" + gridID + " tr:eq(' + i + ')').attr('id');");
sbButtonEvents.Append("var row = $('#" + gridID + "').jqGrid('getRowData', rowId);");
sbButtonEvents.Append(" if (($('#Status" + GridControlId + "'+rowId).attr('checked') == 'checked') && ($('#Status" + GridControlId + "'+rowId).attr('disabled') != 'disabled')) {");
sbButtonEvents.Append("CurrentArtifactDetails = {");
sbButtonEvents.Append(" Complete: 'Y',");
sbButtonEvents.Append("StakeHolderEmail: $('#Stakeholder" + GridControlId + "'+rowId).attr('value'),");
sbButtonEvents.Append("UploadFile: $('#uploadFile" + GridControlId + "'+rowId).attr('value'),");
sbButtonEvents.Append("PhaseArtifactId: $(row).attr('ID'),");
sbButtonEvents.Append("Status: $('#list" + GridControlId + "'+rowId+' option:selected').text()");
sbButtonEvents.Append("};");
sbButtonEvents.Append("SelectedArtifactDetails.push(CurrentArtifactDetails);");
sbButtonEvents.Append("}");
sbButtonEvents.Append("}");
sbButtonEvents.Append(" $.ajax({");
sbButtonEvents.Append(" url: '" + ActionUrl + "',");
sbButtonEvents.Append(" async: false,");
sbButtonEvents.Append(" loadonce:false, type: 'POST', dataType: 'json', data: JSON.stringify(SelectedArtifactDetails), contentType: 'application/json; charset=utf-8',");
sbButtonEvents.Append(" success: function () {");
//sbButtonEvents.Append(" $('#" + gridID + "').jqGrid('GridUnload');");
sbButtonEvents.Append(" $('#" + gridID + "').trigger('reloadGrid');");
sbButtonEvents.Append(" }, error: function () { alert('error'); }");
sbButtonEvents.Append("});");
sbButtonEvents.Append("});");
return sbButtonEvents.ToString();
}
我有多个标签,但网格ID生成是完美的。我正在构建.cs本身的网格。我需要将行中的数据更新到DB。所以,我有一个更新按钮...点击它我发布(ajax)数据。数据得到了很好的更新。但网格没有重新加载。
点击更新按钮我获取值,然后调用下面的ajax帖子
$.ajax({ url: '/SDLCMClassic/EditProject/BatchUpdate',
type: 'POST',
dataType: 'json',
data: JSON.stringify(SelectedArtifactDetails),
contentType: 'application/json; charset=utf-8',
success: function () {
$('#tblArtifact1').trigger('reloadGrid');
}, error: function () { alert('error'); }
});
});
我能够获取网格中的行值,并且我能够成功发布它。它也在DB中更新。但是没有立即重新加载。如果我刷新整个页面,那么我只能看到更新的数据。
以下是在js
中构造jqgrid的代码$(function () {
$('#tblArtifact1').jqGrid({
url: '/SDLCMClassic/EditProject/FillArtifactGrid?ppmno=188035&phaseName=Project Startup',
datatype: 'json',
mtype: 'GET',
colNames: ['Artifact', 'Complete', 'Status', 'Stakeholder', 'App Reference', 'Document', 'URL', 'ID'],
colModel: [
{ name: 'Name', index: 'Name', editable: false, edittype: '', align: 'left', key: false, hidden: false, formatter: 'showlink', formatoptions: { target: '_blank', baseLinkUrl: '' }, width: $(window).width() * .1, sortable: false },
{ name: 'Complete', index: 'Complete', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .06, sortable: false },
{ name: 'Status', index: 'Status', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .10, sortable: false },
{ name: 'StakeHolderEmail', index: 'StakeHolderEmail', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .15, sortable: false },
{ name: 'App Reference', index: 'App Reference', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .15, sortable: false },
{ name: 'Document', index: 'Document', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .18, sortable: false },
{ name: 'URL', index: 'URL', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .15, sortable: false },
{ name: 'ID', index: 'ID', editable: false, edittype: '', align: 'center', key: false, hidden: true, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .01, sortable: false }
],
viewrecords: true,
sortname: 'Complete',
sortorder: 'asc',
width: 'auto',
height: 'auto',
subGrid: true,
subGridRowExpanded: function (subgrid_id, row_id) {
$('#' + subgrid_id).html(renderhtmlforSubgrid(this, subgrid_id, row_id));
},
gridComplete: function () {
var dataIds = $('#tblArtifact1').jqGrid('getDataIDs');
for (var i = 0; i < dataIds.length; i++) {
$('#tblArtifact1').editRow(dataIds[i], false);
}
},
loadComplete: function () {
ModifyGridDefaultStyles('tblArtifact1');
}
});
});
答案 0 :(得分:2)
您没有发布代码中最重要的部分:定义jqGrid的代码。所以我不得不猜测。
未按.trigger('reloadGrid');
重新加载网格的典型问题是因为您在jqGrid中使用loadonce: true
选项。它会将datatype
从最初的"json"
或"xml"
值更改为datatype: "local"
。因此重新加载确实有效,但重新加载本地数据。如果您需要从服务器重新加载数据,则必须在触发datatype
之前将"json"
重置为初始值"xml"
或reloadGrid
。有关详细信息,请参阅the answer和the answer。