Comparing version 0.3.3 to 0.3.4
@@ -285,2 +285,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
dp.setWidth = function (width) { | ||
if (this.empty) return | ||
var obj = { width: width } | ||
@@ -287,0 +288,0 @@ this.emit('beforeSetWidth', obj) |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Datagrid=t():e.Datagrid=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}(function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))switch(typeof e[t]){case"function":break;case"object":e[t]=function(t){var r=t.slice(1),n=e[t[0]];return function(e,t,o){n.apply(this,[e,t,o].concat(r))}}(e[t]);break;default:e[t]=e[e[t]]}return e}([function(e,t,r){e.exports=r(11),e.exports.Selection=r(15),e.exports.Paging=r(14),e.exports.Sorting=r(16),e.exports.ColumnMove=r(12),e.exports.ColumnFixed=r(13)},function(e,t){e.exports=function(e,t,r,n){return e.addEventListener(t,r,n),function(){e.removeEventListener(t,r,n)}}},function(e,t){e.exports=function(e,t,r){r||(r=document.body);var n=e.toUpperCase(),o=t,i=null;do if(o.tagName===n){i=o;break}while(o!==r&&(o=o.parentElement));return i}},function(e,t){},3,3,3,3,3,function(e,t){e.exports='<div class=grid-wrapper> <div class=grid-columns-wrapper> <table class=grid-columns> <colgroup></colgroup> <thead></thead> </table> </div> <div class=grid-body-wrapper> <table class=grid-body> <colgroup></colgroup> <tbody></tbody> </table> </div> </div> <div class="grid-no-data hidden"> <div class=no-data-content> 暂无数据 </div> </div> '},function(e,t){e.exports="<div class=grid-pager> <div>显示第 {{start}} - {{end}} 条数据, 共 {{total}} 条数据</div> <div> <span data-jump=first>首页</span> <span data-jump=prev>上一页</span> <span>第 <input type=text data-page value={{cur}}> 页, 共 {{totalPage}} 页</span> <span data-jump=next>下一页</span> <span data-jump=end>尾页</span> </div> </div> "},function(e,t,r){function n(e){return e.name}function o(e,t){return t[e.key]}function i(e,t){s.call(this);var r=this.el=document.createElement("div");this.options=u({},{height:e.offsetHeight},t),this.origin=e.parentElement.replaceChild(r,e),h.forEach(function(e){e(this)},this),this._init()}r(3);var a=r(9),s=r(17),c=r(1),u=r(19),l=r(2),d=r(18),p=100,f="data-grid",h=[];i.use=function(e){e(i)},i.hook=function(e){return h.push(e),function(){var t=h.indexOf(e);t>=0&&h.splice(t,1)}};var v=i.prototype=Object.create(s.prototype);v.constructor=i,v._init=function(){var e=this._unbindEvents=[];this.emit("beforeInit");var t=this.el;t.classList.add(f),t.innerHTML=a;var r={$gridWrapper:".grid-wrapper",$columnsWrapper:".grid-columns-wrapper",$columns:".grid-columns",$columnsColGroup:".grid-columns colgroup",$columnsThead:".grid-columns thead",$bodyWrapper:".grid-body-wrapper",$body:".grid-body",$bodyColGroup:".grid-body colgroup",$bodyTbody:".grid-body tbody",$noData:".grid-no-data"};for(var n in r)r[n]=t.querySelector(r[n]);r.$gridWrapper.style.height=this.options.height+"px";var o=this;e.push(c(r.$bodyWrapper,"scroll",function(){r.$columns.style.left="-"+r.$bodyWrapper.scrollLeft+"px"}),c(r.$bodyWrapper,"mouseover",function(e){var t=l("tr",e.target);if(t){var r=t.getAttribute("data-index");r&&o.trHover(!0,Number(r))}}),c(r.$bodyWrapper,"mouseout",function(e){var t=l("tr",e.target);if(t){var r=t.getAttribute("data-index");r&&o.trHover(!1,Number(r))}}),c(r.$bodyWrapper,"click",function(e){var t=l("td",e.target);if(t){var r=l("tr",t);if(r){var n=t.getAttribute("data-index"),i=r.getAttribute("data-index"),a=o.renderData;o.emit("cellClick",a.columnsDef[n],o.empty?null:a.rows[i])}}})),this.ui=r,this.options.fit&&e.push(c(window,"resize",d(function(){o.setWidth()}))),this.emit("afterInit")},v.trHover=function(e,t,r){var n=this.ui.$bodyTbody,o=n.querySelector('tr[data-index="'+t+'"]');o.classList[e?"add":"remove"]("hover"),r!==!1&&this.emit(e?"trHoverTo":"clearHover",t,o,this.rows&&this.rows[t])},v.setData=function(e){if(this.renderData={},this.emit("beforeSetData",e),this.empty=!(e.columns&&e.columns.length&&e.rows&&e.rows.length),this.empty){var t=this.ui;t.$body.classList.add("hidden"),t.$noData.classList.remove("hidden")}else this.setColumns(e.columns),this.setBody(e.rows),this.setWidth(e.width);this.emit("afterSetData",e)},v.normalizeWidth=function(e){var t=this.renderData,r=t.columnsDef;Array.isArray(e)||(e=[]);for(var n=[],o=0;o<r.length;o++)n[o]=e[o]||Math.max(15*(r[o].name||"").length,p);return n},v.setWidth=function(e){var t={width:e};this.emit("beforeSetWidth",t);var r=this.renderData,n=t.width;!n&&r.columnsMinWidth||(r.columnsMinWidth=this.normalizeWidth(n));var o,i=r.columnsMinWidth;if(this.options.fit){var a=i.reduce(function(e,t){return e+t}),s=this.ui.$bodyWrapper.clientWidth;if(a>=s)o=i;else{var c=(s-a)/r.columnsDef.length;o=i.map(function(e){return Math.round(e+c)})}}else o=i;r.columnsWidth=o;var u=this._colGroupsHTML(o);this._renderCols(u),this._resize(o)},v._colGroupsHTML=function(e){return e?e.map(function(e){return'<col style="width:'+e+'px">'}):[]},v._renderCols=function(e){var t=this.ui;t.$columnsColGroup.innerHTML=t.$bodyColGroup.innerHTML=e.join("")},v._resize=function(e){var t=this.ui,r=t.$columns,n=t.$noData,o=t.$body,i=e.reduce(function(e,t){return e+t});r.style.width=o.style.width=i+"px",this.empty?n.classList.remove("hidden"):n.classList.add("hidden")},v.setColumns=function(e){var t=this.renderData.columnsDef=this._normalize(e),r=this._columnsHTML(t);this.emit("beforeRenderColumns",r),this._renderColumns(r)},v._normalize=function(e){return e.map(function(e){var t="string"==typeof e?{name:e}:e;return t.key||(t.key=t.name),t})},v._columnsHTML=function(e){var t=this.options.thRenderer;return e.map(function(e,r){var o;return e.thRenderer&&(o=e.thRenderer(e)),null==o&&(t&&(o=t(e)),null==o&&(o=n(e))),'<th data-index="'+r+'">'+o+"</th>"})},v._renderColumns=function(e){this.ui.$columnsThead.innerHTML=e.join("")},v.setBody=function(e){var t=this.renderData;this.empty=!e||!e.length,t.rows=e,this._renderBody(t.trsArr=this._bodyHTML(t.columnsDef,e))},v._bodyHTML=function(e,t){var r=this.options.tdRenderer;return this.empty?[]:t.map(function(t,n){var i='<tr data-index="'+n+'">';return e.forEach(function(e,n){var a;e.tdRenderer&&(a=e.tdRenderer(e,t)),null==a&&(r&&(a=r(e,t)),null==a&&(a=o(e,t))),i+='<td data-index="'+n+'">'+a+"</td>"}),i+="</tr>"})},v._renderBody=function(e){var t=this.ui;t.$bodyTbody.innerHTML=e.join(""),t.$body.classList.remove("hidden"),t.$noData.classList.add("hidden")},v.destroy=function(){this.emit("beforeDestroy"),this._unbindEvents.forEach(function(e){e()});var e=this.el;try{e.parentElement.replaceChild(this.origin,e)}catch(t){}this.emit("afterDestroy")},e.exports=i},function(e,t,r){r(4);var n=r(1),o=r(2),i=100,a=Array.prototype.indexOf,s="ontouchstart"in window,c=s?"touchstart":"mousedown",u=s?"touchmove":"mousemove",l=s?"touchend":"mouseup";e.exports=function(e){e.hook(function(e){if(e.options.columnResize){var t=document.createElement("div");t.classList.add("dragging-line");var r=[];e.once("afterInit",function(){e.ui.$draggingLine=t,e.el.appendChild(t)});var s,d,p,f,h,v,m=!1;r.push(e.on("beforeRenderColumns",function(e){e.forEach(function(t,r){e[r]=t.replace("</th>",'<span class="drag-lever"></span></th>')})}),n(e.el,c,function(r){if(r.target.classList.contains("drag-lever")&&0===r.button){var n=o("th",r.target,e.el);if(!n)return;n.classList.add("resizing"),d=n,v=-(n.clientWidth-i);var c=e.ui,u=c.$columnsWrapper,l=c.$bodyWrapper;t.style.height=u.offsetHeight+l.offsetHeight+"px",h=n.offsetLeft+n.clientWidth-l.scrollLeft,t.style.left=h+"px",t.classList.add("show"),m=!0,s=r.target,s.classList.add("dragging"),f=r.pageX,p=a.call(n.parentElement.children,n)}}),n(document,u,function(e){if(m){e.preventDefault();var r=e.pageX-f;r>v&&(t.style.left=h+(e.pageX-f)+"px")}}),n(document,l,function(r){if(m){setTimeout(function(){d.classList.remove("resizing")},0),t.classList.remove("show"),m=!1,s.classList.remove("dragging");var n=r.pageX-f;n<v&&(n=v);var o=e.renderData.columnsMinWidth;o[p]=o[p]+n,e.setWidth(o)}})),e.once("beforeDestroy",function(){r.forEach(function(e){e()})})}})}},function(e,t,r){r(5);var n=Array.prototype.slice,o=r(1);e.exports=function(e){e.hook(function(t){function r(){function r(e,r){var n=i.el.contains(r)?t:i;n.trHover(!0,e,!1)}function n(e,r){var n=i.el.contains(r)?t:i;n.trHover(!1,e,!1)}var c=document.createElement("div");c.classList.add("fixed-datagrid");var u=document.createElement("div");u.classList.add("hidden"),c.appendChild(u),t.el.appendChild(c),i=new e(u,{height:t.ui.$columnsWrapper.offsetHeight+t.ui.$bodyWrapper.offsetHeight,columnSorting:t.options.columnSorting,columnResize:t.options.columnResize,selection:t.options.selection});var l,d,p=!1,f=!1;s.push(o(t.ui.$bodyWrapper,"scroll",function(){f||(p=!0,l&&clearTimeout(l),l=setTimeout(function(){p=!1},250),i.ui.$bodyWrapper.scrollTop=this.scrollTop)}),o(i.ui.$bodyWrapper,"scroll",function(){p||(f=!0,d&&clearTimeout(d),d=setTimeout(function(){f=!1},250),t.ui.$bodyWrapper.scrollTop=this.scrollTop)})),s.push(t.on("trHoverTo",r),i.on("trHoverTo",r),t.on("clearHover",n),i.on("clearHover",n)),t.options.selection&&(t.on("selectedChanged",function(e){i.selectRow(e,!1)}),i.on("selectedChanged",function(e){t.selectRow(e)})),t.options.columnSorting&&(i.on("sort",function(e,r,n){t.sortBy(n)}),t.on("sort",function(e,t,r){if(!(r<a)){var n=i.sort&&i.sort.index;if("number"==typeof n){i.sort.direction=0;var o=i.ui.$columnsWrapper.querySelector('th[data-index="'+n+'"]');o&&o.classList.remove("order-by-asc","order-by-desc")}}}))}if(t.options.fixedColumns){var i,a,s=[];t.on("afterSetData",function(e){if(a=e.fixedColumnsLeft,!a)return void(i&&i.el.classList.add("hidden"));i||r(t.el),i.el.classList.remove("hidden"),i.setData({columns:t.renderData.columnsDef.slice(0,a),width:t.renderData.columnsWidth.slice(0,a),rows:t.renderData.rows});var o=n.call(i.ui.$columnsWrapper.querySelectorAll("tr")).concat(n.call(i.ui.$bodyWrapper.querySelectorAll("tr"))),s=n.call(t.ui.$columnsWrapper.querySelectorAll("tr")).concat(n.call(t.ui.$bodyWrapper.querySelectorAll("tr")));o.forEach(function(e,t){var r=s[t];e.clientHeight!==r.clientHeight&&(e.style.height=r.clientHeight+"px")})}),t.once("beforeDestroy",function(){s.forEach(function(e){e()})})}})}},function(e,t,r){r(6);var n=r(10),o=r(1);e.exports=function(e){e.hook(function(e){function t(t){return Number.isNaN(t)||t<1||t>i.totalPage?void(s.querySelector("[data-page]").value=i.cur):(s.querySelector("[data-page]").value=i.cur=t,void e.emit("switchPage",t))}if(e.options.pagination){var r=e.options.pagingTemplate||n,i=e.pager={cur:1,total:null,size:null,start:null,end:null,totalPage:null},a=[],s=document.createElement("div");s.classList.add("grid-pager-wrapper"),a.push(o(s,"click",function(e){var r=e.target.dataset.jump;if(r){var n;switch(r){case"first":n=1;break;case"end":n=i.totalPage;break;case"prev":n=i.cur-1;break;case"next":n=i.cur+1;break;default:return}t(n)}}),o(s,"keydown",function(e){13===e.keyCode&&void 0!==e.target.dataset.page&&t(Number(e.target.value))}),e.on("beforeSetData",function(e){if(!e.rows||!e.rows.length)return void s.classList.add("hidden");var t=e.size||0,n=e.total||0,o=i.cur,a=e.rows.length;i.total=n,i.size=t,i.start=(o-1)*t+1,i.end=i.start+a-1,i.total=n,i.totalPage=Math.ceil(n/t)||0,s.innerHTML=r.replace(/\{\{(\w+)\}\}/g,function(e,t){return i.hasOwnProperty(t)?i[t]:e}),s.classList.remove("hidden")})),e.once("afterInit",function(){e.ui.$gridWrapper.appendChild(s),e.ui.$pagerWrapper=s}),e.once("beforeDestroy",function(){a.forEach(function(e){e()})})}})}},function(e,t,r){r(7);var n=r(2),o=r(1),i="selected";e.exports=function(e){e.prototype.selectRow=function(e,t){var r=this.ui.$body,n=r.querySelector('tr[data-index="'+e+'"]');if(n){var o=this._selectRowsIndex.indexOf(e);if(this._isMultipleSelect)o>=0?this._selectRowsIndex.splice(o,1):this._selectRowsIndex.push(e);else{if(o>=0)return;var a=r.querySelector("tr."+i);a&&a.classList.remove(i),n.classList.add("selected"),this._selectRowsIndex=[e]}t!==!1&&this.emit("selectedChanged",this._isMultipleSelect?this._selectRowsIndex:e)}},e.prototype.selectAll=function(e,t){if(this._isMultipleSelect){this._selectRowsIndex=[];var r=this;Array.prototype.forEach.call(this.ui.$bodyWrapper.querySelectorAll("tr[data-index]"),function(t){if(e){var n=Number(t.getAttribute("data-index"));r._selectRowsIndex.push(n)}t.querySelector("input[type=checkbox]").checked=e}),t!==!1&&this.emit("selectedChanged",this._selectRowsIndex)}},e.hook(function(e){var t=e.options.selection;if(t){var r=e._isMultipleSelect="multiple"===t,i=[];i.push(e.on("beforeSetData",function(){e._selectRowsIndex=[]})),r&&i.push(e.on("beforeSetData",function(e){e.columns.unshift({sortable:!1,thRenderer:function(){return'<input type="checkbox" class="select-all">'},tdRenderer:function(){return'<input type="checkbox">'}})})),e.once("afterInit",function(){var t=e.ui.$bodyWrapper,a=e.ui.$columnsWrapper;r?(i.push(o(t,"change",function(r){if("INPUT"===r.target.tagName&&"checkbox"===r.target.type){a.querySelector("input.select-all").checked=!1;var o=n("tr",r.target,t);if(o){var i=Number(o.getAttribute("data-index"));Number.isNaN(i)||e.selectRow(i),a.querySelector("input[type=checkbox].select-all").checked=!e.empty&&e._selectRowsIndex.length===e.renderData.rows.length}}})),i.push(o(a,"change",function(t){var r=t.target;"INPUT"===r.tagName&&"checkbox"===r.type&&r.classList.contains("select-all")&&e.selectAll(r.checked)}))):i.push(o(t,"click",function(r){var o=n("tr",r.target,t);if(o){var i=Number(o.getAttribute("data-index"));Number.isNaN(i)||e.selectRow(i)}}))}),e.once("beforeDestroy",function(){i.forEach(function(e){e()})})}})}},function(e,t,r){r(8);var n=r(2),o=r(1),i=-1,a=1,s=0,c="order-by-asc",u="order-by-desc";e.exports=function(e){e.prototype.sortBy=function(e,t){var r=this.renderData.columnsDef[e];if(r&&r.sortable!==!1){var n=this.sort||(this.sort={}),o=this.ui.$columnsWrapper,l=n.index;if(e!==l){if("number"==typeof l){var d=o.querySelector('th[data-index="'+l+'"]');d&&d.classList.remove(c,u)}n.index=e,n.direction=s}var p=o.querySelector('th[data-index="'+e+'"]');switch(p.classList.remove(c,u),n.direction){case s:n.direction=a,p.classList.add(c);break;case a:n.direction=i,p.classList.add(u);break;case i:n.direction=s}t!==!1&&this.emit("sort",r,n.direction,e,p)}},e.hook(function(e){if(e.options.columnSorting){var t=[];t.push(e.on("beforeRenderColumns",function(e){e.forEach(function(t,r){e[r]=t.replace("</th>",'<span class="order-ico"></span></th>')})})),e.once("afterInit",function(){var r=e.ui.$columnsWrapper;t.push(o(r,"click",function(t){var o=n("th",t.target,r);if(o&&!o.classList.contains("resizing")){var i=Number(o.getAttribute("data-index"));window.isNaN(i)||e.sortBy(i)}}),e.on("afterSetData",function(){var t=e.sort&&e.sort.index;if(!("number"!=typeof t||t<0)){var r=e.ui.$columnsWrapper.querySelector('th[data-index="'+t+'"]');if(r)switch(e.sort.direction){case a:r.classList.add(c);break;case i:r.classList.add(u)}}}))}),e.once("beforeDestroy",function(){t.forEach(function(e){e()})})}})}},function(e,t){function r(){this._callbacks={}}var n=Array.prototype.slice,o=r.prototype;o.on=function(e,t){var r=this._callbacks,n=r[e]||(r[e]=[]);return n.push(t),function(){var e=n.indexOf(t);e>=0&&n.splice(e,1)}},o.once=function(e,t){var r=this.on(e,function(){t.apply(null,arguments),window.setTimeout(r,0)});return r},o.emit=function(e){var t=this._callbacks[e];if(t&&t.length){var r=n.call(arguments,1);t.forEach(function(e){e.apply(null,r)})}},e.exports=r},function(e,t){e.exports=function(e,t){var r;return t="number"==typeof t?t:250,function(){"number"==typeof r&&window.clearTimeout(r);var n=arguments;r=window.setTimeout(function(){e.apply(null,n)},t)}}},function(e,t){var r=Object.prototype.hasOwnProperty;e.exports=function(e){for(var t=1;t<arguments.length;t+=1){var n=arguments[t];if(n&&"object"==typeof n)for(var o in n)r.call(n,o)&&(e[o]=n[o])}return e}}]))}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Datagrid=t():e.Datagrid=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}(function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))switch(typeof e[t]){case"function":break;case"object":e[t]=function(t){var r=t.slice(1),n=e[t[0]];return function(e,t,o){n.apply(this,[e,t,o].concat(r))}}(e[t]);break;default:e[t]=e[e[t]]}return e}([function(e,t,r){e.exports=r(11),e.exports.Selection=r(15),e.exports.Paging=r(14),e.exports.Sorting=r(16),e.exports.ColumnMove=r(12),e.exports.ColumnFixed=r(13)},function(e,t){e.exports=function(e,t,r,n){return e.addEventListener(t,r,n),function(){e.removeEventListener(t,r,n)}}},function(e,t){e.exports=function(e,t,r){r||(r=document.body);var n=e.toUpperCase(),o=t,i=null;do if(o.tagName===n){i=o;break}while(o!==r&&(o=o.parentElement));return i}},function(e,t){},3,3,3,3,3,function(e,t){e.exports='<div class=grid-wrapper> <div class=grid-columns-wrapper> <table class=grid-columns> <colgroup></colgroup> <thead></thead> </table> </div> <div class=grid-body-wrapper> <table class=grid-body> <colgroup></colgroup> <tbody></tbody> </table> </div> </div> <div class="grid-no-data hidden"> <div class=no-data-content> 暂无数据 </div> </div> '},function(e,t){e.exports="<div class=grid-pager> <div>显示第 {{start}} - {{end}} 条数据, 共 {{total}} 条数据</div> <div> <span data-jump=first>首页</span> <span data-jump=prev>上一页</span> <span>第 <input type=text data-page value={{cur}}> 页, 共 {{totalPage}} 页</span> <span data-jump=next>下一页</span> <span data-jump=end>尾页</span> </div> </div> "},function(e,t,r){function n(e){return e.name}function o(e,t){return t[e.key]}function i(e,t){s.call(this);var r=this.el=document.createElement("div");this.options=u({},{height:e.offsetHeight},t),this.origin=e.parentElement.replaceChild(r,e),h.forEach(function(e){e(this)},this),this._init()}r(3);var a=r(9),s=r(17),c=r(1),u=r(19),l=r(2),d=r(18),p=100,f="data-grid",h=[];i.use=function(e){e(i)},i.hook=function(e){return h.push(e),function(){var t=h.indexOf(e);t>=0&&h.splice(t,1)}};var v=i.prototype=Object.create(s.prototype);v.constructor=i,v._init=function(){var e=this._unbindEvents=[];this.emit("beforeInit");var t=this.el;t.classList.add(f),t.innerHTML=a;var r={$gridWrapper:".grid-wrapper",$columnsWrapper:".grid-columns-wrapper",$columns:".grid-columns",$columnsColGroup:".grid-columns colgroup",$columnsThead:".grid-columns thead",$bodyWrapper:".grid-body-wrapper",$body:".grid-body",$bodyColGroup:".grid-body colgroup",$bodyTbody:".grid-body tbody",$noData:".grid-no-data"};for(var n in r)r[n]=t.querySelector(r[n]);r.$gridWrapper.style.height=this.options.height+"px";var o=this;e.push(c(r.$bodyWrapper,"scroll",function(){r.$columns.style.left="-"+r.$bodyWrapper.scrollLeft+"px"}),c(r.$bodyWrapper,"mouseover",function(e){var t=l("tr",e.target);if(t){var r=t.getAttribute("data-index");r&&o.trHover(!0,Number(r))}}),c(r.$bodyWrapper,"mouseout",function(e){var t=l("tr",e.target);if(t){var r=t.getAttribute("data-index");r&&o.trHover(!1,Number(r))}}),c(r.$bodyWrapper,"click",function(e){var t=l("td",e.target);if(t){var r=l("tr",t);if(r){var n=t.getAttribute("data-index"),i=r.getAttribute("data-index"),a=o.renderData;o.emit("cellClick",a.columnsDef[n],o.empty?null:a.rows[i])}}})),this.ui=r,this.options.fit&&e.push(c(window,"resize",d(function(){o.setWidth()}))),this.emit("afterInit")},v.trHover=function(e,t,r){var n=this.ui.$bodyTbody,o=n.querySelector('tr[data-index="'+t+'"]');o.classList[e?"add":"remove"]("hover"),r!==!1&&this.emit(e?"trHoverTo":"clearHover",t,o,this.rows&&this.rows[t])},v.setData=function(e){if(this.renderData={},this.emit("beforeSetData",e),this.empty=!(e.columns&&e.columns.length&&e.rows&&e.rows.length),this.empty){var t=this.ui;t.$body.classList.add("hidden"),t.$noData.classList.remove("hidden")}else this.setColumns(e.columns),this.setBody(e.rows),this.setWidth(e.width);this.emit("afterSetData",e)},v.normalizeWidth=function(e){var t=this.renderData,r=t.columnsDef;Array.isArray(e)||(e=[]);for(var n=[],o=0;o<r.length;o++)n[o]=e[o]||Math.max(15*(r[o].name||"").length,p);return n},v.setWidth=function(e){if(!this.empty){var t={width:e};this.emit("beforeSetWidth",t);var r=this.renderData,n=t.width;!n&&r.columnsMinWidth||(r.columnsMinWidth=this.normalizeWidth(n));var o,i=r.columnsMinWidth;if(this.options.fit){var a=i.reduce(function(e,t){return e+t}),s=this.ui.$bodyWrapper.clientWidth;if(a>=s)o=i;else{var c=(s-a)/r.columnsDef.length;o=i.map(function(e){return Math.round(e+c)})}}else o=i;r.columnsWidth=o;var u=this._colGroupsHTML(o);this._renderCols(u),this._resize(o)}},v._colGroupsHTML=function(e){return e?e.map(function(e){return'<col style="width:'+e+'px">'}):[]},v._renderCols=function(e){var t=this.ui;t.$columnsColGroup.innerHTML=t.$bodyColGroup.innerHTML=e.join("")},v._resize=function(e){var t=this.ui,r=t.$columns,n=t.$noData,o=t.$body,i=e.reduce(function(e,t){return e+t});r.style.width=o.style.width=i+"px",this.empty?n.classList.remove("hidden"):n.classList.add("hidden")},v.setColumns=function(e){var t=this.renderData.columnsDef=this._normalize(e),r=this._columnsHTML(t);this.emit("beforeRenderColumns",r),this._renderColumns(r)},v._normalize=function(e){return e.map(function(e){var t="string"==typeof e?{name:e}:e;return t.key||(t.key=t.name),t})},v._columnsHTML=function(e){var t=this.options.thRenderer;return e.map(function(e,r){var o;return e.thRenderer&&(o=e.thRenderer(e)),null==o&&(t&&(o=t(e)),null==o&&(o=n(e))),'<th data-index="'+r+'">'+o+"</th>"})},v._renderColumns=function(e){this.ui.$columnsThead.innerHTML=e.join("")},v.setBody=function(e){var t=this.renderData;this.empty=!e||!e.length,t.rows=e,this._renderBody(t.trsArr=this._bodyHTML(t.columnsDef,e))},v._bodyHTML=function(e,t){var r=this.options.tdRenderer;return this.empty?[]:t.map(function(t,n){var i='<tr data-index="'+n+'">';return e.forEach(function(e,n){var a;e.tdRenderer&&(a=e.tdRenderer(e,t)),null==a&&(r&&(a=r(e,t)),null==a&&(a=o(e,t))),i+='<td data-index="'+n+'">'+a+"</td>"}),i+="</tr>"})},v._renderBody=function(e){var t=this.ui;t.$bodyTbody.innerHTML=e.join(""),t.$body.classList.remove("hidden"),t.$noData.classList.add("hidden")},v.destroy=function(){this.emit("beforeDestroy"),this._unbindEvents.forEach(function(e){e()});var e=this.el;try{e.parentElement.replaceChild(this.origin,e)}catch(e){}this.emit("afterDestroy")},e.exports=i},function(e,t,r){r(4);var n=r(1),o=r(2),i=100,a=Array.prototype.indexOf,s="ontouchstart"in window,c=s?"touchstart":"mousedown",u=s?"touchmove":"mousemove",l=s?"touchend":"mouseup";e.exports=function(e){e.hook(function(e){if(e.options.columnResize){var t=document.createElement("div");t.classList.add("dragging-line");var r=[];e.once("afterInit",function(){e.ui.$draggingLine=t,e.el.appendChild(t)});var s,d,p,f,h,v,m=!1;r.push(e.on("beforeRenderColumns",function(e){e.forEach(function(t,r){e[r]=t.replace("</th>",'<span class="drag-lever"></span></th>')})}),n(e.el,c,function(r){if(r.target.classList.contains("drag-lever")&&0===r.button){var n=o("th",r.target,e.el);if(!n)return;n.classList.add("resizing"),d=n,v=-(n.clientWidth-i);var c=e.ui,u=c.$columnsWrapper,l=c.$bodyWrapper;t.style.height=u.offsetHeight+l.offsetHeight+"px",h=n.offsetLeft+n.clientWidth-l.scrollLeft,t.style.left=h+"px",t.classList.add("show"),m=!0,s=r.target,s.classList.add("dragging"),f=r.pageX,p=a.call(n.parentElement.children,n)}}),n(document,u,function(e){if(m){e.preventDefault();var r=e.pageX-f;r>v&&(t.style.left=h+(e.pageX-f)+"px")}}),n(document,l,function(r){if(m){setTimeout(function(){d.classList.remove("resizing")},0),t.classList.remove("show"),m=!1,s.classList.remove("dragging");var n=r.pageX-f;n<v&&(n=v);var o=e.renderData.columnsMinWidth;o[p]=o[p]+n,e.setWidth(o)}})),e.once("beforeDestroy",function(){r.forEach(function(e){e()})})}})}},function(e,t,r){r(5);var n=Array.prototype.slice,o=r(1);e.exports=function(e){e.hook(function(t){function r(){function r(e,r){var n=i.el.contains(r)?t:i;n.trHover(!0,e,!1)}function n(e,r){var n=i.el.contains(r)?t:i;n.trHover(!1,e,!1)}var c=document.createElement("div");c.classList.add("fixed-datagrid");var u=document.createElement("div");u.classList.add("hidden"),c.appendChild(u),t.el.appendChild(c),i=new e(u,{height:t.ui.$columnsWrapper.offsetHeight+t.ui.$bodyWrapper.offsetHeight,columnSorting:t.options.columnSorting,columnResize:t.options.columnResize,selection:t.options.selection});var l,d,p=!1,f=!1;s.push(o(t.ui.$bodyWrapper,"scroll",function(){f||(p=!0,l&&clearTimeout(l),l=setTimeout(function(){p=!1},250),i.ui.$bodyWrapper.scrollTop=this.scrollTop)}),o(i.ui.$bodyWrapper,"scroll",function(){p||(f=!0,d&&clearTimeout(d),d=setTimeout(function(){f=!1},250),t.ui.$bodyWrapper.scrollTop=this.scrollTop)})),s.push(t.on("trHoverTo",r),i.on("trHoverTo",r),t.on("clearHover",n),i.on("clearHover",n)),t.options.selection&&(t.on("selectedChanged",function(e){i.selectRow(e,!1)}),i.on("selectedChanged",function(e){t.selectRow(e)})),t.options.columnSorting&&(i.on("sort",function(e,r,n){t.sortBy(n)}),t.on("sort",function(e,t,r){if(!(r<a)){var n=i.sort&&i.sort.index;if("number"==typeof n){i.sort.direction=0;var o=i.ui.$columnsWrapper.querySelector('th[data-index="'+n+'"]');o&&o.classList.remove("order-by-asc","order-by-desc")}}}))}if(t.options.fixedColumns){var i,a,s=[];t.on("afterSetData",function(e){if(a=e.fixedColumnsLeft,!a)return void(i&&i.el.classList.add("hidden"));i||r(t.el),i.el.classList.remove("hidden"),i.setData({columns:t.renderData.columnsDef.slice(0,a),width:t.renderData.columnsWidth.slice(0,a),rows:t.renderData.rows});var o=n.call(i.ui.$columnsWrapper.querySelectorAll("tr")).concat(n.call(i.ui.$bodyWrapper.querySelectorAll("tr"))),s=n.call(t.ui.$columnsWrapper.querySelectorAll("tr")).concat(n.call(t.ui.$bodyWrapper.querySelectorAll("tr")));o.forEach(function(e,t){var r=s[t];e.clientHeight!==r.clientHeight&&(e.style.height=r.clientHeight+"px")})}),t.once("beforeDestroy",function(){s.forEach(function(e){e()})})}})}},function(e,t,r){r(6);var n=r(10),o=r(1);e.exports=function(e){e.hook(function(e){function t(t){return Number.isNaN(t)||t<1||t>i.totalPage?void(s.querySelector("[data-page]").value=i.cur):(s.querySelector("[data-page]").value=i.cur=t,void e.emit("switchPage",t))}if(e.options.pagination){var r=e.options.pagingTemplate||n,i=e.pager={cur:1,total:null,size:null,start:null,end:null,totalPage:null},a=[],s=document.createElement("div");s.classList.add("grid-pager-wrapper"),a.push(o(s,"click",function(e){var r=e.target.dataset.jump;if(r){var n;switch(r){case"first":n=1;break;case"end":n=i.totalPage;break;case"prev":n=i.cur-1;break;case"next":n=i.cur+1;break;default:return}t(n)}}),o(s,"keydown",function(e){13===e.keyCode&&void 0!==e.target.dataset.page&&t(Number(e.target.value))}),e.on("beforeSetData",function(e){if(!e.rows||!e.rows.length)return void s.classList.add("hidden");var t=e.size||0,n=e.total||0,o=i.cur,a=e.rows.length;i.total=n,i.size=t,i.start=(o-1)*t+1,i.end=i.start+a-1,i.total=n,i.totalPage=Math.ceil(n/t)||0,s.innerHTML=r.replace(/\{\{(\w+)\}\}/g,function(e,t){return i.hasOwnProperty(t)?i[t]:e}),s.classList.remove("hidden")})),e.once("afterInit",function(){e.ui.$gridWrapper.appendChild(s),e.ui.$pagerWrapper=s}),e.once("beforeDestroy",function(){a.forEach(function(e){e()})})}})}},function(e,t,r){r(7);var n=r(2),o=r(1),i="selected";e.exports=function(e){e.prototype.selectRow=function(e,t){var r=this.ui.$body,n=r.querySelector('tr[data-index="'+e+'"]');if(n){var o=this._selectRowsIndex.indexOf(e);if(this._isMultipleSelect)o>=0?this._selectRowsIndex.splice(o,1):this._selectRowsIndex.push(e);else{if(o>=0)return;var a=r.querySelector("tr."+i);a&&a.classList.remove(i),n.classList.add("selected"),this._selectRowsIndex=[e]}t!==!1&&this.emit("selectedChanged",this._isMultipleSelect?this._selectRowsIndex:e)}},e.prototype.selectAll=function(e,t){if(this._isMultipleSelect){this._selectRowsIndex=[];var r=this;Array.prototype.forEach.call(this.ui.$bodyWrapper.querySelectorAll("tr[data-index]"),function(t){if(e){var n=Number(t.getAttribute("data-index"));r._selectRowsIndex.push(n)}t.querySelector("input[type=checkbox]").checked=e}),t!==!1&&this.emit("selectedChanged",this._selectRowsIndex)}},e.hook(function(e){var t=e.options.selection;if(t){var r=e._isMultipleSelect="multiple"===t,i=[];i.push(e.on("beforeSetData",function(){e._selectRowsIndex=[]})),r&&i.push(e.on("beforeSetData",function(e){e.columns.unshift({sortable:!1,thRenderer:function(){return'<input type="checkbox" class="select-all">'},tdRenderer:function(){return'<input type="checkbox">'}})})),e.once("afterInit",function(){var t=e.ui.$bodyWrapper,a=e.ui.$columnsWrapper;r?(i.push(o(t,"change",function(r){if("INPUT"===r.target.tagName&&"checkbox"===r.target.type){a.querySelector("input.select-all").checked=!1;var o=n("tr",r.target,t);if(o){var i=Number(o.getAttribute("data-index"));Number.isNaN(i)||e.selectRow(i),a.querySelector("input[type=checkbox].select-all").checked=!e.empty&&e._selectRowsIndex.length===e.renderData.rows.length}}})),i.push(o(a,"change",function(t){var r=t.target;"INPUT"===r.tagName&&"checkbox"===r.type&&r.classList.contains("select-all")&&e.selectAll(r.checked)}))):i.push(o(t,"click",function(r){var o=n("tr",r.target,t);if(o){var i=Number(o.getAttribute("data-index"));Number.isNaN(i)||e.selectRow(i)}}))}),e.once("beforeDestroy",function(){i.forEach(function(e){e()})})}})}},function(e,t,r){r(8);var n=r(2),o=r(1),i=-1,a=1,s=0,c="order-by-asc",u="order-by-desc";e.exports=function(e){e.prototype.sortBy=function(e,t){var r=this.renderData.columnsDef[e];if(r&&r.sortable!==!1){var n=this.sort||(this.sort={}),o=this.ui.$columnsWrapper,l=n.index;if(e!==l){if("number"==typeof l){var d=o.querySelector('th[data-index="'+l+'"]');d&&d.classList.remove(c,u)}n.index=e,n.direction=s}var p=o.querySelector('th[data-index="'+e+'"]');switch(p.classList.remove(c,u),n.direction){case s:n.direction=a,p.classList.add(c);break;case a:n.direction=i,p.classList.add(u);break;case i:n.direction=s}t!==!1&&this.emit("sort",r,n.direction,e,p)}},e.hook(function(e){if(e.options.columnSorting){var t=[];t.push(e.on("beforeRenderColumns",function(e){e.forEach(function(t,r){e[r]=t.replace("</th>",'<span class="order-ico"></span></th>')})})),e.once("afterInit",function(){var r=e.ui.$columnsWrapper;t.push(o(r,"click",function(t){var o=n("th",t.target,r);if(o&&!o.classList.contains("resizing")){var i=Number(o.getAttribute("data-index"));window.isNaN(i)||e.sortBy(i)}}),e.on("afterSetData",function(){var t=e.sort&&e.sort.index;if(!("number"!=typeof t||t<0)){var r=e.ui.$columnsWrapper.querySelector('th[data-index="'+t+'"]');if(r)switch(e.sort.direction){case a:r.classList.add(c);break;case i:r.classList.add(u)}}}))}),e.once("beforeDestroy",function(){t.forEach(function(e){e()})})}})}},function(e,t){function r(){this._callbacks={}}var n=Array.prototype.slice,o=r.prototype;o.on=function(e,t){var r=this._callbacks,n=r[e]||(r[e]=[]);return n.push(t),function(){var e=n.indexOf(t);e>=0&&n.splice(e,1)}},o.once=function(e,t){var r=this.on(e,function(){t.apply(null,arguments),window.setTimeout(r,0)});return r},o.emit=function(e){var t=this._callbacks[e];if(t&&t.length){var r=n.call(arguments,1);t.forEach(function(e){e.apply(null,r)})}},e.exports=r},function(e,t){e.exports=function(e,t){var r;return t="number"==typeof t?t:250,function(){"number"==typeof r&&window.clearTimeout(r);var n=arguments;r=window.setTimeout(function(){e.apply(null,n)},t)}}},function(e,t){var r=Object.prototype.hasOwnProperty;e.exports=function(e){for(var t=1;t<arguments.length;t+=1){var n=arguments[t];if(n&&"object"==typeof n)for(var o in n)r.call(n,o)&&(e[o]=n[o])}return e}}]))}); |
{ | ||
"name": "datagrid", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Datagrid.", | ||
@@ -28,18 +28,18 @@ "main": "./src/index.js", | ||
"file-loader": "0.9.0", | ||
"postcss-loader": "0.13.0", | ||
"autoprefixer": "6.4.1", | ||
"postcss-loader": "1.1.1", | ||
"autoprefixer": "6.5.3", | ||
"html-loader": "0.4.4", | ||
"node-sass": "3.10.0", | ||
"node-sass": "3.11.2", | ||
"sass-loader": "4.0.2", | ||
"css-loader": "0.25.0", | ||
"style-loader": "0.13.1", | ||
"html-webpack-plugin": "2.22.0", | ||
"html-webpack-plugin": "2.24.1", | ||
"extract-text-webpack-plugin": "1.0.1", | ||
"webpack-dev-server": "1.16.1", | ||
"webpack": "1.13.2", | ||
"eslint": "3.6.0", | ||
"webpack-dev-server": "1.16.2", | ||
"webpack": "1.13.3", | ||
"eslint": "3.9.1", | ||
"eslint-plugin-html": "1.5.3", | ||
"eslint-config-standard": "6.0.1", | ||
"eslint-plugin-promise": "2.0.1", | ||
"eslint-plugin-standard": "2.0.0" | ||
"eslint-config-standard": "6.2.1", | ||
"eslint-plugin-promise": "3.3.1", | ||
"eslint-plugin-standard": "2.0.1" | ||
}, | ||
@@ -46,0 +46,0 @@ "author": "Milk Lee <milk.lee@qq.com>", |
@@ -217,2 +217,3 @@ require('./index.scss') | ||
dp.setWidth = function (width) { | ||
if (this.empty) return | ||
var obj = { width: width } | ||
@@ -219,0 +220,0 @@ this.emit('beforeSetWidth', obj) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101631
2191