This demo is based on Hyperlink to Call JavaScript Function. It triggers a JavaScript event when hyperlink is clicked.
To call JavaScript function on hyperlink click, we use “showlink” in set_col_format method.
In the following example, the gotoUrl() function displays text from one field (productName) and hyperlink from another (productUrl) in the same row.
Javascript:
1 2 3 4 5 6 7 8 | gotoUrl = function (grid,param) { var ar = param.split('='); if (grid.length > 0 && ar.length === 2 && ar[0] === '?id') { var rowid = ar[1]; var url = grid.getCell(rowid, 'productUrl'); window.location.href = url; } }; |
PHP:
1 2 3 4 5 6 7 8 9 10 11 | $dg = new C_DataGrid("select * from products", "productCode", "products"); $dg -> set_col_title("productCode", "Product Code"); $dg -> set_col_title("productName", "Product Name"); $dg -> set_col_title("productLine", "Product Line"); // form hyperlink from another cell that contains URL in product code $dg->set_col_format("productName", "showlink", array("baseLinkUrl"=>"javascript:", "target"=>"_new", "showAction"=>"gotoUrl(jQuery('#products'),'", "addParam"=>"');")); $dg -> display(); |