hyperlink Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Tue, 03 Dec 2024 18:30:38 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 Display Hyperlink From Another Field of The Same Row https://phpgrid.com/example/display-hyperlink-from-another-field-of-the-same-row/ Sat, 17 Feb 2018 09:56:49 +0000 http://phpgrid.com/?p=9420 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: […]

The post Display Hyperlink From Another Field of The Same Row appeared first on phpGrid - PHP Datagrid.

]]>
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
12
13
14
15
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$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();

See live demo!

The post Display Hyperlink From Another Field of The Same Row appeared first on phpGrid - PHP Datagrid.

]]>
9420
Hyperlink to Call JavaScript Function https://phpgrid.com/example/call-javascript-function-on-hyperlink-click/ Sun, 15 Jul 2012 20:59:37 +0000 http://phpgrid.com/?p=2199 You can show hyperlink using set_col_link for static link or set_col_dynalink for dynamic link. What about if you want to do something even fancier, like open a new window, or trigger a JavaScript event when hyperlink is clicked? To call JavaScript function on hyperlink click, use “showlink” in set_col_format method. In the following example, the […]

The post Hyperlink to Call JavaScript Function appeared first on phpGrid - PHP Datagrid.

]]>
You can show hyperlink using set_col_link for static link or set_col_dynalink for dynamic link. What about if you want to do something even fancier, like open a new window, or trigger a JavaScript event when hyperlink is clicked?

To call JavaScript function on hyperlink click, use “showlink” in set_col_format method.

In the following example, the first set_col_format displays text in alert window using JavaScript function “myFunction” to retrieved text from a different cell in the same row. The second does a phpgrid.com site search using jQuery Ajax function “phpGridSiteAjaxSearch”, and displays the result in a alert message window.

PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$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");

$dg->set_col_format("productLine", "showlink", array("baseLinkUrl"=>"javascript:", "target"=>"_self",
"showAction"=>"myFunction(jQuery('#products'),'",
"addParam"=>"');"));

$dg->set_col_format("productName", "showlink", array("baseLinkUrl"=>"javascript:", "target"=>"_self",
"showAction"=>"phpGridSiteAjaxSearch(jQuery('#products'),'",
"addParam"=>"');"));
$dg -> display();

JavaScript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
myFunction = function(grid, param) {
    var ar = param.split('=');
    if (grid.length > 0 && ar.length === 2 && ar[0] === '?id') {
        var rowid = ar[1];
        var prodDesc = grid.getCell(rowid, 'productDescription');

        alert(prodDesc);
    }
};

phpGridSiteAjaxSearch = function(grid, param) {
    var ar = param.split('=');
    if (grid.length > 0 && ar.length === 2 && ar[0] === '?id') {
        var rowid = ar[1];
        var productName = grid.getCell(rowid, 'productName');

        jQuery.ajax({
            url: 'https://phpgrid.com',
            data: {
                s: productName
            },
            type: 'GET',
            dataType: 'text',
            success: function(data, status) {
                // your code goes here for a successul Ajax call .e.g open a new window
                alert(data);
            },
            error: function(data, status, err) {
                alert(data + status);
            }
        });
    }
};

See Live Example

The post Hyperlink to Call JavaScript Function appeared first on phpGrid - PHP Datagrid.

]]>
2199
Display Dynamic URL https://phpgrid.com/example/display-dynamic-url/ Thu, 16 Sep 2010 23:42:51 +0000 http://64.38.236.7/?p=522 From example above, we learn that phpGrid can display simple, static URL using set_col_link() method. However, it is often for database driven webpage that URL is dynamically formed based on parameters value. Method set_col_dynalink() is designed specially for this purpose. The following demonstrates passing the column orderNumber as the dynamic value used as part of […]

The post Display Dynamic URL appeared first on phpGrid - PHP Datagrid.

]]>
From example above, we learn that phpGrid can display simple, static URL using set_col_link() method. However, it is often for database driven webpage that URL is dynamically formed based on parameters value. Method set_col_dynalink() is designed specially for this purpose.

The following demonstrates passing the column orderNumber as the dynamic value used as part of the URL.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("select * from products", "productCode", "productCode");
$dg -> set_col_title("productCode", "Product Code");
$dg -> set_col_title("productName", "Product Name");
$dg -> set_col_title("productLine", "Product Line");
         
// display static Url
$dg -> set_col_link("productUrl");
                 
// display dynamic url. e.g.http://www.example.com/?productCode=101&foo=bar
$dg -> set_col_dynalink("productCode", "http://www.example.com/", "productCode", '&foo=bar');                                                                  

$dg -> display();

See Live Example!

The post Display Dynamic URL appeared first on phpGrid - PHP Datagrid.

]]>
522
Hyperlink Display https://phpgrid.com/example/display-hyperlink/ Thu, 16 Sep 2010 23:36:07 +0000 http://64.38.236.7/?p=520 You can display the text in column as static hyperlink by calling set_col_link() and passing the column name. Note this method only display static URL stored in database field. To display dynamic URL links based in variables, see the next example on set_col_dynalink() method. Please note we are using Products table in this example. 12345678910111213// […]

The post Hyperlink Display appeared first on phpGrid - PHP Datagrid.

]]>
You can display the text in column as static hyperlink by calling set_col_link() and passing the column name. Note this method only display static URL stored in database field. To display dynamic URL links based in variables, see the next example on set_col_dynalink() method.

Please note we are using Products table in this example.

1
2
3
4
5
6
7
8
9
10
11
12
13
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("select * from products", "productCode", "productcode");
$dg -> set_col_title("productCode", "Product Code");
$dg -> set_col_title("productName", "Product Name");
$dg -> set_col_title("productLine", "Product Line");

// display static Url
$dg -> set_col_link("productUrl");                                            
                                                                                     
$dg -> display();

See Live Example!

The post Hyperlink Display appeared first on phpGrid - PHP Datagrid.

]]>
520