0

While using jqGrid's getCell method, it always returns me undefined in IE8. On Mozilla it works fine.

$('#grid').jqGrid('getCell',id,column); //returns undefined in IE8 :(

Should I use the method defined in this answer instead.

function getCellValue(rowId, cellId) {
   var cell = jQuery('#' + rowId + '_' + cellId);        
   var val = cell.val();
   return val;
}

What is the best approach? I have treegrid implemented and am using version 4.3.1 of jqGrid.

My configurations is

var grid = $("#grid").jqGrid({
treeGrid: true,
treeGridModel: 'adjacency',
ExpandColumn: 'businessAreaName',
ExpandColClick : true,
url:'agileProgramme/records.do',
datatype: 'json',
mtype: 'GET',
colNames:['Id'
          , 'Business Area'
          , 'Investment'
          , 'Org'
          , 'Goal'
],
colModel:[
/*00*/          {name:'agileProgrammeId',index:'agileProgrammeId', width:0, editable:false,hidden:true},
/*01*/          {name:'businessAreaName',index:'businessAreaName', width:160, editable:false},
/*02*/          {name:'programmeName',index:'programmeName', width:150, editable:false, classes:'link'},
/*03*/          {name:'org',index:'org', width:50, editable:false, classes:'orgHierarchy', sortable : false},
/*04*/          {name:'goal',index:'goal', width:70, editable:false}
],
treeReader : {
    level_field: "level",
    parent_id_field: "parent", 
    leaf_field: "leaf",
    expanded_field: "expanded"
},
autowidth: true,
height: 240,
pager: '#pager',
sortname: 'id',
sortorder: "asc",
toolbar:[true,"top"],
caption:"TableGridDemo",
emptyrecords: "Empty records",
jsonReader : {
    root: "rows",
    page: "page",
    total: "total",
    records: "records",
    repeatitems: false,
    cell: "cell",
    id: "agileProgrammeId"
}
});   

Thanks Oleg for the response. I found the root cause of the problem. It is in the $.unformat method of jqGrid.

 return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());

I changed it to

return (typeof ret != 'undefined') ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());

Actually the ret !== undefined is not working in ie8. Once, I changed it to typeof ret != 'undefined', it worked like expected.

Community
  • 1
  • 1
Nehal Damania
  • 8,671
  • 9
  • 37
  • 52

1 Answers1

1

I supposed that you used getCell in the wrong place. The most safe place to use getCell in in loadComplete or inside of some other callback. In case situation you are sure that the data which you try to read are already in jqGrid. IE8 is much slowly as other web browsers so I can only suppose that even you used getCell in the wrong place the modern browsers are already read the grid contain and so your tests were successful.

The demo I made based on the code which you previously posted. It read 'programmeName' from the first loaded row with respect of getCell and display it with respect of alert. How you can verify the code works without any problem in IE8.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks a lot Oleg for the demo. The demo is working fine in IE8. However, when I paste the same code that you have in the loadComplete method in my jqGrid implementation, it returns me undefined. So, I think the problem lies elsewhere. I will try to debug and let you know once finished. – Nehal Damania Apr 03 '12 at 03:49
  • Oleg, I got the root cause of the problem. It is in the $.unformat method. I have updated my original question with the answer. – Nehal Damania Apr 03 '12 at 04:55
  • @Nehu: Could you post the test data which can be used to reproduce the problem. The demo which I posted use `getCell`. Which data should be used to reproduce the problem? Do you overwrite `undefined`? – Oleg Apr 03 '12 at 05:28
  • Oleg, I only found out that `ret !== undefined` is not working in IE8, but works in Mozilla. From this answer in SO - [whether a variable is undefined](http://stackoverflow.com/a/1485852/470347), I replaced the above with `typeof ret != 'undefined'` and it worked. I have seen few more places in jqGrid code which uses variable === undefined, which can also be changed. – Nehal Damania Apr 03 '12 at 05:52
  • Also, I have few more columns and they are updated via setCell method when the grid is loaded. Then, when I get the value for any Cell usind getCell, the $.unformat method is called, wherein lies the issue – Nehal Damania Apr 03 '12 at 06:01
  • @Nehu: Could you post *test data* which can be used to reproduce the problem? The main advantage of usage of `typeof ret !== 'undefined'` compared with `ret !== undefined` is that the value of `undefined` can be overwritten. For example you can use `undefined = 123;`. So could you post the test data which one can use to reproduce the problem. It's important to know whether your code or code of jqGrid change the value of `undefined`. – Oleg Apr 03 '12 at 06:06
  • I tried your demo independently in IE8 and it worked fine. Then, I embedded your demo in my application and the getCell method broke. So, I think you are right, something in the application or the various jquery plugin I am using is changing the value of `undefined`. I am using the following additional plugins : sparkline, jquery.layout, jquery UI.Also, using DWR... Also, I see that the tree Grid's child Node image changes from the small circle to upper arrow in IE8 when embedded. Your demo independently works perfectly fine. Ill try to find out which plugin or javascript is breaking jqGrid – Nehal Damania Apr 03 '12 at 06:35