You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
JavaScript
81 lines
2.8 KiB
JavaScript
|
|
var CommonBuild = {
|
|
/**
|
|
* //构造 Table
|
|
* @param {Array<String>} f 字段列表
|
|
* @param {Array<String>} h 表头列表
|
|
* @param {Array<Object>} t 数据列表
|
|
* @param {Array<Number>} w 列宽列表
|
|
* @param {Array<Object>} m 格式化列表
|
|
* @returns {} table
|
|
*/
|
|
InitialTable: function (f, h, t, w, m) {
|
|
var twidth = 0;
|
|
for (var i = 0; i < w.length; i++) twidth += w[i];
|
|
return ''.concat('<table style="text-align: center;width:' + twidth +'px;min-width: 100%;" class="x-grid-table x-grid-table-resizer">',
|
|
'<thead>', this.InitialThead(f, h, w), '</thead>',
|
|
'<tbody>', this.InitialTbody(f, t, w, m), '</tbody>',
|
|
'</table>');
|
|
},
|
|
/**
|
|
* 构造表头
|
|
* @returns {String}
|
|
*/
|
|
InitialThead: function(f,h,w) {
|
|
var thead = "<tr>";
|
|
for (var i = 0; i < f.length; i++) {
|
|
thead = thead.concat(
|
|
'<th style="width: ' + w[i] + 'px; " data-field="' + f[i] +'" class="x-column-header-inner"><div class="th-inner ">'+h[i]+'</div></th>');
|
|
}
|
|
return thead.concat('</tr>');
|
|
},
|
|
/**
|
|
* 构造表身
|
|
* @returns {String}
|
|
*/
|
|
InitialTbody: function(f, t, w, m) {
|
|
var tbody = "";
|
|
if (t != null && t.length > 0) {
|
|
for (var i = 0; i < t.length; i++) {
|
|
tbody = tbody.concat(this.InitialTbodyTr(t[i], i, f, w, m));
|
|
}
|
|
} else
|
|
tbody = "<tr><td colspan='" +
|
|
f.length +
|
|
"'><div style='text-align: center; color: #555;height: 30px;line-height:30px;'>没有找到匹配的记录</div></td></tr>";
|
|
return tbody;
|
|
},
|
|
/**
|
|
* 构造行
|
|
* @param {Object} r 数据实例
|
|
* @param {Number} i 行索引
|
|
* @returns {String}
|
|
*/
|
|
InitialTbodyTr: function (r,i, f, w, m) {
|
|
var tr = '<tr class="' + ((i % 2 === 0) ? "x-grid-row" : "x-grid-row x-grid-row-alt") + '">';
|
|
for (var j = 0; j < f.length; j++) {
|
|
var c = new Object();//td类
|
|
var value = this.InitialFormatData(m, f[j], r, i, c);
|
|
tr = tr.concat('<td style="width: ' + w[j] + 'px;" class="x-grid-cell ' + c.tdCls + '">' + value + '</td>');
|
|
}
|
|
return tr.concat('</tr>');
|
|
},
|
|
/**
|
|
*
|
|
* @param {String} d 当前字段
|
|
* @returns {String} 结果值
|
|
*/
|
|
InitialFormatData: function (m, d, r, i, c) {//格式化值
|
|
var v = r[d];//当前值
|
|
for (var p = 0; p < m.length; p++) {
|
|
var n = m[p];//当前格式化实例
|
|
for (var j in n) {
|
|
if (n.hasOwnProperty(j)) {
|
|
if (j === d) return n[j](v, c, null, i);
|
|
}
|
|
}
|
|
}
|
|
c.tdCls = '';
|
|
return v;
|
|
}
|
|
} |