Hyperlink some records only

QuestionsHyperlink some records only
Richard asked 11 years ago

I have a store locator. Some stores (a very small proportion) have their own home page. I would like to create a hyperlink on the store name in those cases where a hyperlink exists, but leave the others unmarked.

Is this possible?

3 Answers
Abu Ghufran answered 11 years ago

Yes, it is possible using 'conditional cell data' feature. Little modification required in lib jqgrid_dist.php

search
$row[$col_name] = ( $r ? $c["default"] : '');
and replace with
$row[$col_name] = ( $r ? $c["default"] : $row[$col_name]);

Now, in column definition…

$col = array();
$col["title"] = "Company";
$col["name"] = "company";
$col["width"] = "30";
$col["align"] = "center";

$buttons_html = "<a target='_blank' href={website}'>{company}</a>"; // where website and company both are cols of grid.
$col["default"] = $buttons_html;

// use single quote for condition, and $row will have all columns data, to use in condition
$col["condition"] = '$row["website"] != ""';
$cols[] = $col;

Richard answered 11 years ago

$buttons_html = "<a target='_blank' href={website}'>{company}</a>";
should be
$buttons_html = "<a target='_blank' href='{website}'>{company}</a>";

… but even so, there are 2 issues:

1. The company field is url encoded (showing + instead of spaces). I have tried to fix this both by using the built in php urldecode function and str_replace("+"," ","{company}") but neither removes the +.

2. The website link is part of the data returned via $g-select_command = $SQL; but I have not put it in the grid. It does work (sort of) when I add it to the grid, but I have not worked out how to hide the column (as I don't want it displayed).
The other problem is that the link appears like this:
http://www.mywebsite.com/http%3A%2F%2Fwww.storewebsite.com

Abu Ghufran answered 11 years ago

For html encoded data, use this formatter for company and website.
$col["formatter"] = "function(cellval,options,rowdata){return $.jgrid.htmlEncode(cellval);}";

Youcan hide website column using
$col["hidden"] = true;

Your Answer

18 + 14 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?