I have inserted an image and text in jqgrid cells using a formatter as follows:
function myFormatter (cellvalue, options, rowObject)
{
switch(cellvalue){
case 'Unknown': newCell="<img src='../../Content/images/ui-flag_green.png' />"+cellvalue;break;//unknown
case 'Informational' : newCell="<img src='../../Content/images/ui-flag_green.png' />"+cellvalue;break; //informational
case 'Warning' : newCell="<img src='../../Content/images/ui-flag_green.png' />"+cellvalue;break; //warning
}
return newCell;
}
I need to check each value of my cell for another operation.So I need to get only the text part of the cell value.
Something like this:
var rows =myGrid.getRowData();
//for(var i=1;i<=rows;i++)
for(var i=1;i<=rows.length;i++)
{
var rowdata =myGrid.getRowData(i);
var Val = rowdata.myColumn;
switch(Val){
case 'Unknown': do this 1;break;//unknown
case 'Informational' : do THIS 2;break; //informational
case 'Warning' : do this 3;break; //warning
}
The Val
obtained is the image
but my requirement is the text .
Why don't you add a title and id to the image in the formatter like below:
something like this :
<img id='cusmFrmt_"+rowObject.id+"' title='"+cellvalue+"'
src='../../Content/images/ui-flag_green.png' />"+cellvalue;
So formatter would be:
function myFormatter (cellvalue, options, rowObject)
{
switch(cellvalue){
case 'Unknown': newCell="<img id='cusmFrmt_"+rowObject.id+"' title='"+cellvalue+"' src='../../Content/images/ui-flag_green.png' />"+cellvalue;break;//unknown
case 'Informational' : newCell="<img id='cusmFrmt_"+rowObject.id+"' title='"+cellvalue+"' src='../../Content/images/ui-flag_green.png' />"+cellvalue;break; //informational
case 'Warning' : newCell="<img id='cusmFrmt_"+rowObject.id+"' title='"+cellvalue+"' src='../../Content/images/ui-flag_green.png' />"+cellvalue;break; //warning
}
return newCell;
}
After that in your getRow stuff:
var imgObject = $('#cusmFrmt_'+rowdata.id);
// get cell value
var cellValueTxt = imgObject.attr('title');
So actually it will look like this:
var rows =myGrid.getRowData();
//for(var i=1;i<=rows;i++)
for(var i=1;i<=rows.length;i++)
{
var rowdata =myGrid.getRowData(i);
var Val = rowdata.myColumn;
// get image object
var imgObject = $('#cusmFrmt_'+rowdata.id);
// get cell value
var cellValueTxt = imgObject.attr('title');
switch(cellValueTxt){
case 'Unknown': do this 1;break;//unknown
case 'Informational' : do THIS 2;break; //informational
case 'Warning' : do this 3;break; //warning
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments