New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

datagrid

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datagrid - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

4

dist/datagrid.js

@@ -228,4 +228,4 @@ (function webpackUniversalModuleDefinition(root, factory) {

dp.trHover = function (inOrOut, index, emit) {
var tbody = this.ui.$bodyWrapper.querySelector('tbody')
var hoverToTR = tbody.querySelector('[data-index="' + index + '"]')
var tbody = this.ui.$bodyTbody
var hoverToTR = tbody.querySelector('tr[data-index="' + index + '"]')
hoverToTR.classList[inOrOut ? 'add' : 'remove']('hover')

@@ -232,0 +232,0 @@ if (emit !== false) this.emit(inOrOut ? 'trHoverTo' : 'clearHover', index, hoverToTR, this.rows && this.rows[index])

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Datagrid=e():t.Datagrid=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}(function(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))switch(typeof t[e]){case"function":break;case"object":t[e]=function(e){var n=e.slice(1),r=t[e[0]];return function(t,e,o){r.apply(this,[t,e,o].concat(n))}}(t[e]);break;default:t[e]=t[t[e]]}return t}([function(t,e,n){t.exports=n(11),t.exports.Selection=n(15),t.exports.Paging=n(14),t.exports.Sorting=n(16),t.exports.ColumnMove=n(12),t.exports.ColumnFixed=n(13)},function(t,e){t.exports=function(t,e,n,r){return t.addEventListener(e,n,r),function(){t.removeEventListener(e,n,r)}}},function(t,e){t.exports=function(t,e,n){n||(n=document.body);var r=t.toUpperCase(),o=e,i=null;do if(o.tagName===r){i=o;break}while(o!==n&&(o=o.parentElement));return i}},function(t,e){},3,3,3,3,3,function(t,e){t.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(t,e){t.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(t,e,n){function r(t){return t.name}function o(t,e){return e[t.key]}function i(t,e){s.call(this);var n=this.el=document.createElement("div");this.options=u({},{height:t.offsetHeight},e),this.origin=t.parentElement.replaceChild(n,t),f.forEach(function(t){t(this)},this),this._init()}n(3);var a=n(9),s=n(17),c=n(1),u=n(19),d=n(2),l=n(18),p=100,f=[];i.use=function(t){t(i)},i.hook=function(t){return f.push(t),function(){var e=f.indexOf(t);e>=0&&f.splice(e,1)}};var h=i.prototype=Object.create(s.prototype);h.constructor=i,h._init=function(){var t=this._unbindEvents=[];this.emit("beforeInit");var e=this.el;e.classList.add("datagrid"),e.innerHTML=a;var n={$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 r in n)n[r]=e.querySelector(n[r]);n.$gridWrapper.style.height=this.options.height+"px";var o=this;t.push(c(n.$bodyWrapper,"scroll",function(){n.$columns.style.left="-"+n.$bodyWrapper.scrollLeft+"px"}),c(n.$bodyWrapper,"mouseover",function(t){var e=d("tr",t.target);if(e){var n=e.getAttribute("data-index");n&&o.trHover(!0,Number(n))}}),c(n.$bodyWrapper,"mouseout",function(t){var e=d("tr",t.target);if(e){var n=e.getAttribute("data-index");n&&o.trHover(!1,Number(n))}}),c(n.$bodyWrapper,"click",function(t){var e=d("td",t.target);if(e){var n=d("tr",e);if(n){var r=e.getAttribute("data-index"),i=n.getAttribute("data-index"),a=o.renderData;o.emit("cellClick",a.columnsDef[r],o.empty?null:a.rows[i])}}})),this.ui=n,this.options.fit&&t.push(c(window,"resize",l(function(){o.setWidth()}))),this.emit("afterInit")},h.trHover=function(t,e,n){var r=this.ui.$bodyWrapper.querySelector("tbody"),o=r.querySelector('[data-index="'+e+'"]');o.classList[t?"add":"remove"]("hover"),n!==!1&&this.emit(t?"trHoverTo":"clearHover",e,o,this.rows&&this.rows[e])},h.setData=function(t){this.emit("beforeSetData",t),this.renderData={},this.setColumns(t.columns),this.setBody(t.rows),this.setWidth(t.width),this.emit("afterSetData",t)},h.normalizeWidth=function(t){var e=this.renderData,n=e.columnsDef;Array.isArray(t)||(t=[]);for(var r=[],o=0;o<n.length;o++)r[o]=t[o]||Math.max(15*n[o].name.length,p);return r},h.setWidth=function(t){var e=this.renderData;!t&&e.columnsMinWidth||(e.columnsMinWidth=this.normalizeWidth(t));var n,r=e.columnsMinWidth;if(this.options.fit){var o=r.reduce(function(t,e){return t+e}),i=this.ui.$bodyWrapper.clientWidth;if(o>=i)n=r;else{var a=(i-o)/e.columnsDef.length;n=r.map(function(t){return t+a})}}else n=r;e.columnsWidth=n;var s=this._colGroupsHTML(n);this._renderCols(s),this._resize(n)},h._colGroupsHTML=function(t){return t?t.map(function(t){return'<col style="width:'+t+'px">'}):[]},h._renderCols=function(t){var e=this.ui;e.$columnsColGroup.innerHTML=e.$bodyColGroup.innerHTML=t.join("")},h._resize=function(t){var e=this.ui,n=e.$columns,r=e.$noData,o=e.$body,i=t.reduce(function(t,e){return t+e});n.style.width=o.style.width=i+"px",this.empty?r.classList.remove("hidden"):r.classList.add("hidden")},h.setColumns=function(t){var e=this.renderData.columnsDef=this._normalize(t),n=this._columnsHTML(e);this.emit("beforeRenderColumns",n),this._renderColumns(n)},h._normalize=function(t){return t.map(function(t){var e="string"==typeof t?{name:t}:t;return e.key||(e.key=e.name),e})},h._columnsHTML=function(t){var e=this.options.thRenderer;return t.map(function(t,n){var o;return e&&(o=e(t)),null==o&&(t.thRenderer&&(o=t.thRenderer(t)),null==o&&(o=r(t))),'<th data-index="'+n+'">'+o+"</th>"})},h._renderColumns=function(t){this.ui.$columnsThead.innerHTML=t.join("")},h.setBody=function(t){var e=this.renderData;this.empty=!t||!t.length,e.rows=t,this._renderBody(e.trsArr=this._bodyHTML(e.columnsDef,t))},h._bodyHTML=function(t,e){var n=this.options.tdRenderer;return this.empty?[]:e.map(function(e,r){var i='<tr data-index="'+r+'">';return t.forEach(function(t,r){var a;n&&(a=n(t,e)),null==a&&(t.tdRenderer&&(a=t.tdRenderer(t,e)),null==a&&(a=o(t,e))),i+='<td data-index="'+r+'">'+a+"</td>"}),i+="</tr>"})},h._renderBody=function(t){var e=this.ui,n=e.$body,r=e.$noData,o=e.$bodyTbody;return this.empty?(n.classList.add("hidden"),void r.classList.remove("hidden")):(o.innerHTML=t.join(""),n.classList.remove("hidden"),void r.classList.add("hidden"))},h.destroy=function(){this.emit("beforeDestroy"),this._unbindEvents.forEach(function(t){t()});var t=this.el;try{t.parentElement.replaceChild(this.origin,t)}catch(e){}this.emit("afterDestroy")},t.exports=i},function(t,e,n){n(4);var r=n(1),o=n(2),i=100,a=Array.prototype.indexOf,s="ontouchstart"in window,c=s?"touchstart":"mousedown",u=s?"touchmove":"mousemove",d=s?"touchend":"mouseup";t.exports=function(t){t.hook(function(t){if(t.options.columnResize){var e=document.createElement("div");e.classList.add("dragging-line");var n=[];t.once("afterInit",function(){t.ui.$draggingLine=e,t.el.appendChild(e)});var s,l,p,f,h,v,m=!1;n.push(t.on("beforeRenderColumns",function(t){t.forEach(function(e,n){t[n]=e.replace("</th>",'<span class="drag-lever"></span></th>')})}),r(t.el,c,function(n){if(n.target.classList.contains("drag-lever")&&0===n.button){var r=o("th",n.target,t.el);if(!r)return;r.classList.add("resizing"),l=r,v=-(r.clientWidth-i);var c=t.ui,u=c.$columnsWrapper,d=c.$bodyWrapper;e.style.height=u.offsetHeight+d.offsetHeight+"px",h=r.offsetLeft+r.clientWidth-d.scrollLeft,e.style.left=h+"px",e.classList.add("show"),m=!0,s=n.target,s.classList.add("dragging"),f=n.pageX,p=a.call(r.parentElement.children,r)}}),r(document,u,function(t){if(m){t.preventDefault();var n=t.pageX-f;n>v&&(e.style.left=h+(t.pageX-f)+"px")}}),r(document,d,function(n){if(m){setTimeout(function(){l.classList.remove("resizing")},0),e.classList.remove("show"),m=!1,s.classList.remove("dragging");var r=n.pageX-f;r<v&&(r=v);var o=t.renderData.columnsMinWidth;o[p]=o[p]+r,t.setWidth(o)}})),t.once("beforeDestroy",function(){n.forEach(function(t){t()})})}})}},function(t,e,n){n(5);var r=n(1);t.exports=function(t){t.hook(function(e){function n(){function n(t,n){var r=o.el.contains(n)?e:o;r.trHover(!0,t,!1)}function a(t,n){var r=o.el.contains(n)?e:o;r.trHover(!1,t,!1)}var s=document.createElement("div");s.classList.add("fixed-datagrid");var c=document.createElement("div");c.classList.add("hidden"),s.appendChild(c),e.el.appendChild(s),o=new t(c,{height:e.ui.$columnsWrapper.offsetHeight+e.ui.$bodyWrapper.offsetHeight,columnSorting:e.options.columnSorting,columnResize:e.options.columnResize,selection:e.options.selection});var u,d,l=!1,p=!1;i.push(r(e.ui.$bodyWrapper,"scroll",function(){p||(l=!0,u&&clearTimeout(u),u=setTimeout(function(){l=!1},250),o.ui.$bodyWrapper.scrollTop=this.scrollTop)}),r(o.ui.$bodyWrapper,"scroll",function(){l||(p=!0,d&&clearTimeout(d),d=setTimeout(function(){p=!1},250),e.ui.$bodyWrapper.scrollTop=this.scrollTop)})),i.push(e.on("trHoverTo",n),o.on("trHoverTo",n),e.on("clearHover",a),o.on("clearHover",a)),e.options.selection&&(e.on("selectedChanged",function(t){o.selectRow(t,!1)}),o.on("selectedChanged",function(t){e.selectRow(t)}))}if(e.options.fixedColumns){var o,i=[];e.on("afterSetData",function(t){var r=t.fixedColumnsLeft;return r?(o||n(e.el),o.el.classList.remove("hidden"),void o.setData({columns:e.renderData.columnsDef.slice(0,r),width:e.renderData.columnsWidth.slice(0,r),rows:e.renderData.rows})):void(o&&o.el.classList.add("hidden"))}),e.once("beforeDestroy",function(){i.forEach(function(t){t()})})}})}},function(t,e,n){n(6);var r=n(10),o=n(1);t.exports=function(t){t.hook(function(t){function e(e){return Number.isNaN(e)||e<1||e>i.totalPage?void(s.querySelector("[data-page]").value=i.cur):(s.querySelector("[data-page]").value=i.cur=e,void t.emit("switchPage",e))}if(t.options.pagination){var n=t.options.pagingTemplate||r,i=t.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(t){var n=t.target.dataset.jump;if(n){var r;switch(n){case"first":r=1;break;case"end":r=i.totalPage;break;case"prev":r=i.cur-1;break;case"next":r=i.cur+1;break;default:return}e(r)}}),o(s,"keydown",function(t){13===t.keyCode&&void 0!==t.target.dataset.page&&e(Number(t.target.value))}),t.on("beforeSetData",function(t){if(!t.rows||!t.rows.length)return void s.classList.add("hidden");var e=t.size||0,r=t.total||0,o=i.cur,a=t.rows.length;i.total=r,i.size=e,i.start=(o-1)*e+1,i.end=i.start+a-1,i.total=r,i.totalPage=Math.ceil(r/e)||0,s.innerHTML=n.replace(/\{\{(\w+)\}\}/g,function(t,e){return i.hasOwnProperty(e)?i[e]:t}),s.classList.remove("hidden")})),t.once("afterInit",function(){t.ui.$gridWrapper.appendChild(s),t.ui.$pagerWrapper=s}),t.once("beforeDestroy",function(){a.forEach(function(t){t()})})}})}},function(t,e,n){n(7);var r=n(2),o=n(1);t.exports=function(t){t.prototype.selectRow=function(t,e){var n=this.ui.$body,r=n.querySelector('tr[data-index="'+t+'"]');if(r){var o=n.querySelector("tr.selected");o&&o.classList.remove("selected"),r.classList.add("selected"),this._selectRowIndex=t,e!==!1&&this.emit("selectedChanged",t)}},t.hook(function(t){if(t.options.selection){var e=[];e.push(t.on("beforeSetData",function(){t._selectRowIndex=null})),t.once("afterInit",function(){var n=t.ui.$body;e.push(o(n,"click",function(e){var o=r("tr",e.target,n);if(o){var i=Number(o.dataset.index);Number.isNaN(i)||t._selectRowIndex===i||t.selectRow(i)}}))}),t.once("beforeDestroy",function(){e.forEach(function(t){t()})})}})}},function(t,e,n){n(8);var r=n(2),o=n(1),i=Array.prototype.indexOf,a=-1,s=1,c=0,u="order-by-asc",d="order-by-desc";t.exports=function(t){t.hook(function(t){function e(){if("number"==typeof n){var e=t.ui.$columnsWrapper.querySelector("th:nth-child("+(n+1)+")");e&&e.classList.remove(u,d)}}if(t.options.columnSorting){var n,l=[],p=c;l.push(t.on("beforeRenderColumns",function(t){t.forEach(function(e,n){t[n]=e.replace("</th>",'<span class="order-ico"></span></th>')})})),t.once("afterInit",function(){var f=t.ui.$columnsWrapper;l.push(o(f,"click",function(o){var l=r("th",o.target,f);if(l&&!l.classList.contains("resizing")){var h=i.call(l.parentElement.children,l),v=t.renderData.columnsDef[h];if(v.sortable!==!1){switch(h!==n&&(e(),n=h,p=c),l.classList.remove(u,d),p){case c:p=s,l.classList.add(u);break;case s:p=a,l.classList.add(d);break;case a:p=c}t.emit("sort",v,p,l)}}}))}),t.once("beforeDestroy",function(){l.forEach(function(t){t()})})}})}},function(t,e){function n(){this._callbacks={}}var r=Array.prototype.slice,o=n.prototype;o.on=function(t,e){var n=this._callbacks,r=n[t]||(n[t]=[]);return r.push(e),function(){var t=r.indexOf(e);t>=0&&r.splice(t,1)}},o.once=function(t,e){var n=this.on(t,function(){e.apply(null,arguments),window.setTimeout(n,0)});return n},o.emit=function(t){var e=this._callbacks[t];if(e&&e.length){var n=r.call(arguments,1);e.forEach(function(t){t.apply(null,n)})}},t.exports=n},function(t,e){t.exports=function(t,e){var n;return e="number"==typeof e?e:250,function(){"number"==typeof n&&window.clearTimeout(n);var r=arguments;n=window.setTimeout(function(){t.apply(null,r)},e)}}},function(t,e){var n=Object.prototype.hasOwnProperty;t.exports=function(t){for(var e=1;e<arguments.length;e+=1){var r=arguments[e];if(r&&"object"==typeof r)for(var o in r)n.call(r,o)&&(t[o]=r[o])}return t}}]))});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Datagrid=e():t.Datagrid=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}(function(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))switch(typeof t[e]){case"function":break;case"object":t[e]=function(e){var n=e.slice(1),r=t[e[0]];return function(t,e,o){r.apply(this,[t,e,o].concat(n))}}(t[e]);break;default:t[e]=t[t[e]]}return t}([function(t,e,n){t.exports=n(11),t.exports.Selection=n(15),t.exports.Paging=n(14),t.exports.Sorting=n(16),t.exports.ColumnMove=n(12),t.exports.ColumnFixed=n(13)},function(t,e){t.exports=function(t,e,n,r){return t.addEventListener(e,n,r),function(){t.removeEventListener(e,n,r)}}},function(t,e){t.exports=function(t,e,n){n||(n=document.body);var r=t.toUpperCase(),o=e,i=null;do if(o.tagName===r){i=o;break}while(o!==n&&(o=o.parentElement));return i}},function(t,e){},3,3,3,3,3,function(t,e){t.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(t,e){t.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(t,e,n){function r(t){return t.name}function o(t,e){return e[t.key]}function i(t,e){s.call(this);var n=this.el=document.createElement("div");this.options=u({},{height:t.offsetHeight},e),this.origin=t.parentElement.replaceChild(n,t),f.forEach(function(t){t(this)},this),this._init()}n(3);var a=n(9),s=n(17),c=n(1),u=n(19),d=n(2),l=n(18),p=100,f=[];i.use=function(t){t(i)},i.hook=function(t){return f.push(t),function(){var e=f.indexOf(t);e>=0&&f.splice(e,1)}};var h=i.prototype=Object.create(s.prototype);h.constructor=i,h._init=function(){var t=this._unbindEvents=[];this.emit("beforeInit");var e=this.el;e.classList.add("datagrid"),e.innerHTML=a;var n={$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 r in n)n[r]=e.querySelector(n[r]);n.$gridWrapper.style.height=this.options.height+"px";var o=this;t.push(c(n.$bodyWrapper,"scroll",function(){n.$columns.style.left="-"+n.$bodyWrapper.scrollLeft+"px"}),c(n.$bodyWrapper,"mouseover",function(t){var e=d("tr",t.target);if(e){var n=e.getAttribute("data-index");n&&o.trHover(!0,Number(n))}}),c(n.$bodyWrapper,"mouseout",function(t){var e=d("tr",t.target);if(e){var n=e.getAttribute("data-index");n&&o.trHover(!1,Number(n))}}),c(n.$bodyWrapper,"click",function(t){var e=d("td",t.target);if(e){var n=d("tr",e);if(n){var r=e.getAttribute("data-index"),i=n.getAttribute("data-index"),a=o.renderData;o.emit("cellClick",a.columnsDef[r],o.empty?null:a.rows[i])}}})),this.ui=n,this.options.fit&&t.push(c(window,"resize",l(function(){o.setWidth()}))),this.emit("afterInit")},h.trHover=function(t,e,n){var r=this.ui.$bodyTbody,o=r.querySelector('tr[data-index="'+e+'"]');o.classList[t?"add":"remove"]("hover"),n!==!1&&this.emit(t?"trHoverTo":"clearHover",e,o,this.rows&&this.rows[e])},h.setData=function(t){this.emit("beforeSetData",t),this.renderData={},this.setColumns(t.columns),this.setBody(t.rows),this.setWidth(t.width),this.emit("afterSetData",t)},h.normalizeWidth=function(t){var e=this.renderData,n=e.columnsDef;Array.isArray(t)||(t=[]);for(var r=[],o=0;o<n.length;o++)r[o]=t[o]||Math.max(15*n[o].name.length,p);return r},h.setWidth=function(t){var e=this.renderData;!t&&e.columnsMinWidth||(e.columnsMinWidth=this.normalizeWidth(t));var n,r=e.columnsMinWidth;if(this.options.fit){var o=r.reduce(function(t,e){return t+e}),i=this.ui.$bodyWrapper.clientWidth;if(o>=i)n=r;else{var a=(i-o)/e.columnsDef.length;n=r.map(function(t){return t+a})}}else n=r;e.columnsWidth=n;var s=this._colGroupsHTML(n);this._renderCols(s),this._resize(n)},h._colGroupsHTML=function(t){return t?t.map(function(t){return'<col style="width:'+t+'px">'}):[]},h._renderCols=function(t){var e=this.ui;e.$columnsColGroup.innerHTML=e.$bodyColGroup.innerHTML=t.join("")},h._resize=function(t){var e=this.ui,n=e.$columns,r=e.$noData,o=e.$body,i=t.reduce(function(t,e){return t+e});n.style.width=o.style.width=i+"px",this.empty?r.classList.remove("hidden"):r.classList.add("hidden")},h.setColumns=function(t){var e=this.renderData.columnsDef=this._normalize(t),n=this._columnsHTML(e);this.emit("beforeRenderColumns",n),this._renderColumns(n)},h._normalize=function(t){return t.map(function(t){var e="string"==typeof t?{name:t}:t;return e.key||(e.key=e.name),e})},h._columnsHTML=function(t){var e=this.options.thRenderer;return t.map(function(t,n){var o;return e&&(o=e(t)),null==o&&(t.thRenderer&&(o=t.thRenderer(t)),null==o&&(o=r(t))),'<th data-index="'+n+'">'+o+"</th>"})},h._renderColumns=function(t){this.ui.$columnsThead.innerHTML=t.join("")},h.setBody=function(t){var e=this.renderData;this.empty=!t||!t.length,e.rows=t,this._renderBody(e.trsArr=this._bodyHTML(e.columnsDef,t))},h._bodyHTML=function(t,e){var n=this.options.tdRenderer;return this.empty?[]:e.map(function(e,r){var i='<tr data-index="'+r+'">';return t.forEach(function(t,r){var a;n&&(a=n(t,e)),null==a&&(t.tdRenderer&&(a=t.tdRenderer(t,e)),null==a&&(a=o(t,e))),i+='<td data-index="'+r+'">'+a+"</td>"}),i+="</tr>"})},h._renderBody=function(t){var e=this.ui,n=e.$body,r=e.$noData,o=e.$bodyTbody;return this.empty?(n.classList.add("hidden"),void r.classList.remove("hidden")):(o.innerHTML=t.join(""),n.classList.remove("hidden"),void r.classList.add("hidden"))},h.destroy=function(){this.emit("beforeDestroy"),this._unbindEvents.forEach(function(t){t()});var t=this.el;try{t.parentElement.replaceChild(this.origin,t)}catch(e){}this.emit("afterDestroy")},t.exports=i},function(t,e,n){n(4);var r=n(1),o=n(2),i=100,a=Array.prototype.indexOf,s="ontouchstart"in window,c=s?"touchstart":"mousedown",u=s?"touchmove":"mousemove",d=s?"touchend":"mouseup";t.exports=function(t){t.hook(function(t){if(t.options.columnResize){var e=document.createElement("div");e.classList.add("dragging-line");var n=[];t.once("afterInit",function(){t.ui.$draggingLine=e,t.el.appendChild(e)});var s,l,p,f,h,v,m=!1;n.push(t.on("beforeRenderColumns",function(t){t.forEach(function(e,n){t[n]=e.replace("</th>",'<span class="drag-lever"></span></th>')})}),r(t.el,c,function(n){if(n.target.classList.contains("drag-lever")&&0===n.button){var r=o("th",n.target,t.el);if(!r)return;r.classList.add("resizing"),l=r,v=-(r.clientWidth-i);var c=t.ui,u=c.$columnsWrapper,d=c.$bodyWrapper;e.style.height=u.offsetHeight+d.offsetHeight+"px",h=r.offsetLeft+r.clientWidth-d.scrollLeft,e.style.left=h+"px",e.classList.add("show"),m=!0,s=n.target,s.classList.add("dragging"),f=n.pageX,p=a.call(r.parentElement.children,r)}}),r(document,u,function(t){if(m){t.preventDefault();var n=t.pageX-f;n>v&&(e.style.left=h+(t.pageX-f)+"px")}}),r(document,d,function(n){if(m){setTimeout(function(){l.classList.remove("resizing")},0),e.classList.remove("show"),m=!1,s.classList.remove("dragging");var r=n.pageX-f;r<v&&(r=v);var o=t.renderData.columnsMinWidth;o[p]=o[p]+r,t.setWidth(o)}})),t.once("beforeDestroy",function(){n.forEach(function(t){t()})})}})}},function(t,e,n){n(5);var r=n(1);t.exports=function(t){t.hook(function(e){function n(){function n(t,n){var r=o.el.contains(n)?e:o;r.trHover(!0,t,!1)}function a(t,n){var r=o.el.contains(n)?e:o;r.trHover(!1,t,!1)}var s=document.createElement("div");s.classList.add("fixed-datagrid");var c=document.createElement("div");c.classList.add("hidden"),s.appendChild(c),e.el.appendChild(s),o=new t(c,{height:e.ui.$columnsWrapper.offsetHeight+e.ui.$bodyWrapper.offsetHeight,columnSorting:e.options.columnSorting,columnResize:e.options.columnResize,selection:e.options.selection});var u,d,l=!1,p=!1;i.push(r(e.ui.$bodyWrapper,"scroll",function(){p||(l=!0,u&&clearTimeout(u),u=setTimeout(function(){l=!1},250),o.ui.$bodyWrapper.scrollTop=this.scrollTop)}),r(o.ui.$bodyWrapper,"scroll",function(){l||(p=!0,d&&clearTimeout(d),d=setTimeout(function(){p=!1},250),e.ui.$bodyWrapper.scrollTop=this.scrollTop)})),i.push(e.on("trHoverTo",n),o.on("trHoverTo",n),e.on("clearHover",a),o.on("clearHover",a)),e.options.selection&&(e.on("selectedChanged",function(t){o.selectRow(t,!1)}),o.on("selectedChanged",function(t){e.selectRow(t)}))}if(e.options.fixedColumns){var o,i=[];e.on("afterSetData",function(t){var r=t.fixedColumnsLeft;return r?(o||n(e.el),o.el.classList.remove("hidden"),void o.setData({columns:e.renderData.columnsDef.slice(0,r),width:e.renderData.columnsWidth.slice(0,r),rows:e.renderData.rows})):void(o&&o.el.classList.add("hidden"))}),e.once("beforeDestroy",function(){i.forEach(function(t){t()})})}})}},function(t,e,n){n(6);var r=n(10),o=n(1);t.exports=function(t){t.hook(function(t){function e(e){return Number.isNaN(e)||e<1||e>i.totalPage?void(s.querySelector("[data-page]").value=i.cur):(s.querySelector("[data-page]").value=i.cur=e,void t.emit("switchPage",e))}if(t.options.pagination){var n=t.options.pagingTemplate||r,i=t.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(t){var n=t.target.dataset.jump;if(n){var r;switch(n){case"first":r=1;break;case"end":r=i.totalPage;break;case"prev":r=i.cur-1;break;case"next":r=i.cur+1;break;default:return}e(r)}}),o(s,"keydown",function(t){13===t.keyCode&&void 0!==t.target.dataset.page&&e(Number(t.target.value))}),t.on("beforeSetData",function(t){if(!t.rows||!t.rows.length)return void s.classList.add("hidden");var e=t.size||0,r=t.total||0,o=i.cur,a=t.rows.length;i.total=r,i.size=e,i.start=(o-1)*e+1,i.end=i.start+a-1,i.total=r,i.totalPage=Math.ceil(r/e)||0,s.innerHTML=n.replace(/\{\{(\w+)\}\}/g,function(t,e){return i.hasOwnProperty(e)?i[e]:t}),s.classList.remove("hidden")})),t.once("afterInit",function(){t.ui.$gridWrapper.appendChild(s),t.ui.$pagerWrapper=s}),t.once("beforeDestroy",function(){a.forEach(function(t){t()})})}})}},function(t,e,n){n(7);var r=n(2),o=n(1);t.exports=function(t){t.prototype.selectRow=function(t,e){var n=this.ui.$body,r=n.querySelector('tr[data-index="'+t+'"]');if(r){var o=n.querySelector("tr.selected");o&&o.classList.remove("selected"),r.classList.add("selected"),this._selectRowIndex=t,e!==!1&&this.emit("selectedChanged",t)}},t.hook(function(t){if(t.options.selection){var e=[];e.push(t.on("beforeSetData",function(){t._selectRowIndex=null})),t.once("afterInit",function(){var n=t.ui.$body;e.push(o(n,"click",function(e){var o=r("tr",e.target,n);if(o){var i=Number(o.dataset.index);Number.isNaN(i)||t._selectRowIndex===i||t.selectRow(i)}}))}),t.once("beforeDestroy",function(){e.forEach(function(t){t()})})}})}},function(t,e,n){n(8);var r=n(2),o=n(1),i=Array.prototype.indexOf,a=-1,s=1,c=0,u="order-by-asc",d="order-by-desc";t.exports=function(t){t.hook(function(t){function e(){if("number"==typeof n){var e=t.ui.$columnsWrapper.querySelector("th:nth-child("+(n+1)+")");e&&e.classList.remove(u,d)}}if(t.options.columnSorting){var n,l=[],p=c;l.push(t.on("beforeRenderColumns",function(t){t.forEach(function(e,n){t[n]=e.replace("</th>",'<span class="order-ico"></span></th>')})})),t.once("afterInit",function(){var f=t.ui.$columnsWrapper;l.push(o(f,"click",function(o){var l=r("th",o.target,f);if(l&&!l.classList.contains("resizing")){var h=i.call(l.parentElement.children,l),v=t.renderData.columnsDef[h];if(v.sortable!==!1){switch(h!==n&&(e(),n=h,p=c),l.classList.remove(u,d),p){case c:p=s,l.classList.add(u);break;case s:p=a,l.classList.add(d);break;case a:p=c}t.emit("sort",v,p,l)}}}))}),t.once("beforeDestroy",function(){l.forEach(function(t){t()})})}})}},function(t,e){function n(){this._callbacks={}}var r=Array.prototype.slice,o=n.prototype;o.on=function(t,e){var n=this._callbacks,r=n[t]||(n[t]=[]);return r.push(e),function(){var t=r.indexOf(e);t>=0&&r.splice(t,1)}},o.once=function(t,e){var n=this.on(t,function(){e.apply(null,arguments),window.setTimeout(n,0)});return n},o.emit=function(t){var e=this._callbacks[t];if(e&&e.length){var n=r.call(arguments,1);e.forEach(function(t){t.apply(null,n)})}},t.exports=n},function(t,e){t.exports=function(t,e){var n;return e="number"==typeof e?e:250,function(){"number"==typeof n&&window.clearTimeout(n);var r=arguments;n=window.setTimeout(function(){t.apply(null,r)},e)}}},function(t,e){var n=Object.prototype.hasOwnProperty;t.exports=function(t){for(var e=1;e<arguments.length;e+=1){var r=arguments[e];if(r&&"object"==typeof r)for(var o in r)n.call(r,o)&&(t[o]=r[o])}return t}}]))});
{
"name": "datagrid",
"version": "0.2.1",
"version": "0.2.2",
"description": "Datagrid.",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -160,4 +160,4 @@ require('./index.scss')

dp.trHover = function (inOrOut, index, emit) {
var tbody = this.ui.$bodyWrapper.querySelector('tbody')
var hoverToTR = tbody.querySelector('[data-index="' + index + '"]')
var tbody = this.ui.$bodyTbody
var hoverToTR = tbody.querySelector('tr[data-index="' + index + '"]')
hoverToTR.classList[inOrOut ? 'add' : 'remove']('hover')

@@ -164,0 +164,0 @@ if (emit !== false) this.emit(inOrOut ? 'trHoverTo' : 'clearHover', index, hoverToTR, this.rows && this.rows[index])

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc