Formatting url column with and without http://

QuestionsFormatting url column with and without http://
Glenn asked 9 years ago

Hi Abu,
Currently formatting works great for url with www. or nothing in front of the url.
So nba.com & http://www.nba.com works great. Issue is for those url that can only work with http:// in front of them so I have to save them this way in the database.
The below formatting for the column leaves out the : when http:// is in the url. eg http//nba.com
Is there a way to keep the colon?

$acol_val["formatter"] = "function(cellval,options,rowdata){ return '<a target="_blank" href="http://'+cellval+'">'+cellval+'</a>&#039;; }";

$acol_val["unformat"] = "function(cellval,options,cell){ return $('a', cell).attr('href').replace('http://&#039;,''); }";

Regards,
Glenn

2 Answers
Abu Ghufran answered 9 years ago

Try following:

$acol_val["formatter"] = "function(cellval,options,rowdata){ return '<a target="_blank" href="'+ ((cellval.indexOf('http') == -1) ? 'http://&#039;: '') +cellval+'">'+cellval+'</a>'; }";
$acol_val["unformat"] = "function(cellval,options,cell){ return $('a', cell).attr('href').replace('http://&#039;,''); }";

Glenn answered 9 years ago

Perfect!
Thanks Abu

Your Answer

6 + 17 =

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?