Search code examples
buttonjqgridparameter-passingformatterrowid

How to add a redirection button to jqGrid with a rowID parameter


I'm using jqGrid to display a database table on screen, and I need to add at the end of every row a button that redirects me to another page (let's call it page2.php) AND that passes the value of the row ID through to that page.

I've added a column in colModel with a formatter but I can't seem to find the right function to add a functionnal button (the redirection works fine but I have trouble with the ID passing) :

{name:'refresh', index:'refresh', width:70, align:'center', formatter:refreshButton}

And the corresponding function :

function refreshButton(cellvalue, options, rowobject){
    return '<button type="button" onclick="window.location=\'page2.php\'">Go</button>';
}

i found somewhere that adding ?id="+rowid+"&oper=edit after page2.php would work to pass the rowID but then the redirection won't work anymore...

I'd gladly use some help with that, thanks in advance


Solution

  • This code works for me any time I click on the button

    function refreshButton(cellvalue, options, rowobject) {
        return '<button type="button" onclick="location.href=\'page2.php?oper=edit&id='+options.rowId+'\'">Go</button>';
    }