9 lines
30 KiB
JavaScript
9 lines
30 KiB
JavaScript
|
/**
|
||
|
*
|
||
|
* @name: 表格增强插件
|
||
|
* @author: yelog
|
||
|
* @link: https://github.com/yelog/layui-soul-table
|
||
|
* @license: MIT
|
||
|
* @version: v1.6.2
|
||
|
*/
|
||
|
layui.define(["table","tableFilter","tableChild","tableMerge"],function(exports){var tableFilter=layui.tableFilter,tableChild=layui.tableChild,tableMerge=layui.tableMerge,$=layui.$,table=layui.table,HIDE="layui-hide",tables={},originCols={},defaultConfig={fixTotal:!1,drag:!0,rowDrag:!1,autoColumnWidth:!0,contextmenu:!1,fixResize:!0,overflow:!1,fixFixedScroll:!0,filter:!1},_BODY=$("body"),_DOC=$(document),mod={render:function(e){tables[e.id]=e;var t,i,l,a=$.extend({},defaultConfig,e);a.filter&&a.filter.cache?(t=location.pathname+location.hash+e.id,i=this.deepStringify(e.cols),originCols[e.id]||(originCols[e.id]=this.deepClone(e.cols),(l=localStorage.getItem(t))&&i===localStorage.getItem("origin"+t)?this.updateCols(e,this.deepParse(l)):(localStorage.setItem("origin"+t,i),localStorage.removeItem(t)))):this.clearCache(e),tableFilter.render(e),tableChild.render(e),tableMerge.render(e),this.suspendConfig[e.id]={drag:!1,rowDrag:!1},a.fixTotal&&this.fixTotal(e),a.drag&&this.drag(e,a.drag),a.rowDrag&&this.rowDrag(e,a.rowDrag),a.autoColumnWidth&&this.autoColumnWidth(e,a.autoColumnWidth),this.contextmenu(e,a.contextmenu),a.fixResize&&this.fixResizeRightFixed(e),a.overflow&&this.overflow(e,a.overflow),a.fixFixedScroll&&this.fixFixedScroll(e)},config:function(e){"object"==typeof e&&$.extend(!0,defaultConfig,e)},updateCols:function(a,n){for(var o,r,e={},t=[],i=[],l=$(a.elem).next().children(".layui-table-box"),d=l.children(".layui-table-fixed").children(".layui-table-header").children("table"),s=$.merge(l.children(".layui-table-header").children("table"),d),c=l.children(".layui-table-header").children("table"),h=l.children(".layui-table-fixed").children(".layui-table-body").children("table"),u=l.children(".layui-table-body").children("table"),f=$.merge(l.children(".layui-table-body").children("table"),h),b=0;b<a.cols.length;b++)for(o=0;o<a.cols[b].length;o++)a.cols[b][o].oldPos=b+"-"+o,e[a.cols[b][o].key]=a.cols[b][o];for(b=0;b<n.length;b++){for(i=[],o=0;o<n[b].length;o++){if(r=a.index+"-"+n[b][o].key,n[b][o].width&&e[n[b][o].key]!==n[b][o].width&&this.getCssRule(a,r,function(e){e.style.width=(n[b][o].width||0)+"px"}),e[n[b][o].key].hide!==n[b][o].hide&&(s.find('th[data-key="'+r+'"]')[n[b][o].hide?"addClass":"removeClass"]("layui-hide"),f.find('td[data-key="'+r+'"]')[n[b][o].hide?"addClass":"removeClass"]("layui-hide")),(e[n[b][o].key].oldPos!==b+"-"+o||e[n[b][o].key].fixed!==n[b][o].fixed)&&n[b][o].fixed!==e[n[b][o].key].fixed)return a.cols=n,void table.reload(a.id);e[n[b][o].key].fixed=n[b][o].fixed,e[n[b][o].key].width=n[b][o].width,e[n[b][o].key].hide=n[b][o].hide,i.push(e[n[b][o].key])}t.push(i)}function p(e,t){for(b=0;b<n.length;b++)for(o=0;o<n[b].length;o++){r=a.index+"-"+n[b][o].key;var i,l=$(e).children(t+":eq("+o+")").attr("data-key");l!==r&&($(e).children(t+":eq("+o+")").before($(e).children(t+'[data-key="'+r+'"]')),n[b][o].fixed&&(i=("th"===t?d:h).children().children("th"===t?"tr":'tr[data-index="'+$(e).attr("data-index")+'"]')).children(t+'[data-key="'+l+'"]').before(i.children(t+'[data-key="'+r+'"]')))}}c.children().children("tr").each(function(){p(this,"th")}),u.children().children("tr").each(function(){p(this,"td")}),a.cols=t,table.resize(a.id)},export:function(e,t){tableFilter.export(e.config||e,t)},getCssRule:function(e,i,l){e=e.elem.next().find("style")[0],e=e.sheet||e.styleSheet||{},e=e.cssRules||e.rules;layui.each(e,function(e,t){if(t.selectorText===".laytable-cell-"+i)return l(t),!0})},autoColumnWidth:function(e,n){var t=this;function i(c,i){var e=$(i.elem),t=e.next().children(".layui-table-box").children(".layui-table-header").children("table").children("thead").children("tr").children("th"),l=e.next().children(".layui-table-box").children(".layui-table-fixed").children(".layui-table-header").children("table").children("thead").children("tr").children("th"),h=e.next().children(".layui-table-box").children(".layui-table-body").children("table").children("tbody").children("tr"),u=e.next().children(".layui-table-total").find("tr");function a(e,t,i){var l=t.data("key"),a=l.split("-"),n=3===a.length?a[1]+"-"+a[2]:""
|