我有一个 jgGrid,其中我在页面加载时默认选择了第一行。(所选行突出显示为黄色)。现在,当我在同一个 jqGrid 中选择其他行时,当前选择的行和默认选择的行都以黄色突出显示。理想情况下,当用户选择另一行时,先前选择的行不应以黄色突出显示。
下面是快照以更好地解释:
默认选定行以黄色突出显示(在页面加载中):
当前选定和默认选定行都以黄色突出显示:
下面是我的 jqGrid 代码:
$("#discActionHistGrid").jqGrid({
url:contextRoot+'discActHist',
datatype: 'json',
jsonReader: {repeatitems: false},
mtype: 'POST',
colNames: ['Record ID','Close date','Final Action','Summary','Title','Council','Retraction'],
colModel: [
{ name: 'referralId', index: 'referralId', width: 25 },
{ name: 'closureDate', index: 'closureDate', width: 30, formatter: function(cellValue){return $.datepicker.formatDate('mm-dd-yy', new Date(cellValue));}},
{ name: 'finalAction', index: 'finalAction', width: 30 },
{ name: 'summary', index: 'summary', width: 50, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;line-height: 1.3em;"'; } },
{ name: 'title', index: 'title', width: 30 },
{ name: 'councilNm', index: 'councilNm', width: 30 },
{ name: 'retract', index: 'retract', width: 30, formatter: function (cellvalue, options, rowObject) {return '<a href="'+ contextRoot +'dart/approved">Retract</a>';} }
],loadError: function(xhr,st,err) {
alert(err);
},gridComplete: function() {
$(this).setSelection(1, true);
},onSelectRow : function(rowid, status, e) {
var selRow = $(this).getGridParam("selrow");
var selReferralId = $(this).getCell(selRow, 'referralId');
$("#referralDetailsTab").load(contextRoot+"refDetailsTab?refId=" + selReferralId );
},
pager: '#discActionHistPager',
sortorder: 'desc',
sortname: 'closureDate',
gridview: true,
viewrecords: true,
loadonce: true,
hoverrows : true,
autowidth: true,
height: 'auto',
rowNum: 3,
shrinkToFit: true,
altRows:true
});
$("#discActionHistGrid").jqGrid('navGrid','#discActionHistPager',
{
edit:false,
add:false,
del:false,
search:false,
refresh:false
});
谁能帮我解决这个问题?
在 Oleg 的建议后编辑的代码:
$("#discActionHistGrid").jqGrid({
url:contextRoot+'discActHist',
datatype: 'json',
jsonReader: {repeatitems: false, id: "referralId"},
mtype: 'POST',
colNames: ['Record ID','Close date','Final Action','Summary','Title','Council','Retraction'],
colModel: [
{ name: 'referralId', index: 'referralId', key: true, width: 25 },
{ name: 'closureDate', index: 'closureDate', width: 30, formatter: function(cellValue){return $.datepicker.formatDate('mm-dd-yy', new Date(cellValue));}},
{ name: 'finalAction', index: 'finalAction', width: 30 },
{ name: 'summary', index: 'summary', width: 50, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;line-height: 1.3em;"'; } },
{ name: 'title', index: 'title', width: 30 },
{ name: 'councilNm', index: 'councilNm', width: 30 },
{ name: 'retract', index: 'retract', width: 30, formatter: function (cellvalue, options, rowObject) {return '<a href="'+ contextRoot +'dart/approved">Retract</a>';} }
],loadComplete: function() {
if (this.rows.length > 1) {
// select the first row of the grid
$(this).jqGrid("setSelection", this.rows[1].id, true);
}
referralsCnt = $(this).getGridParam("records");
rowCount = $(this).getGridParam("reccount");
if(referralsCnt > rowCount) {
$("#viewAllReferrals").show();
}
$(this).triggerHandler("reloadGrid");
},loadError: function(xhr,st,err) {
alert(err);
},onSelectRow : function(rowid) {
$("#referralDetailsTab").load(contextRoot + "refDetailsTab?refId=" + rowid);
},
pager: '#discActionHistPager',
sortorder: 'desc',
sortname: 'closureDate',
gridview: true,
viewrecords: true,
loadonce: true,
hoverrows : true,
autowidth: true,
height: 'auto',
rowNum: 3,
shrinkToFit: true,
altRows:true
});
示例 JSON 数据:
{"rows":[{"referralId":"2345","closureDate":1366395788927,"finalAction":"","summary":"","title":"TitleName","councilNm":"CouncilName"},{"referralId":"23455660","closureDate":1366395788927,"finalAction":"Reprimand","summary":"Reprimand and letter of reecommendiation recinded","title":"TitleName","councilNm":"CouncilName"},{"referralId":"23455661","closureDate":1366395788927,"finalAction":"Reprimand","summary":"Reprimand and letter of reecommendiation recinded","title":"TitleName","councilNm":"CouncilName"},{"referralId":"23455662","closureDate":1366395788927,"finalAction":"Reprimand","summary":"Reprimand and letter of reecommendiation recinded","title":"TitleName","councilNm":"CouncilName"},{"referralId":"23455663","closureDate":1366395788927,"finalAction":"Reprimand","summary":"Reprimand and letter of reecommendiation recinded","title":"TitleName","councilNm":"CouncilName"},{"referralId":"23455664","closureDate":1366395788927,"finalAction":"Reprimand","summary":"Reprimand and letter of reecommendiation recinded","title":"TitleName","councilNm":"CouncilName"}],"page":0,"total":0,"records":0}