Fseee
Fseee

Reputation: 2631

jqgrid getCell strange behaviour

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?

Upvotes: 2

Views: 4273

Answers (1)

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 2

Related Questions