Helen Araya
Helen Araya

Reputation: 1946

JqGrid Specifying the Column Label using colNames vs using label property from colNames

I have been using jqGrid for a while And I am just wondering what the difference is between using colNames to specify the Label as shown

colNames:['Actions','Inv No'],
colModel [
    {name:'act',index:'act',width:55,align:'center'},
    {name:'inv',width:100,align:'left'}
]

OR using the Label property of colModel as shown below

colModel [
    {label:'Actions', name:'act',index:'act',width:55,align:'center'},
    {label:'Inv No', name:'inv',width:100,align:'left'}
]

Upvotes: 1

Views: 1690

Answers (2)

Oleg
Oleg

Reputation: 221997

There are no differences in both declarations. The usage of colNames is a little shorter because one provides the same information without including the text label: before every text of the column header. On the other side including label: and skipping colNames have some small practical advantages. Everybody who modified old code had made an error: one removed (commented) one column in colModel, but one forget to remove (to comment) the corresponding item in colNames.

I find important to understand how the label information be used. Look at the code fragment:

if (p.colNames.length === 0) {
    for (iCol = 0; iCol < p.colModel.length; iCol++) {
        p.colNames[iCol] = p.colModel[iCol].label !== undefined ?
                p.colModel[iCol].label :
                p.colModel[iCol].name;
    }
}

You can see that jqGrid tests whether colNames is specified. If the colNames is empty array (it's default value of colNames), then the colNames array will be filled with information from label or name property.

It's all. I personally fine the code which uses label instead of colNames more readable.

One additional small remark I have to include to be more exactly. If both colNames and label are specified, then jqGrid uses colNames for column headers, but the label will be used as the label in the Searching Dialog (see the text "Inv No" in the searching dialog).

Upvotes: 1

pratikpawar
pratikpawar

Reputation: 2098

colNames and label does the same thing; assign column name on header layer.

Only difference that I could read into is colNames takes priority over label. if both are defined colNames values are shown as header.

label acts as a backup for colNames. If colNames option is not defined then label option property gets utilized to assign column header.

JSFiddle https://jsfiddle.net/tfkanxhv/ refer to colNames and label values.

Upvotes: 1

Related Questions