jqGrid 内容超过一定长度省略表示

colNames : [                                          
    "描述" 
  ],
colModel : [

{
                                    name : 'description',
                                    index : 'description',
                                    width : 60,
                                    sortable : true,
                                    formatter : function(cellvalue, options,rowObject){
                                        //显示 转义
                                        cellvalue=cellvalue.replace(/({|})/g,'');   //过滤{}
                                        cellvalue=cellvalue.replace(/</g,'&lt;');    //置换符号<
                                        cellvalue=cellvalue.replace(/>/g,'&gt;');    //置换符号>
                                         //  t=t.replace(/<\/?[^>]*>/g,''); //*<\/?[^>]*>可以匹配<script></style></body>等,并置空。而不是替换<和>两个符号
                                        return role_strLimite(cellvalue);
                                    }, 
                                },
],
function role_strLimite(cellvalue) {
        if (cellvalue != null && cellvalue.length > 20) {
            var value = cellvalue.toString().replace("\"", " ").replace("\'", " ");
            return "<div title ='" + GLOBAL.XXX.ROLE.showAllInfo(value) + "'>" + value.substring(0, 20) + ".....</div>";
        }
        if (cellvalue == null) {
            return "";
        }
        return cellvalue;
    }
/**
 * 强制截取字符串换行,解决火狐浏览器悬浮窗不换行的问题
 * @param value
 * @returns {string}
 */
GLOBALXXX.ROLE.showAllInfo = function (value) {
    var valueStr = "";
    var len = value.length;
    var count = Math.ceil(len / 50);
    for (var i = 0; i < count; i++) {
        if (i == count - 1) {
            valueStr = valueStr + value.substring(i * 50);
        } else {
            valueStr = valueStr + value.substring(i * 50, (i + 1) * 50) + "\n";
        }
    }

    return valueStr;
}

猜你喜欢

转载自www.cnblogs.com/slowcity/p/9098751.html
今日推荐