How to replace hyperlink with text in dojo EnhanceGrid?

134 views Asked by At

I am using dojo EnganceGrid which have 5 columns and the fifth column is image hyperlink. I want to replace hyperlink with text particular row of column. For example, I am clicking on 2nd row of fifth column. When I will click on image and My image hyperlink replace with some text. Can any one help to fix this issue?

For example 
<th field="mobileNumber"  noresize="true" formatter="formatMobileNumber" width="10" cellClasses="alignTextCenter">Mobile Number</th>

<span style="display:none" id="defaultFormatMobileNumber_${ns}">
<a href="javascript:void(0);" onClick="showMobileNumber(event,valueToChange)">
<img src='/images/mobile.png' />
</a>
</span>

function formatMobileNumber(data, rowId){
var link = dojo.byId('defaultFormatMobileNumber').innerHTML;
link = link.replace("valueToChange",rowId);
return link
}

function showMobileNumber_<p:namespace/>(e,rowIdx){
//here I want to replace my link with some text
}
1

There are 1 answers

0
A penguin in Redmond On

The text that you want to show should be returned by the formatter. You could have showMobileNumber set some variable, say clickedRow, to the clicked row number and adapt formatMobileNumber to take that variable into account:

clickedRow = -1;

function formatMobileNumber(data, rowId){
  if (clickedRow != rowId) {
    var link = dojo.byId('defaultFormatMobileNumber').innerHTML;
    link = link.replace("valueToChange",rowId);
    return link;
  }
  else {
    return "some text";
  }
}

function showMobileNumber_<p:namespace/>(e,rowIdx){
  clickedRow = rowIdx;
  // now the grid should probably be refreshed so that the formatter is 
  // re-applied. If variable 'grid' holds the grid:
  // grid._refresh();
}