I use free jqgrid(v5.1.1) in my asp.net mvc project. In my view,I have 5 level hierarchical jqgrid. how can I set background color of header of each level? for example header of first level has "blue" color,second level has "green" color,third level has "light blue" color and....
here is my code:
//************************************fill grid level 1 **********************************
function FillJQueryGrid(ProjectIdVal) {
$("#jqGrid").jqGrid({
url: '@Url.Action("GetCodingCodeSumLists", "Report")' + '?ProjectId=' + ProjectIdVal,// jqgrid_data,
jsonReader: {
repeatitems: false,
root: function (obj) {
return obj.records;
}
},
datatype: "json",
height: 'auto',
page: 1,
colModel: [
{ label: 'Fieco Doc No.', name: 'comp_code', key: true},
{ label: 'Subject', name: 'Comp_Subject' },
{ label: 'Delay', name: 'sum_delay_count' },
],
width:"100%",
loadonce: true,
autowidth: true,
rowNum: 20,
subGrid: true,
subGridRowExpanded: showChildGridrevision,
pager: "#jqGridPager"
});
};
//***********************************fill grid level 2 *******************************************
function showChildGridrevision(parentRowID, parentRowKey) {
var childGridID = parentRowID + "_table";
var childGridPagerID = parentRowID + "_pager";
var childGridURL = '@Url.Action("GetRevisionSumLists", "Report")' + '?CompCode=' + parentRowKey;
$('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');
$("#" + childGridID).jqGrid({
url: childGridURL,
jsonReader: {
repeatitems: false,
root: function (obj) {
return obj.records;
}
},
datatype: "json",
height: 'auto',
width: "100%",
page: 1,
colModel: [
{label:'CompCode_Revision',name:'CompCode_Revision',key:true,hidden:true},
{ label: 'comp_code', name: 'comp_code', hidden: true },
{ label: 'revision', name: 'revision',width:500 },
{ label: 'Delay', name: 'sum_delay_count',width:500 }
],
loadonce: true,
subGrid: true,
subGridRowExpanded: showChildGridTransmital,
pager: "#" + childGridPagerID
});
}
//***********************************fill grid level 3 *******************************************
function showChildGridTransmital(parentRowID2, parentRowKey2) {
debugger;
var childGridID2 = parentRowID2 + "_table";
var childGridPagerID2 = parentRowID2 + "_pager";
var childGridURL2 = '@Url.Action("GetTransmitalSumLists", "Report")' + '?CompCode_Revision=' + parentRowKey2;
$('#' + parentRowID2).append('<table id=' + childGridID2 + '></table><div id=' + childGridPagerID2 + ' class=scroll></div>');
$("#" + childGridID2).jqGrid({
url: childGridURL2,
jsonReader: {
repeatitems: false,
root: function (obj) {
return obj.records;
}
},
datatype: "json",
height:'auto',
page: 1,
colModel: [
{ label: 'CompCode_Revision_Transmital', name: 'CompCode_Revision_Transmital', key: true,hidden:true},
{ label: 'CompCode_Revision', name: 'CompCode_Revision', hidden: true },
{ label: 'transmital no', name: 'trans_ref_no' ,width:200},
{ label: 'transmital subject', name: 'ChkMain_Subject' ,width:400},
{ label: 'transmital date', name: 'trans_date',width:200 },
{ label: 'Delay', name: 'sum_delay_count',width:200 }
],
width:'100%',
loadonce: true,
subGrid: true,
subGridRowExpanded: showChildGridReceiver,
pager: "#" + childGridPagerID2
});
}
//***********************************fill grid level 4 *******************************************
function showChildGridReceiver(parentRowID, parentRowKey) {
debugger;
var childGridID = parentRowID + "_table";
var childGridPagerID = parentRowID + "_pager";
var childGridURL = '@Url.Action("GetReceiverSumLists", "Report")' + '?CompCode_Revision_Transmital=' + parentRowKey;
$('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');
$("#" + childGridID).jqGrid({
url: childGridURL,
jsonReader: {
repeatitems: false,
root: function (obj) {
return obj.records;
}
},
datatype: "json",
page: 1,
colModel: [
{ label: 'CompCode_Revision_Transmital_receiver', name: 'CompCode_Revision_Transmital_receiver', key: true, hidden: true },
{ label: 'receiver_id', name: 'receiver_id',hidden:true },
{ label: 'Receiver Name', name: 'receiver_name',width:500 },
{ label: 'Delay', name: 'sum_delay_count', width: 500 }
],
loadonce: true,
height: '100%',
subGrid: true,
subGridRowExpanded: showChildGridLetter,
pager: "#" + childGridPagerID
});
}
//***********************************fill grid level 5 *******************************************
function showChildGridLetter(parentRowID, parentRowKey) {
debugger;
var childGridID = parentRowID + "_table";
var childGridPagerID = parentRowID + "_pager";
var childGridURL = '@Url.Action("GetLettersOfCodingWithDelayLists", "Report")' + '?CompCode_Revision_Transmital_Receiver=' + parentRowKey;
$('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');
$("#" + childGridID).jqGrid({
url: childGridURL,
jsonReader: {
repeatitems: false,
root: function (obj) {
return obj.records;
}
},
datatype: "json",
page: 1,
colModel: [
{ label: 'DCC_letter_id', name: 'DCC_letter_id', key: true, hidden: true },
{ label: 'CommentLetter No', name: 'Let_no'},
{ label: 'Subject', name: 'Let_subject' ,width:300},
{ label: 'Estimate Date', name: 'estimate_date_of_letter' },
{ label: 'Send Date', name: 'Let_date' },
{ label: 'Delay', name: 'delay_count_of_letter'}
],
loadonce: true,
height: '100%',
subGrid: false,
pager: "#" + childGridPagerID
});
}
First of all, I want to mention, that there are no free jqGrid v5.1.1. It's commercial version, which price you can see under under link, which you see in the comment at the beginning of jquery.jqGrid.min.js:
"License: http://guriddo.net/?page_id=103334%22"
. Free jqGrid is alternative fork of jqGrid, which I develop starting with the end of 2014, after the end of "jqGrid" and renaming the fork to "Guriddo jqGrid JS".The second important common remark: it's important, that one has no id duplicates on HTML page. Thus one should choose unique
id
values. In case of usage subgrids one can easy get id duplicates if multiple subgrids are opened. One can solve the problem in very easy way, by usageidPrefix
in all subgrids. For example you can useNow about your main problem. There are many ways to use
background-color
to allow the user to see the level of the grid. For example, every subgrid consist of two parts:td.subgrid-cell
andtd.subgrid-data
. One can set background color ontd.subgrid-cell
. You will have the results like on the picture belowOne more option will be setting background color on the column headers of every subgrid. The results will be like
If you would use free jqGrid, then you can use
labelClasses
property ofcolModel
. You need just add the propertylabelClasses: "blue"
tocolModel
and to define the following CSS rule:To add
labelClasses: "blue"
option to all columns of subgrid you can use `cmTemplate``option of the subgrid:The code of
subGridRowExpanded
could be the following:One will be need to add CSS rule like the following
See the demo https://jsfiddle.net/OlegKi/q5j6vnLa/.
If you have to use old jqGrid of Guriddo, then you can't use
labelClasses
, but you can usesetLabel
method, for example, to assign class on the column header.