I am using phpgrid.com datagrid and want to generate a dynamic grid for my column ‘kbid’. I saw an example on their page as follows:
$dg -> set_col_dynalink("productCode", "http://www.example.com/", "productCode", '&foo=bar');
I made mine similarly:
$dg -> set_col_dynalink("kbid", "../ib/detail.php", "kbid");
Now it shows:
localhost/reskb/ib/detail.php?kbid=1143
but i need to make it like
localhost/reskb/ib/detail.php?offset=0&KBID=4916
here the offset is the row number.
Advertisement
Answer
You are trying to manipulate hyperlink to pass additional parameter through URL. You have to do it in the client with Javascript.
Here’s an example from phpGrid that calls javascript function when user clicks a hyperlink in the grid. Here’s the link:
http://phpgrid.com/example/call-javascript-function-on-hyperlink-click/
You need also to enable row number first (http://phpgrid.com/documentation/enable_rownumbers/)
PHP
$dg->set_col_format("productLine", "showlink", array("baseLinkUrl"=>"javascript:", "target"=>"_self", "showAction"=>"myFunction(jQuery('#products'),'", "addParam"=>"');"));
Javascript
myFunction = function (grid,param) { var ar = param.split('='); if (grid.length > 0 && ar.length === 2 && ar[0] === '?id') { var rowid = ar[1]; var kbid = grid.getCell(rowid, 'kbid'); var rowNum = grid.getInd(rowid); window.location.href = "http://example.com/?offset="+ rowNum +"&kbid="+kbid; } };
Use getInd to get row index as documented here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods