tags:

views:

305

answers:

2

I'm using jqgrid to create a grid. I have looked but can't seem to find a solution. I'm trying to add links to the column headers.

Any help appreciated. Thanks

A: 

jqGrid creates the column header names using names in the colName list. So you can try putting the markup directly in this list during grid initialization:

colNames:['<a href="#test">Test</a>', 'Column 2', ... ],

I have not tested this, so YMMV. Also keep in mind there may be usability issues - a user is probably going to expect that clicking on a header would sort the column.

Justin Ethier
I have tried this but nothing happens:colNames:['<a href="http://www.cnn.com">Test</a>',Any other ideas?Thanks
Noe
+1  A: 

Use jQuery to bind your click event:

jQuery(document).ready(function() {
    $("#jqgh_colName").click(function() {
        alert('jqgh_colName clicked');
    });
});
gurun8
This is probably the best solution, just use window.location (for example) to link to the new URL. If you want you can also still use mine below, as it will allow a user to see the URL in their status bar, and allow them to right-click on it to open in a new tab/window. Noe - That said, I still have concerns about the usability of what you are trying to accomplish.
Justin Ethier
Thanks gurun8! This works for me.Justin, I'm using this on columns that are not sortable and I will have the text be underlined so they know its a link. Any suggestions on doing it differently? I will also be using your code to do exactly what you said. Thanks guys.
Noe
Noe - Glad you got it working! It sounds like you have all your bases covered, no further suggestions from me :)
Justin Ethier