0

When I use this code below, I am getting "Length of colNames and <> colModel!" error. If isUserGlobal is false, I am not getting any error. I am using jqGrid-4.5.4

receivedColModel.push({name:'NAME', index:'NAME', sortable:true});
receivedColModel.push({name:'SURNAME', index:'SURNAME', sortable:true});
receivedColModel.push({name:'AGE', index:'AGE', sortable:true});
receivedColModel.push({name:'STATUS', index:'STATUS', sortable:true});

receivedColNames.push(messageDictionary['userHistory.NAME']);
receivedColNames.push(messageDictionary['userHistory.SURNAME']);
receivedColNames.push(messageDictionary['userHistory.AGE']);
receivedColNames.push(messageDictionary['userHistory.STATUS']);

if(isUserGlobal == 'true') {
    receivedColModel.push({name:'CITY', index:'CITY', sortable:true});
    receivedColNames.push(messageDictionary['userHistory.CITY']);
}

$('#historyGrid').jqGrid({
     url:'ajax.htm',
     datatype: "json",
     mtype: "POST",
     jsonReader: { repeatitems : false, cell:"", id: "", userdata: "jsonModel", root: "rows" },
     postData:postData,
     colNames:receivedColNames,
     colModel:receivedColModel,
     .
     .
     .

By the way, If I don't use colNames as a parameter as shown below, programs works successfuly. I don't understand, Why this situtation happens. Thank you very much.

receivedColModel.push({name:'NAME', index:'NAME', sortable:true, label:messageDictionary['userHistory.NAME']});
receivedColModel.push({name:'SURNAME', index:'SURNAME', sortable:true, label:messageDictionary['userHistory.SURNAME']});
receivedColModel.push({name:'AGE', index:'AGE', sortable:true, label:messageDictionary['userHistory.AGE'});
receivedColModel.push({name:'STATUS', index:'STATUS', sortable:true, label:messageDictionary['userHistory.STATUS']});

if(isUserGlobal == 'true') {
    receivedColModel.push({name:'CITY', index:'CITY', sortable:true});
}

$('#historyGrid').jqGrid({
    url:'ajax.htm',
    datatype: "json",
    mtype: "POST",
    jsonReader: { repeatitems : false, cell:"", id: "", userdata: "jsonModel", root: "rows" },
    postData:postData,
    colModel:receivedColModel,
    .
    .
    .

1 Answer 1

1

You don't included real parameters of jqGrid. It's clear that you use receivedColModel and receivedColNames for building colNames and colModel`. I guess that the origin of your problem is in the part (in the part which we don't see in the text of your question).

You can don't use colNames at all. Instead of that you can specify the column header with respect of label property of colModel. You will don't have any disadvantages. By the way index property isn't required if it's value is the same as the value of name property. Default value of sortable property is true and you can remove sortable:true too.

1
  • First code block does not work when if statement is true, but second code block works anyway. I currious about this problem. Thank you for your answer.
    – S.Balaban
    Mar 19, 2019 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.