views:

555

answers:

5

Can someone please throw some light on how to go about rendering an hyperlink in the cells of a particular column in ExtJS? I have tried binding the column to a render function in my JS, from which I send back the html:

<a href="ControllerName/viewName">SELECT</a>

However, with this, the problem is that, once I hit the controller through the link, the navigation is successful, but subsequent navigations to the data-grid show up only empty records.

The records get fetched from the DB successfully through the Spring MVC controller, I have checked.

Please note that this happens only once I use the row hyperlink in the extJS grid to navigate away from the grid. If I come to the grid, and navigate elsewhere and again come back to the grid, the data is displayed fine. The problem only occurs in case of navigating away from the grid, using the hyperlink rendered in one/any of the cells.

Thanks for your help!

A: 

Instead of using an anchor tag, I would probably use plain cell content styled to look like an anchor (using basic CSS) and handle the cellclick event of the GridPanel to handle the action. This avoids dealing with the anchor's default click behavior reloading the page (which is what I'm assuming is happening).

bmoeskau
A: 

For these purposes I use CellActions or RowActions plugin depending on what I actually need and handle cell click through it.

If you want something that looks like an anchor, use <span> instead and do what @bmoeskau suggested.

Igor Pavelek
A: 

You can use 'renderer' function to include any HTML you want into cell.

Thevs
+1  A: 

I created a renderer so it looked like you were clicking on it.

aRenderer: function (val, metaData, record, rowIndex, colIndex, store){
// Using CellClick to invoke
return "<a>View</a>";
},

But I used a cell event to manage the click.

cellclick: {
    fn: function (o, idx, column, e) {
        if (column == 1)  // Doesn't prevent the user from moving the column
        {
            var store = o.getStore();
            var record = store.getAt(idx);
            // Do work
        }
    }
}
CrazyEnigma
A: 

Thanks guys for your response. AFter debugging the extJS-all.js script, I found the issue to be on the server side.

In my Spring MVC controller, I was setting the model to the session, which in the use-case I mentioned earlier, used to reset the "totalProperty" of Ext.data.XmlStore to 0, and hence subsequent hits to the grid, used to display empty records.

This is because, ext-JS grid, checks the "totalProperty" value, before it even iterates through the records from the dataStore. In my case, the dataStore had data, but the size was reset to null, and hence the issue showed up.

Thanks to all again for your inputs!

PaiS