PDA

View Full Version : how to show url link in grid column



maneljn
27 Dec 2012, 7:33 AM
I have a textfield saved in database that can contains a string value like this:



some text bla bla bla http://www.google.com some more text bla bla alb ala bla


I want to show this field inside a grid column, but converting the "http://....." in a url link (<a href =".....)

Is it possible ?

skirtle
27 Dec 2012, 11:15 AM
Just use a renderer function on the column:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.column.Column-cfg-renderer

You can return whatever HTML you want.

maneljn
28 Dec 2012, 12:46 AM
Yes Skirtle, i know the use of renderer, but my question is how can i "detect" that inside the text are strings like http://...... , and how can i make substitution of this string adding the html tags for url link <a href=.......


Manel

skirtle
28 Dec 2012, 1:02 AM
Identifying URLs in text isn't really an ExtJS question but I guess you could do something using a regular expression:


renderer: function(value) {
return value.replace(/(https?:\/\/\S+)/g, '<a href="$1">$1</a>');
}

You'll have to do some experimenting to refine the expression to pick out exactly what you want.

maneljn
4 Jan 2013, 3:16 AM
i've found this solution. It works very well.

https://github.com/cowboy/javascript-linkify/

maxlau11
6 Jan 2014, 8:03 AM
This in an easy solution:


{
html:'blah blah blah <a href="http://google.com" title="http://google.com">google.com</a> blah blah blah',
}