1. 程式人生 > >table內容自定義換行

table內容自定義換行

$("#rep").datagrid({
    singleSelect: true, //選中一行的設定
    AllowPaging: true,
    pagination: true,
    pageSize: 20,
    pageList: [20, 50, 200, 1000],
    rownumbers: true, //行號
    iconCls: "icon-save", //圖示
    collapsible: true, //隱藏按鈕
    border: true,
    fit: true,
    remoteSort: false,
    columns: [[
        {  field: "type",
            title: "型別",
            width: 130,
            align: 'center',
            headalign: 'center'
        }, 
          { field: "username",
            title: "操作人",
            width: 100,
            align: 'center',
            headalign: 'center'
        }, 
         {  field: "operatorDate",
            title: "操作時間",
            width: 110,
            align: 'center',
            headalign: 'center'
        },
         {  field: "remarks",
            title: "備註",
            align: 'left',
            headalign: 'center',
            formatter: function (value, row, index) {
                var va = eval("row." + $(this).attr("field"));
                return formatBr(100,va);
            }
        }
    ]],
    pagination: true,
    //pagination : true,
    toolbar: "#tool"
});
function formatBr(len, value) {
    if (!value) {
        return "";
    }
    var slengh = value.length;
    var restr = "";
    var flag = true;
    for (var i = 1; i <= 100; i++) {
        len2 = i * len;
        if (slengh >= len2) {
            flag = false;
            restr += value.substring(len2 - len, len2) + "</br>"
        } else {
            break;
        }
    }
    if (flag) {
        restr += value;
    } else {
        if (len2 - len <= value.length - 1) {
            restr += value.substring(len2 - len, value.length)
        }
    }
    return restr;
}