UNPKG

vue-easy-data-grid

Version:
6 lines 8.74 kB
/*! * vue.dataGrid.js * (c) 2017-2018 yuw * Released under the MIT License. */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["vue.dataGrid"]=t():e["vue.dataGrid"]=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(s){if(n[s])return n[s].exports;var l=n[s]={i:s,l:!1,exports:{}};return e[s].call(l.exports,l,l.exports,t),l.l=!0,l.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,s){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:s})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var s=n(1),l=n.n(s),o=function(e){e.component(l.a.name,l.a)};l.a.install=o,"undefined"!=typeof window&&window.Vue&&o(window.Vue),t.default=l.a},function(e,t,n){var s=n(3)(n(4),n(5),!1,function(e){n(2)},"data-v-299ba092",null);e.exports=s.exports},function(e,t){},function(e,t){e.exports=function(e,t,n,s,l,o){var i,a=e=e||{},c=typeof e.default;"object"!==c&&"function"!==c||(i=e,a=e.default);var r,u="function"==typeof a?a.options:a;if(t&&(u.render=t.render,u.staticRenderFns=t.staticRenderFns,u._compiled=!0),n&&(u.functional=!0),l&&(u._scopeId=l),o?(r=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),s&&s.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(o)},u._ssrRegister=r):s&&(r=s),r){var d=u.functional,f=d?u.render:u.beforeCreate;d?(u._injectStyles=r,u.render=function(e,t){return r.call(t),f(e,t)}):u.beforeCreate=f?[].concat(f,r):[r]}return{esModule:i,exports:a,options:u}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default={name:"vue-data-grid",props:{selection:{default:function(){return!1},type:Boolean},listData:{default:function(){return[]},type:Array},columns:{default:function(){return{}},type:Object},zebra:{default:function(){return!0},type:Boolean},hasOperation:{default:function(){return!1},type:Boolean},isKeyValue:{default:function(){return!0},type:Boolean},isLoading:{default:function(){return!1},type:Boolean}},data:function(){return{selectionVal:[]}},mounted:function(){if(this.columns)for(var e in this.columns)if(this.columns.hasOwnProperty(e)){var t=this.columns[e];t.sort&&void 0!==t.sort.type&&this.sort(t.sort.type,e)}},computed:{selectionAllVal:{get:function(){for(var e=0,t=0;t<this.selectionVal.length;t++)"undefined"!==this.selectionVal[t]&&this.selectionVal[t]&&e++;return e===this.listData.length},set:function(){if(this.selectionAllVal)this.selectionVal=[];else{this.selectionVal=[];for(var e=0;e<this.listData.length;e++)this.selectionVal.push(!0)}}}},watch:{selectionVal:function(e){this.$emit("on-selection-change",e)}},methods:{sort:function(e,t){void 0===this.columns[t].sort.type&&this.$set(this.columns[t].sort,"type",""),"up"===e?this.columns[t].sort.type="up":"down"===e&&(this.columns[t].sort.type="down"),this.columns[t].sort.custom&&"function"==typeof this.columns[t].sort.custom?this.columns[t].sort.custom(e,t):this.listData.sort(this.sortBy(t,"up"===e))},sortBy:function(e,t){return t=void 0==t?1:t?1:-1,function(n,s){return(n=n[e])<(s=s[e])?-1*t:n>s?1*t:0}},clearSelection:function(){this.selectionVal=[]},selectionAllChange:function(){if(this.selectionAllVal)this.selectionVal=[];else{this.selectionVal=[];for(var e=0;e<this.listData.length;e++)this.selectionVal.push(!0)}},formatter:function(e,t,n){return e.formatter&&"function"==typeof e.formatter?e.formatter(t):t[n]},click:function(e,t,n){return e.click?e.click(t):t[n]}}}},function(e,t){e.exports={render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"vue-table-wrap",class:e.isLoading?"loading":""},[n("table",{staticClass:"vue-table"},[n("thead",[e.isKeyValue?e._e():n("tr",[e.selection&&e.listData&&e.listData.length>0?n("th",[n("label",{staticClass:"checkbox-wrap"},[e._v("'\r\n "),n("input",{directives:[{name:"model",rawName:"v-model",value:e.selectionAllVal,expression:"selectionAllVal"}],staticClass:"checkbox-input",attrs:{type:"checkbox",id:"selectionAll"},domProps:{checked:Array.isArray(e.selectionAllVal)?e._i(e.selectionAllVal,null)>-1:e.selectionAllVal},on:{change:function(t){var n=e.selectionAllVal,s=t.target,l=!!s.checked;if(Array.isArray(n)){var o=e._i(n,null);s.checked?o<0&&(e.selectionAllVal=n.concat([null])):o>-1&&(e.selectionAllVal=n.slice(0,o).concat(n.slice(o+1)))}else e.selectionAllVal=l}}}),n("label",{staticClass:"checkbox-inner",attrs:{for:"selectionAll"}})])]):e._e(),e._l(e.columns,function(t){return n("th",{domProps:{textContent:e._s(t)}})}),e.hasOperation?n("th",[e._v("操作")]):e._e()],2),e.isKeyValue?n("tr",[e.selection&&e.listData&&e.listData.length>0?n("th",[n("label",{staticClass:"checkbox-wrap"},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.selectionAllVal,expression:"selectionAllVal"}],staticClass:"checkbox-input",attrs:{type:"checkbox",id:"selectionAll"},domProps:{checked:Array.isArray(e.selectionAllVal)?e._i(e.selectionAllVal,null)>-1:e.selectionAllVal},on:{change:function(t){var n=e.selectionAllVal,s=t.target,l=!!s.checked;if(Array.isArray(n)){var o=e._i(n,null);s.checked?o<0&&(e.selectionAllVal=n.concat([null])):o>-1&&(e.selectionAllVal=n.slice(0,o).concat(n.slice(o+1)))}else e.selectionAllVal=l}}}),n("label",{staticClass:"checkbox-inner",attrs:{for:"selectionAll"}})])]):e._e(),e._l(e.columns,function(t,s){return n("th",[n("span",{domProps:{textContent:e._s("object"==typeof t?t.name:t)}}),"object"==typeof t&&t.sort?n("div",{staticClass:"sort-wrap"},[n("span",{staticClass:"sort-up",class:"up"===t.sort.type?"on":"",on:{click:function(t){e.sort("up",s)}}},[n("i",{staticClass:"icon-sort-up"})]),n("span",{staticClass:"sort-down",class:"down"===t.sort.type?"on":"",on:{click:function(t){e.sort("down",s)}}},[n("i",{staticClass:"icon-sort-down"})])]):e._e()])}),e.hasOperation?n("th",[e._v("操作")]):e._e()],2):e._e()]),n("tbody",[e._l(e.listData,function(t,s){return e.isKeyValue?e._e():n("tr",{class:e.zebra&&s%2==1?"zebra-line":""},[e.selection?n("td",{staticStyle:{"min-width":"0px",width:"45px"}},[n("label",{staticClass:"checkbox-wrap"},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.selectionVal[s],expression:"selectionVal[index]"}],staticClass:"checkbox-input",attrs:{id:"selection_"+s,type:"checkbox"},domProps:{checked:Array.isArray(e.selectionVal[s])?e._i(e.selectionVal[s],null)>-1:e.selectionVal[s]},on:{change:function(t){var n=e.selectionVal[s],l=t.target,o=!!l.checked;if(Array.isArray(n)){var i=e._i(n,null);l.checked?i<0&&(e.selectionVal[s]=n.concat([null])):i>-1&&(e.selectionVal[s]=n.slice(0,i).concat(n.slice(i+1)))}else e.$set(e.selectionVal,s,o)}}}),n("label",{staticClass:"checkbox-inner",attrs:{for:"selection_"+s}})])]):e._e(),e._l(t,function(t,s){return n("td",{attrs:{"track-by":"$index"},domProps:{textContent:e._s(t)}})}),e.hasOperation?n("td"):e._e()],2)}),e._l(e.listData,function(t,s){return e.isKeyValue?n("tr",{class:e.zebra&&s%2==1?"zebra-line":""},[e.selection?n("td",{staticStyle:{"min-width":"0px",width:"45px"}},[n("label",{staticClass:"checkbox-wrap"},[n("input",{directives:[{name:"model",rawName:"v-model",value:e.selectionVal[s],expression:"selectionVal[index]"}],staticClass:"checkbox-input",attrs:{id:"selection_"+s,type:"checkbox"},domProps:{checked:Array.isArray(e.selectionVal[s])?e._i(e.selectionVal[s],null)>-1:e.selectionVal[s]},on:{change:function(t){var n=e.selectionVal[s],l=t.target,o=!!l.checked;if(Array.isArray(n)){var i=e._i(n,null);l.checked?i<0&&(e.selectionVal[s]=n.concat([null])):i>-1&&(e.selectionVal[s]=n.slice(0,i).concat(n.slice(i+1)))}else e.$set(e.selectionVal,s,o)}}}),n("label",{staticClass:"checkbox-inner",attrs:{for:"selection_"+s}})])]):e._e(),e._l(e.columns,function(l,o){return n("td",["object"==typeof l?n("span",{domProps:{innerHTML:e._s(e.formatter(l,e.listData[s],o))},on:{click:function(t){e.click(l,e.listData[s],o)}}}):e._e(),"object"!=typeof l?n("span",{domProps:{textContent:e._s(t[o])}}):e._e()])}),e.hasOperation?n("td",{staticClass:"options"},[e._t("default",null,{data:t,index:s})],2):e._e()],2):e._e()})],2)]),e.isLoading?n("div",{staticClass:"vue-table-loading "},[e._m(0)]):e._e()])},staticRenderFns:[function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"loadEffect"},[t("span"),t("span"),t("span"),t("span"),t("span"),t("span"),t("span"),t("span")])}]}}])});