2

I've a jqgrid and a getCell method which returns the value of a cell depending of id. It works only for the first row of the grid, in others identifyImg = false:

var ids = jQuery("#myGrid").getDataIDs(); 
        for(var i=0;i<ids.length;i++){
            var identifyImg = $('#myGrid').jqGrid('getCell', i, 'idState');
alert(identifyImg); // return false after first row
            if(identifyImg == '1'){
                 //DO SOMETHING 
              }
            }

the column is defined as the follow:

{name:'idState',index:'idState', width:55}

And is correctly populated with numbers. How can I solve this?

1
  • You should post more full code of jqGrid and the test data which can be used to reproduce the problem. Moreover I don't full understand why such code could be needed. In the most cases one should use cellattr, rowattr or custom formatter instead of the enumeration which use getDataIDs.
    – Oleg
    Nov 10, 2012 at 10:46

1 Answer 1

2

you should use

 $('#myGrid').jqGrid('getCell', ids[i], 'idState');

instead of

 $('#myGrid').jqGrid('getCell', i, 'idState');

I want additionally to mention that in the most cases one don't need use loop over ids returned from getDataIDs. It was a good approach in customizing of jqGrid inside of loadComplete or gridComplete in old versions of jqGrid. Now there are more better (from the performance point of view) alternatives. For example if you need to change some style or other attribute of one cell based on the content of one column you can use cellattr (see the answer, the answer, the answer, the answer or other). If you need to change some attributes of the whole row based on the content of one column you can use rowattr (see the answer). In other cases if you need to change content of the cell (not an attribute) based on the content of another cell you can use custom formatter.

0

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.