提交 d425877c 编写于 作者: ModStart's avatar ModStart

develop

上级 8377c6d2
layui.define([],function(t){var o=layui.$,i={},u=o("body");t("mstable",{render:function(t){i[t.id]=t;var e=this;layui.each(i,function(){!function(d,l){var t=o(l.elem),e=t.next().children(".layui-table-box").children(".layui-table-header").children("table").children("thead").children("tr").children("th"),i=t.next().children(".layui-table-box").children(".layui-table-fixed").children(".layui-table-header").children("table").children("thead").children("tr").children("th"),r=t.next().children(".layui-table-box").children(".layui-table-body").children("table").children("tbody").children("tr"),c=t.next().children(".layui-table-total").find("tr");String.prototype.width=function(t){var e=t||u.css("font"),t=o("<div>"+this+"</div>").css({position:"absolute",float:"left","white-space":"nowrap",visibility:"hidden",font:e}).appendTo(u),e=t.width();return t.remove(),e},e.add(i).on("dblclick",function(t){var e=o(this),i=t.clientX-e.offset().left,t=e.attr("data-key").split("-"),t=l.cols[t[1]][t[2]];s(0,e,0<e.parents(".layui-table-fixed-r").length?i<=10:e.width()-i<=10,t),h(l,e,0<e.parents(".layui-table-fixed-r").length?i<=10:e.width()-i<=10,t)});var a=0,n=0;e.add(i).each(function(t,e){var i=o(this).attr("data-key").split("-"),i=l.cols[i[1]][i[2]];!0===i.withAuto&&(s(0,o(this),!0,i),"widthAutoSize"in i&&"widthAutoOld"in i&&(a+=i.widthAutoOld,a-=i.widthAutoSize,n++))}),0<a&&0<n&&e.add(i).each(function(t,e){var i=o(this).attr("data-key").split("-"),i=l.cols[i[1]][i[2]];!0===i.withAuto&&(i.width=i.widthAutoSize+a/n)});function h(t,e,i,l){var a=e.data("key"),n=a.split("-");3===n.length&&(n[1],n[2]);1<e.attr("colspan")||e.data("unresize")||i&&d.getCssRule(t,a,function(t){t.style.width=l.width+"px"})}function s(t,e,i,l){var a,n,d=e.data("key"),h=d.split("-");3===h.length&&(h[1],h[2]);1<e.attr("colspan")||e.data("unresize")||i&&(l.widthAutoOld=e.width(),a=e.text().width(e.css("font"))+21,n=e.css("font"),r.children('td[data-key="'+d+'"]').each(function(t,e){var i=0;o(this).children().children()&&0<o(this).children().children().length?i+=o(this).children().html().width(n):i=o(this).text().width(n),a<i&&(a=i)}),0<c.length&&(d=c.children('td[data-key="'+d+'"]').text().width(n),a<d&&(a=d)),a+=32,l.width=a,l.widthAutoSize=a)}e.add(i).each(function(t,e){var i=o(this).attr("data-key").split("-"),i=l.cols[i[1]][i[2]];!0===i.withAuto&&h(l,o(this),!0,i)})}(e,this)})},getCssRule:function(t,i,l){t=t.elem.next().find("style")[0],t=t.sheet||t.styleSheet||{},t=t.cssRules||t.rules;layui.each(t,function(t,e){if(e.selectorText===".laytable-cell-"+i)return l(e),!0})}})});
\ No newline at end of file
layui.define([],function(t){var o=layui.$,i={},u=o("body");t("mstable",{render:function(t){i[t.id]=t;var e=this;layui.each(i,function(){!function(d,l){var t=o(l.elem),e=t.next().children(".layui-table-box").children(".layui-table-header").children("table").children("thead").children("tr").children("th"),i=t.next().children(".layui-table-box").children(".layui-table-fixed").children(".layui-table-header").children("table").children("thead").children("tr").children("th"),r=t.next().children(".layui-table-box").children(".layui-table-body").children("table").children("tbody").children("tr"),c=t.next().children(".layui-table-total").find("tr");String.prototype.width=function(t){var e=t||u.css("font"),t=o("<div>"+this+"</div>").css({position:"absolute",float:"left","white-space":"nowrap",visibility:"hidden",font:e}).appendTo(u),e=t.width();return t.remove(),e},e.add(i).on("dblclick",function(t){var e=o(this),i=t.clientX-e.offset().left,t=e.attr("data-key").split("-"),t=l.cols[t[1]][t[2]];s(0,e,0<e.parents(".layui-table-fixed-r").length?i<=10:e.width()-i<=10,t),h(l,e,0<e.parents(".layui-table-fixed-r").length?i<=10:e.width()-i<=10,t)});var a=0,n=0;e.add(i).each(function(t,e){var i=o(this).attr("data-key").split("-"),i=l.cols[i[1]][i[2]];!0===i.withAuto&&(s(0,o(this),!0,i),"widthAutoSize"in i&&"widthAutoOld"in i&&(a+=i.widthAutoOld,a-=i.widthAutoSize,n++))}),0<a&&0<n&&e.add(i).each(function(t,e){var i=o(this).attr("data-key").split("-"),i=l.cols[i[1]][i[2]];!0===i.withAuto&&(i.width=i.widthAutoSize+a/n)});function h(t,e,i,l){var a=e.data("key"),n=a.split("-");3===n.length&&(n[1],n[2]);1<e.attr("colspan")||e.data("unresize")||i&&d.getCssRule(t,a,function(t){t.style.width=l.width+"px"})}function s(t,e,i,l){var a,n,d=e.data("key"),h=d.split("-");3===h.length&&(h[1],h[2]);1<e.attr("colspan")||e.data("unresize")||i&&(l.widthAutoOld=e.width(),a=e.text().width(e.css("font"))+21,n=e.css("font"),r.children('td[data-key="'+d+'"]').each(function(t,e){var i=0;o(this).children().children()&&0<o(this).children().children().length?i+=o(this).children().html().width(n):i=o(this).text().width(n),a<i&&(a=i)}),0<c.length&&(d=c.children('td[data-key="'+d+'"]').text().width(n),a<d&&(a=d)),a+=32,l.width=a,l.widthAutoSize=a)}e.add(i).each(function(t,e){var i=o(this).attr("data-key").split("-"),i=l.cols[i[1]][i[2]];!0===i.withAuto&&h(l,o(this),!0,i)})}(e,this)})},getCssRule:function(t,i,l){t=t.elem.next().find("style")[0],t=t.sheet||t.styleSheet||{},t=t.cssRules||t.rules;layui.each(t,function(t,e){if(e.selectorText===".laytable-cell-"+i)return l(e),!0})}})});
\ No newline at end of file
layui.define([], function (exports) {
var $ = layui.$,
tables = {},
_BODY = $('body');
var mod = {
render: function (myTable) {
tables[myTable.id] = myTable
var _this = this;
layui.each(tables, function () {
innerColumnWidth(_this, this)
});
function innerColumnWidth(_this, myTable) {
var $table = $(myTable.elem),
th = $table.next().children('.layui-table-box').children('.layui-table-header').children('table').children('thead').children('tr').children('th'),
fixTh = $table.next().children('.layui-table-box').children('.layui-table-fixed').children('.layui-table-header').children('table').children('thead').children('tr').children('th'),
$tableBodytr = $table.next().children('.layui-table-box').children('.layui-table-body').children('table').children('tbody').children('tr'),
$totalTr = $table.next().children('.layui-table-total').find('tr');
String.prototype.width = function (font) {
var f = font || _BODY.css('font'),
o = $('<div>' + this + '</div>')
.css({
'position': 'absolute',
'float': 'left',
'white-space': 'nowrap',
'visibility': 'hidden',
'font': f
})
.appendTo(_BODY),
w = o.width();
o.remove();
return w;
}
th.add(fixTh).on('dblclick', function (e) {
var othis = $(this),
pLeft = e.clientX - othis.offset().left;
var colKey = othis.attr('data-key').split('-')
var config = myTable.cols[colKey[1]][colKey[2]];
computeColumnWidth(myTable, othis, othis.parents('.layui-table-fixed-r').length > 0 ? pLeft <= 10 : othis.width() - pLeft <= 10, config);
setColumnWidth(myTable, othis, othis.parents('.layui-table-fixed-r').length > 0 ? pLeft <= 10 : othis.width() - pLeft <= 10, config);
});
// 初始化表格后,自动调整所有列宽
var widthLeft = 0;
var widthAutoJustCount = 0;
th.add(fixTh).each(function (e, i) {
var colKey = $(this).attr('data-key').split('-')
var config = myTable.cols[colKey[1]][colKey[2]];
if (config.withAuto === true) {
computeColumnWidth(myTable, $(this), true, config);
if (('widthAutoSize' in config) && ('widthAutoOld' in config)) {
widthLeft += config.widthAutoOld;
widthLeft -= config.widthAutoSize;
widthAutoJustCount++;
}
}
});
if (widthLeft > 0 && widthAutoJustCount > 0) {
th.add(fixTh).each(function (e, i) {
var colKey = $(this).attr('data-key').split('-');
var config = myTable.cols[colKey[1]][colKey[2]];
if (config.withAuto === true) {
config.width = config.widthAutoSize + widthLeft / widthAutoJustCount;
}
});
}
th.add(fixTh).each(function (e, i) {
var colKey = $(this).attr('data-key').split('-')
var config = myTable.cols[colKey[1]][colKey[2]];
if (config.withAuto === true) {
setColumnWidth(myTable, $(this), true, config);
}
});
function setColumnWidth(myTable, othis, isHandle, config) {
var key = othis.data('key')
, keyArray = key.split('-')
, curKey = keyArray.length === 3 ? keyArray[1] + '-' + keyArray[2] : ''
if (othis.attr('colspan') > 1 || othis.data('unresize')) {
return;
}
if (isHandle) {
_this.getCssRule(myTable, key, function (item) {
item.style.width = config.width + 'px'
});
}
}
function computeColumnWidth(myTable, othis, isHandle, config) {
var key = othis.data('key')
, keyArray = key.split('-')
, curKey = keyArray.length === 3 ? keyArray[1] + '-' + keyArray[2] : ''
if (othis.attr('colspan') > 1 || othis.data('unresize')) {
return;
}
if (isHandle) {
config.widthAutoOld = othis.width();
var maxWidth = othis.text().width(othis.css('font')) + 21, font = othis.css('font');
$tableBodytr.children('td[data-key="' + key + '"]').each(function (index, elem) {
var curWidth = 0
if ($(this).children().children() && $(this).children().children().length > 0) {
curWidth += $(this).children().html().width(font)
} else {
curWidth = $(this).text().width(font);
}
if (maxWidth < curWidth) {
maxWidth = curWidth
}
})
if ($totalTr.length > 0) {
var curWidth = $totalTr.children('td[data-key="' + key + '"]').text().width(font)
if (maxWidth < curWidth) {
maxWidth = curWidth
}
}
maxWidth += 32;
config.width = maxWidth;
config.widthAutoSize = maxWidth;
}
}
}
},
getCssRule: function (that, key, callback) {
var style = that.elem.next().find('style')[0]
, sheet = style.sheet || style.styleSheet || {}
, rules = sheet.cssRules || sheet.rules;
layui.each(rules, function (i, item) {
if (item.selectorText === ('.laytable-cell-' + key)) {
return callback(item), true;
}
});
}
};
exports('mstable', mod);
});
\ No newline at end of file
......@@ -425,8 +425,10 @@ class Grid
'title' => $field->label(),
'sort' => $field->sortable(),
];
if ($field->width()) {
if ($field->width() !== '') {
$record['width'] = $field->width();
} else {
$record['withAuto'] = true;
}
$head[] = $record;
}
......
......@@ -88,7 +88,10 @@
}
return items;
};
layui.use(['table', 'laypage'], function () {
layui.extend({
mstable: window.__msCDN + 'asset/layui/lay/ext/mstable'
});
layui.use(['table', 'laypage','mstable'], function () {
var table = layui.table.render({
id: '{{$id}}Table',
elem: '#{{$id}}Table',
......@@ -105,7 +108,10 @@
loading: true,
cellMinWidth: 100,
cols: [[]],
data: []
data: [],
done: function() {
layui.mstable.render(this);
}
});
layui.table.on('sort({{$id}}Table)', function (obj) {
if (null == obj.type) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册