href cell in a data grid Dojo

Alexander picture Alexander · Jul 26, 2011 · Viewed 7.2k times · Source

i cant find how put a cell with an href in a dojo toolkit datagrid, the version od dojo that am using is 1.6 this is my table

  <table id="billsGrid" dojoType="dojox.grid.DataGrid" data-dojo-props="escapeHTMLInData:false">
        <thead>
            <tr>
                <th field="name" width="auto">name</th>
                <th field="description" width="auto">Description</th>
                <th field="activity" width="auto">activity</th>
            </tr>
        </thead>
    </table>

am getting the data with Json.

Answer

Alex Cheng picture Alex Cheng · Jul 26, 2011

You can use formatter function to format a cell. For example, you can declare a JavaScript object that contains all the formatting function.

var myFormatters = {
   formatLink : function(value, index) {
        return "<a href='#'>" + value + "</a>";
   }
};

Then in the grid,

<table id="billsGrid" dojoType="dojox.grid.DataGrid" data-dojo-props="escapeHTMLInData:false" formatterScope="myFormatters"  >
    <thead>
        <tr>
            <th formatter="formatLink" field="name" width="auto">name</th>
            <th field="description" width="auto">Description</th>
            <th field="activity" width="auto">activity</th>
        </tr>
    </thead>
</table>

You don't need to create a scope object for the formatters, then this formatting functions should be in the global scope and then you can omit the formatterScope attribute in the grid.