在表格中写入字符串时如果字符串过长会导致表格会分成多行,页面难看,因此希望进行处理
客户的意见是对过长的用“...”来表示,在网上找了很多资料也没有类似的css,自能手动来处理了
现在的问题是知道了textbox的px长度,但是无法计算字符串对应的px大小,
希望大家解答如何计算给定字符串对应的px大小
度量字符串的长度看
Class Ext.util.TextMetrics
Provides precise pixel measurements for blocks of text so that you can determine exactly how high and wide, in pixels, a given block of text will be. Note that when measuring text, it should be plain text and should not contain any HTML, otherwise it may not be measured correctly.
但是不建议你这么做.
默认的ExtJS Grid应该是默认隐藏的才对啊.除非你设置了
.x-grid3-cell-inner {
/*内容长的时候换行*/
white-space:normal !important;
}
没必要用px来处理的啦,计算字符个数就可以了.精确点的话 中文和中文符号算两个字符宽度应该就很OK了.到了长度,其他的字符就截掉用...替换.
提供一个思路,望能用上.
Class Ext.util.Format
ellipsis( String value, Number length, Boolean word ) : String
Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
刚才给的是extjs里面的js做法.
css做法的看
[url]http://www.codebit.cn/pub/html/xhtml_css/tip/text_overflow/[/url]
你可以利用
[code="js"]Ext.util.Format.ellipsis("好长好长的字符",4);//我只让他显示4个后面用省略号代替[/code]