PDA

View Full Version : how can i escape html code in a grid cell



Fonnit
26 Feb 2014, 9:53 PM
hi all,

How can I escape html code in a grid cell.

After i write [ <button onclick="alert('OK')">OK</button> ] into a cell ( as below 1.png )
the botton is showed ... ( as below 2.png )

thanks.

Zinnia
27 Feb 2014, 12:33 AM
Check the below example, you need to add button in grid cell renderer function.

http://jsfiddle.net/6cwNf/

Fonnit
27 Feb 2014, 12:39 AM
Thanks for your reply Zinnia ,i do not want to display a button in the cell of grid.i just want to show what i inputted (OK ).thanks

Farish
27 Feb 2014, 2:10 AM
you can use Ext.util.Format.htmlEncode(string) to have the html show in your cell in place of the button.

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.util.Format-method-htmlEncode

e.g. Ext.util.Format.htmlEncode("<b>HelloWorld</b>") will return "<b>HelloWorld</b>" and not HelloWorld in bold.

Farish
27 Feb 2014, 2:13 AM
if you want to add it to all your columns, you can do it like this:


columns:
{
defaults: { renderer: 'htmlEncode' },
items:
[
// all your grid columns here
]
}