简体   繁体   中英

Creating dynamic link using phpgrid

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.

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

Did you mean the row id or the number or either? The row id is the value of the primary key of the row.

Here's what potentially you can use a hack to append javascript to back of the querystring.

 $dg -> set_col_dynalink("productLine", "http://www.example.com/", "productName", '"+(rowIndex)+"');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM