I've a jgGrid in which I'm making the first row default selected on page load.(The selected row is highlighted as yellow). Now when I select some other row in the same jqGrid, the currently selected row and default selected row both are highlighted with yellow color. Ideally when the user selects another row, the previously selected row should not be highlighted yellow.
Below is the snapshot to explain better:
Default Selected row highlighted yellow(in page load):
Currently selected and Default Selected row BOTH highlighted yellow:
Below is my jqGrid code:
$("#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
});
Can anyone please help me out with this?
Edited code after Oleg's advice:
$("#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
});
Sample JSON Data:
{"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}