|
|
|
@ -46,11 +46,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
var options = that.config;
|
|
|
|
|
var id = options.id || options.index;
|
|
|
|
|
|
|
|
|
|
if(id){
|
|
|
|
|
thisTable.that[id] = that; // 记录当前实例对象
|
|
|
|
|
thisTable.config[id] = options; // 记录当前实例配置项
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
config: options,
|
|
|
|
|
reload: function(options, deep){
|
|
|
|
@ -322,10 +317,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
options.where = options.where || {};
|
|
|
|
|
|
|
|
|
|
// 初始化 id 属性 - 优先取 options > 元素 id > 自增索引
|
|
|
|
|
options.id = 'id' in options ? options.id : (
|
|
|
|
|
var id = options.id = 'id' in options ? options.id : (
|
|
|
|
|
options.elem.attr('id') || that.index
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
thisTable.that[id] = that; // 记录当前实例对象
|
|
|
|
|
thisTable.config[id] = options; // 记录当前实例配置项
|
|
|
|
|
|
|
|
|
|
//请求参数的自定义格式
|
|
|
|
|
options.request = $.extend({
|
|
|
|
|
pageName: 'page'
|
|
|
|
@ -813,13 +811,20 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
|
|
|
|
|
if(that.autoColNums > 0 && patchNums >= -colNums && patchNums <= colNums){
|
|
|
|
|
var getEndTh = function(th){
|
|
|
|
|
var field;
|
|
|
|
|
th = th || that.layHeader.eq(0).find('thead > tr:first-child > th:last-child')
|
|
|
|
|
field = th.data('field');
|
|
|
|
|
var field, thRet;
|
|
|
|
|
th = th || that.layHeader.eq(0).find('thead th:last-child')
|
|
|
|
|
layui.each(th, function (thIndex, thElem) {
|
|
|
|
|
thElem = $(thElem);
|
|
|
|
|
if (!thElem.children('.'+ELEM_GROUP).length) { // 排除合并表头
|
|
|
|
|
field = thElem.attr('data-field');
|
|
|
|
|
thRet = thElem;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(!field && th.prev()[0]){
|
|
|
|
|
return getEndTh(th.prev())
|
|
|
|
|
}
|
|
|
|
|
return th
|
|
|
|
|
return thRet
|
|
|
|
|
};
|
|
|
|
|
var th = getEndTh();
|
|
|
|
|
var key = th.data('key');
|
|
|
|
@ -899,6 +904,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
table.cache[that.key] = []; //格式化缓存数据
|
|
|
|
|
|
|
|
|
|
that.syncCheckAll();
|
|
|
|
|
that.renderForm();
|
|
|
|
|
that.setColsWidth();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 初始页码
|
|
|
|
@ -959,7 +966,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
}
|
|
|
|
|
// 检查数据格式是否符合规范
|
|
|
|
|
if(res[response.statusName] != response.statusCode){
|
|
|
|
|
that.renderForm();
|
|
|
|
|
that.errorView(
|
|
|
|
|
res[response.msgName] ||
|
|
|
|
|
('返回的数据不符合规范,正确的成功状态码应为:"'+ response.statusName +'": '+ response.statusCode)
|
|
|
|
@ -982,10 +988,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
}
|
|
|
|
|
,error: function(e, msg){
|
|
|
|
|
that.errorView('请求异常,错误提示:'+ msg);
|
|
|
|
|
|
|
|
|
|
that.renderForm();
|
|
|
|
|
that.setColsWidth();
|
|
|
|
|
|
|
|
|
|
typeof options.error === 'function' && options.error(e, msg);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -1037,38 +1039,14 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 数据渲染
|
|
|
|
|
Class.prototype.renderData = function(opts){
|
|
|
|
|
Class.prototype.getTrHtml = function(data, sort, curr, trsObj) {
|
|
|
|
|
var that = this;
|
|
|
|
|
var options = that.config;
|
|
|
|
|
var trs = trsObj && trsObj.trs || [];
|
|
|
|
|
var trs_fixed = trsObj && trsObj.trs_fixed || [];
|
|
|
|
|
var trs_fixed_r = trsObj && trsObj.trs_fixed_r || [];
|
|
|
|
|
curr = curr || 1
|
|
|
|
|
|
|
|
|
|
var res = opts.res;
|
|
|
|
|
var curr = opts.curr;
|
|
|
|
|
var count = opts.count;
|
|
|
|
|
var sort = opts.sort;
|
|
|
|
|
|
|
|
|
|
var data = res[options.response.dataName] || []; //列表数据
|
|
|
|
|
var totalRowData = res[options.response.totalRowName]; //合计行数据
|
|
|
|
|
var trs = [];
|
|
|
|
|
var trs_fixed = [];
|
|
|
|
|
var trs_fixed_r = [];
|
|
|
|
|
|
|
|
|
|
// 渲染视图
|
|
|
|
|
var render = function(){ // 后续性能提升的重点
|
|
|
|
|
// 同步表头父列的相关值
|
|
|
|
|
options.HAS_SET_COLS_PATCH || that.setColsPatch();
|
|
|
|
|
options.HAS_SET_COLS_PATCH = true;
|
|
|
|
|
|
|
|
|
|
var thisCheckedRowIndex;
|
|
|
|
|
if(!sort && that.sortKey){
|
|
|
|
|
return that.sort({
|
|
|
|
|
field: that.sortKey.field,
|
|
|
|
|
type: that.sortKey.sort,
|
|
|
|
|
pull: true,
|
|
|
|
|
reloadType: opts.type
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
layui.each(data, function(i1, item1){
|
|
|
|
|
var tds = [], tds_fixed = [], tds_fixed_r = []
|
|
|
|
|
,numbers = i1 + options.limit*(curr - 1) + 1; // 序号
|
|
|
|
@ -1158,7 +1136,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
break;
|
|
|
|
|
case 'radio': // 单选
|
|
|
|
|
if(tplData[checkName]){
|
|
|
|
|
thisCheckedRowIndex = i1;
|
|
|
|
|
that.thisCheckedRowIndex = i1;
|
|
|
|
|
}
|
|
|
|
|
return '<input type="radio" name="layTableRadio_'+ options.index +'" '
|
|
|
|
|
+ function(){
|
|
|
|
@ -1195,6 +1173,56 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
trs_fixed_r.push('<tr data-index="'+ i1 +'">'+ tds_fixed_r.join('') + '</tr>');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
trs: trs,
|
|
|
|
|
trs_fixed: trs_fixed,
|
|
|
|
|
trs_fixed_r: trs_fixed_r
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回行节点代码
|
|
|
|
|
table.getTrHtml = function (id, data) {
|
|
|
|
|
var that = getThisTable(id);
|
|
|
|
|
return that.getTrHtml(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 数据渲染
|
|
|
|
|
Class.prototype.renderData = function(opts){
|
|
|
|
|
var that = this;
|
|
|
|
|
var options = that.config;
|
|
|
|
|
|
|
|
|
|
var res = opts.res;
|
|
|
|
|
var curr = opts.curr;
|
|
|
|
|
var count = opts.count;
|
|
|
|
|
var sort = opts.sort;
|
|
|
|
|
|
|
|
|
|
var data = res[options.response.dataName] || []; //列表数据
|
|
|
|
|
var totalRowData = res[options.response.totalRowName]; //合计行数据
|
|
|
|
|
var trs = [];
|
|
|
|
|
var trs_fixed = [];
|
|
|
|
|
var trs_fixed_r = [];
|
|
|
|
|
|
|
|
|
|
// 渲染视图
|
|
|
|
|
var render = function(){ // 后续性能提升的重点
|
|
|
|
|
// 同步表头父列的相关值
|
|
|
|
|
options.HAS_SET_COLS_PATCH || that.setColsPatch();
|
|
|
|
|
options.HAS_SET_COLS_PATCH = true;
|
|
|
|
|
|
|
|
|
|
that.thisCheckedRowIndex = '';
|
|
|
|
|
if(!sort && that.sortKey){
|
|
|
|
|
return that.sort({
|
|
|
|
|
field: that.sortKey.field,
|
|
|
|
|
type: that.sortKey.sort,
|
|
|
|
|
pull: true,
|
|
|
|
|
reloadType: opts.type
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
that.getTrHtml(data, sort, curr, {
|
|
|
|
|
trs: trs,
|
|
|
|
|
trs_fixed: trs_fixed,
|
|
|
|
|
trs_fixed_r: trs_fixed_r
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 容器的滚动条位置
|
|
|
|
|
if(!(options.scrollPos === 'fixed' && opts.type === 'reloadData')){
|
|
|
|
|
that.layBody.scrollTop(0);
|
|
|
|
@ -1211,9 +1239,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
that.renderForm();
|
|
|
|
|
|
|
|
|
|
// 标注选中行样式
|
|
|
|
|
typeof thisCheckedRowIndex === 'number' && that.setRowChecked({
|
|
|
|
|
typeof that.thisCheckedRowIndex === 'number' && that.setRowChecked({
|
|
|
|
|
type: 'radio',
|
|
|
|
|
index: thisCheckedRowIndex
|
|
|
|
|
index: that.thisCheckedRowIndex
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
that.syncCheckAll();
|
|
|
|
@ -1245,7 +1273,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
|
|
|
|
|
//如果无数据
|
|
|
|
|
if(data.length === 0){
|
|
|
|
|
that.renderForm();
|
|
|
|
|
return that.errorView(options.text.none);
|
|
|
|
|
} else {
|
|
|
|
|
that.layFixLeft.removeClass(HIDE);
|
|
|
|
@ -2694,7 +2721,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
|
|
|
|
|
// 获取表格配置信息
|
|
|
|
|
table.getOptions = function (id) {
|
|
|
|
|
return $.extend(true, {}, getThisTableConfig(id));
|
|
|
|
|
return getThisTableConfig(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示或隐藏列
|
|
|
|
@ -2761,18 +2788,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|
|
|
|
var args = $.extend([], arguments);
|
|
|
|
|
args[3] = 'reloadData';
|
|
|
|
|
|
|
|
|
|
// 重载时,与数据相关的参数
|
|
|
|
|
// 重载时,影响整个结构的参数,不适合更新的参数
|
|
|
|
|
var dataParams = new RegExp('^('+ [
|
|
|
|
|
'data', 'url', 'method', 'contentType',
|
|
|
|
|
'dataType','jsonpCallback',
|
|
|
|
|
'headers', 'where', 'page', 'limit',
|
|
|
|
|
'request', 'response', 'parseData',
|
|
|
|
|
'scrollPos'
|
|
|
|
|
'elem', 'id', 'cols', 'width', 'height', 'maxHeight',
|
|
|
|
|
'toolbar', 'defaultToolbar',
|
|
|
|
|
'className', 'css', 'totalRow', 'page', 'pagebar'
|
|
|
|
|
].join('|') + ')$');
|
|
|
|
|
|
|
|
|
|
// 过滤与数据无关的参数
|
|
|
|
|
layui.each(args[1], function (key, value) {
|
|
|
|
|
if(!dataParams.test(key)){
|
|
|
|
|
if(dataParams.test(key)){
|
|
|
|
|
delete args[1][key];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|