@jobinsjp/vue3-datatable
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
var e=Object.defineProperty,t=Object.prototype.hasOwnProperty,a=Object.getOwnPropertySymbols,n=Object.prototype.propertyIsEnumerable,d=(t,a,n)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[a]=n,l=(e,l)=>{for(var r in l||(l={}))t.call(l,r)&&d(e,r,l[r]);if(a)for(var r of a(l))n.call(l,r)&&d(e,r,l[r]);return e};import{openBlock as r,createBlock as s,createVNode as o,defineComponent as i,pushScopeId as u,popScopeId as c,withScopeId as g,computed as p,mergeProps as b,toHandlers as v,renderSlot as f,resolveComponent as m,withDirectives as y,toDisplayString as h,vShow as P,withModifiers as x,withCtx as w,Fragment as C,createCommentVNode as k,renderList as _,createTextVNode as I,ref as q,watch as O}from"vue";const $={},L={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},S=o("path",{"fill-rule":"evenodd",d:"M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z","clip-rule":"evenodd"},null,-1);$.render=function(e,t){return r(),s("svg",L,[S])};var j=i({name:"Loading"});const B=g("data-v-f17dff8e");u("data-v-f17dff8e");const N={class:"spinner dt-absolute dt-h-full dt-w-full dt-flex dt-justify-center"},D=o("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1),F=o("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1);c();const Q=B(((e,t,a,n,d,l)=>(r(),s("div",N,[D,F]))));j.render=Q,j.__scopeId="data-v-f17dff8e";var T=i({name:"PaginationLink",props:{active:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1}},setup:e=>({linkClasses:p((()=>e.active?"dt-bg-gray-200 dt-border-gray-300 dt-text-gray-800 hover:dt-bg-gray-200":e.disabled?"dt-cursor-not-allowed dt-text-gray-400":"dt-border-gray-300 dt-bg-white dt-text-gray-500 hover:dt-bg-gray-50"))})});T.render=function(e,t,a,n,d,o){return r(),s("a",b({href:"#",class:["dt-relative dt-inline-flex dt-items-center dt-px-4 dt-py-2 dt-border dt-text-sm dt-font-medium",e.linkClasses]},v(l({},e.$attrs))),[f(e.$slots,"default")],16)};var M=i({name:"Pagination",components:{PaginationLink:T},props:{total:{type:Number,required:!0},perPage:{type:Number,required:!0},currentPage:{type:Number,required:!1,default:1},maxVisibleButtons:{type:Number,required:!1,default:5}},emits:["changed"],setup(e,{emit:t}){const a=p((()=>(e.currentPage-1)*e.perPage+1)),n=p((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),d=p((()=>Math.ceil(e.total/e.perPage))),l=p((()=>1===e.currentPage?1:e.currentPage===d.value?d.value-e.maxVisibleButtons+1:e.currentPage-1)),r=p((()=>Math.min(l.value+e.maxVisibleButtons-1,d.value))),s=p((()=>{const e=[];for(let t=l.value;t<=r.value;t+=1)t>0&&e.push(t);return e})),o=p((()=>1===e.currentPage)),i=p((()=>e.currentPage===d.value)),u=e=>{t("changed",e)};return{currentStart:a,currentEnd:n,totalPages:d,pages:s,isInFirstPage:o,isInLastPage:i,goToPageNumber:u,gotoFirstPage:()=>u(1),gotoLastPage:()=>u(d.value),gotoNextPage:()=>u(e.currentPage>=d.value?d.value:e.currentPage+1),gotoPreviousPage:()=>u(e.currentPage<=1?1:e.currentPage-1),showDots:(e="left")=>{const t="left"===e?1:d.value,a="left"===e?2:d.value-1;return!s.value.includes(t)||!s.value.includes(a)}}}});const E={key:0,class:"dt-bg-white dt-px-4 dt-py-3 dt-flex dt-items-center dt-justify-between dt-border-t dt-border-gray-200 sm:dt-px-6"},R={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},z={class:"dt-text-sm dt-text-gray-700"},A=I(" Showing "),V=I(" to "),G=I(" of "),H=I(" results. "),J={key:0},K={class:"dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"},U=o("span",{class:"dt-sr-only"},"Go to first",-1),W=I(" « "),X=o("span",{class:"dt-sr-only"},"Previous",-1),Y=I(" ‹ "),Z=I(" 1 "),ee=I(" ... "),te=I(" ... "),ae=o("span",{class:"dt-sr-only"},"Next",-1),ne=I(" › "),de=o("span",{class:"dt-sr-only"},"Go to Last",-1),le=I(" » ");M.render=function(e,t,a,n,d,l){const i=m("pagination-link");return e.totalPages?(r(),s("div",E,[o("div",R,[y(o("div",null,[o("p",z,[f(e.$slots,"pagination-info",{currentStart:e.currentStart,currentEnd:e.currentEnd,total:e.total},(()=>[A,o("span",{class:"dt-font-medium",textContent:h(e.currentStart)},null,8,["textContent"]),V,o("span",{class:"dt-font-medium",textContent:h(e.currentEnd)},null,8,["textContent"]),G,o("span",{class:"dt-font-medium",textContent:h(e.total)},null,8,["textContent"]),H]))])],512),[[P,e.total]]),e.totalPages>1?(r(),s("div",J,[o("nav",K,[o(i,{disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:x(e.gotoFirstPage,["prevent"])},{default:w((()=>[U,W])),_:1},8,["disabled","onClick"]),o(i,{disabled:e.isInFirstPage,onClick:x(e.gotoPreviousPage,["prevent"])},{default:w((()=>[X,Y])),_:1},8,["disabled","onClick"]),e.showDots("left")?(r(),s(C,{key:0},[o(i,{class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:x(e.gotoFirstPage,["prevent"])},{default:w((()=>[Z])),_:1},8,["disabled","active","onClick"]),o(i,{class:"sm:dt-hidden"},{default:w((()=>[ee])),_:1})],64)):k("",!0),(r(!0),s(C,null,_(e.pages,((t,a)=>(r(),s(i,{key:`pages_${a}`,class:"dt-hidden md:dt-inline-block",active:t===e.currentPage,disabled:t===e.currentPage,onClick:x((a=>e.goToPageNumber(t)),["prevent"])},{default:w((()=>[I(h(t),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(r(),s(C,{key:1},[o(i,{class:"sm:dt-hidden"},{default:w((()=>[te])),_:1}),o(i,{class:"sm:dt-hidden",disabled:e.isInLastPage,active:e.isInLastPage,onClick:x(e.gotoLastPage,["prevent"])},{default:w((()=>[I(h(e.totalPages),1)])),_:1},8,["disabled","active","onClick"])],64)):k("",!0),o(i,{disabled:e.isInLastPage,onClick:x(e.gotoNextPage,["prevent"])},{default:w((()=>[ae,ne])),_:1},8,["disabled","onClick"]),o(i,{disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:x(e.gotoLastPage,["prevent"])},{default:w((()=>[de,le])),_:1},8,["disabled","onClick"])])])):k("",!0)])])):k("",!0)};const re={},se={class:"dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};re.render=function(e,t){return r(),s("td",se,[f(e.$slots,"default")])};const oe={},ie={scope:"col",class:"dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};oe.render=function(e,t){return r(),s("th",ie,[f(e.$slots,"default")])};const ue=[5,10,15,25,50,75,100],ce=i({components:{SearchIcon:$,Loading:j,Pagination:M,TableBody:re,TableHead:oe},props:{rows:{type:Array,required:!0},columns:{type:Object,required:!1,default:null},pagination:{type:Object,required:!1,default:null},striped:{type:Boolean,required:!1,default:!1},sn:{type:Boolean,required:!1,default:!1},filter:{type:Boolean,required:!1,default:!1},loading:{type:Boolean,required:!1,default:!1},perPageOptions:{type:Array,required:!1,default:()=>ue},query:{type:Object,required:!1,default:()=>({})}},emits:["loadData"],setup(e,{emit:t}){var a,n;const d=q({page:(null==(a=e.pagination)?void 0:a.page)||1,search:e.query.search||"",per_page:(null==(n=e.pagination)?void 0:n.per_page)||10}),r=p((()=>!!e.pagination)),s=p((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),o=p((()=>e.rows)),i=p((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>l(l({},e),{[t]:t})),{}))),u=p((()=>r.value?d.value.per_page*(d.value.page-1):0));O((()=>l({},d.value)),(()=>{t("loadData",d.value)}),{deep:!0,immediate:!0});const c=((e,t=400)=>{let a;return(...n)=>{clearTimeout(a),a=setTimeout((()=>e(...n)),t)}})((e=>{d.value=l(l({},d.value),{page:1,search:e.target.value})}));return{tableQuery:d,showPagination:r,totalData:s,tableRows:o,tableColumns:i,paginatedRowIndex:u,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{d.value.page=e},handleOnSearchChange:c,handleOnChange:e=>{const{name:t,value:a}=e.target;d.value=l(l({},d.value),{page:1,[t]:a})}}}});const ge=g("data-v-0bb37481");u("data-v-0bb37481");const pe={class:"data-table dt-flex dt-flex-col"},be={class:"dt-align-middle dt-min-w-full"},ve={key:0,class:"dt-filter-wrapper dt-mb-3 dt-w-full"},fe={class:"dt-w-64"},me=o("label",{for:"email",class:"dt-sr-only"},"Search",-1),ye={class:"dt-relative dt-rounded-md dt-shadow-sm"},he={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"},Pe={class:"table-wrapper dt-relative dt-shadow dt-overflow-hidden dt-border-b dt-border-gray-200 sm:dt-rounded-lg"},xe={key:1,class:"pagination-wrapper md:dt-flex smdt-flex-col dt-bg-white dt-items-center"},we={class:"dt-pr-4 dt-w-full dt-pb-3 dt-flex dt-justify-end sm:dt-pr-6 sm:dt-pb-0 sm:dt-w-auto"},Ce={class:""},ke=o("label",{for:"location",class:"dt-sr-only"},"Per page",-1),_e={class:"table-container dt-overflow-auto"},Ie={class:"dt-min-w-full dt-divide-y dt-divide-gray-200"},qe={class:"dt-bg-gray-50"},Oe={key:2,class:"pagination-wrapper"};c();const $e=ge(((e,t,a,n,d,l)=>{const i=m("search-icon"),u=m("Loading"),c=m("pagination"),g=m("table-head"),p=m("table-body");return r(),s("div",pe,[o("div",be,[e.filter?(r(),s("div",ve,[o("div",fe,[me,o("div",ye,[o("input",{value:e.tableQuery.search,type:"search",name:"search",class:"focus:dt-ring-0 dt-block dt-w-full dt-pr-10 sm:dt-text-sm dt-border-gray-300 dt-rounded-md",onInput:t[1]||(t[1]=(...t)=>e.handleOnSearchChange&&e.handleOnSearchChange(...t))},null,40,["value"]),o("div",he,[o(i,{class:"dt-text-gray-400"})])])])])):k("",!0),o("div",Pe,[e.loading?f(e.$slots,"loading",{key:0},(()=>[o(u)]),{},!0):k("",!0),e.showPagination?(r(),s("div",xe,[o(c,{class:"dt-flex-1",total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"]),o("div",we,[o("div",Ce,[ke,o("select",{value:e.tableQuery.per_page,name:"per_page",class:"dt-block dt-w-full dt-pl-3 dt-pr-10 dt-py-2 dt-text-base dt-border-gray-300 sm:dt-text-sm dt-rounded-md",onInput:t[2]||(t[2]=(...t)=>e.handleOnChange&&e.handleOnChange(...t))},[(r(!0),s(C,null,_(e.perPageOptions,(t=>(r(),s("option",{key:`per_page_${t}`,value:t,selected:t===e.tableQuery.per_page,textContent:h(t)},null,8,["value","selected","textContent"])))),128))],40,["value"])])])])):k("",!0),o("div",_e,[o("table",Ie,[o("thead",qe,[o("tr",null,[e.sn?f(e.$slots,"thead-sn",{key:0},(()=>[o(g,{textContent:h("S.N.")},null,8,["textContent"])]),{},!0):k("",!0),f(e.$slots,"thead",{column:e.tableColumns},(()=>[(r(!0),s(C,null,_(e.tableColumns,((e,t)=>(r(),s(g,{key:`datatable-thead-th-${t}`,textContent:h(e)},null,8,["textContent"])))),128))]),!0)])]),o("tbody",null,[(r(!0),s(C,null,_(e.tableRows,((t,a)=>(r(),s("tr",{key:`datatable-tbody-${e.uniqueId()}-${a}`,class:e.striped&&a%2?"dt-bg-gray-50":"dt-bg-white"},[e.sn?f(e.$slots,"tbody-sn",{key:0,sn:a+1},(()=>[o(p,{textContent:h(a+1+e.paginatedRowIndex)},null,8,["textContent"])]),!0):k("",!0),f(e.$slots,"tbody",{index:a,row:t},(()=>[(r(!0),s(C,null,_(e.tableColumns,((a,n)=>(r(),s(p,{key:`datatable-tbody-td-${e.uniqueId()}-${n}`,name:a,textContent:h(t[n])},null,8,["name","textContent"])))),128))]),!0)],2)))),128))])])]),e.showPagination?(r(),s("div",Oe,[o(c,{total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"])])):k("",!0)])])])}));ce.render=$e,ce.__scopeId="data-v-0bb37481";export{ce as DataTable,re as TableBody,oe as TableHead}; | ||
var e=Object.defineProperty,t=Object.prototype.hasOwnProperty,a=Object.getOwnPropertySymbols,n=Object.prototype.propertyIsEnumerable,d=(t,a,n)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[a]=n,l=(e,l)=>{for(var r in l||(l={}))t.call(l,r)&&d(e,r,l[r]);if(a)for(var r of a(l))n.call(l,r)&&d(e,r,l[r]);return e};import{openBlock as r,createBlock as s,createVNode as o,defineComponent as i,pushScopeId as u,popScopeId as c,withScopeId as g,computed as p,mergeProps as b,toHandlers as v,renderSlot as f,resolveComponent as m,withDirectives as y,toDisplayString as h,vShow as P,withModifiers as x,withCtx as w,Fragment as C,createCommentVNode as k,renderList as _,createTextVNode as I,ref as q,watch as O}from"vue";const $={},L={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},S=o("path",{"fill-rule":"evenodd",d:"M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z","clip-rule":"evenodd"},null,-1);$.render=function(e,t){return r(),s("svg",L,[S])};var j=i({name:"Loading"});const B=g("data-v-f17dff8e");u("data-v-f17dff8e");const N={class:"spinner dt-absolute dt-h-full dt-w-full dt-flex dt-justify-center"},D=o("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1),F=o("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1);c();const Q=B(((e,t,a,n,d,l)=>(r(),s("div",N,[D,F]))));j.render=Q,j.__scopeId="data-v-f17dff8e";var T=i({name:"PaginationLink",props:{active:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1}},setup:e=>({linkClasses:p((()=>e.active?"dt-bg-gray-200 dt-border-gray-300 dt-text-gray-800 hover:dt-bg-gray-200":e.disabled?"dt-cursor-not-allowed dt-text-gray-400":"dt-border-gray-300 dt-bg-white dt-text-gray-500 hover:dt-bg-gray-50"))})});T.render=function(e,t,a,n,d,o){return r(),s("a",b({href:"#",class:["dt-relative dt-inline-flex dt-items-center dt-px-4 dt-py-2 dt-border dt-text-sm dt-font-medium",e.linkClasses]},v(l({},e.$attrs))),[f(e.$slots,"default")],16)};var M=i({name:"Pagination",components:{PaginationLink:T},props:{total:{type:Number,required:!0},perPage:{type:Number,required:!0},currentPage:{type:Number,required:!1,default:1},maxVisibleButtons:{type:Number,required:!1,default:5}},emits:["changed"],setup(e,{emit:t}){const a=p((()=>(e.currentPage-1)*e.perPage+1)),n=p((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),d=p((()=>Math.ceil(e.total/e.perPage))),l=p((()=>1===e.currentPage?1:e.currentPage===d.value?d.value-e.maxVisibleButtons+1:e.currentPage-1)),r=p((()=>Math.min(l.value+e.maxVisibleButtons-1,d.value))),s=p((()=>{const e=[];for(let t=l.value;t<=r.value;t+=1)t>0&&e.push(t);return e})),o=p((()=>1===e.currentPage)),i=p((()=>e.currentPage===d.value)),u=e=>{t("changed",e)};return{currentStart:a,currentEnd:n,totalPages:d,pages:s,isInFirstPage:o,isInLastPage:i,goToPageNumber:u,gotoFirstPage:()=>u(1),gotoLastPage:()=>u(d.value),gotoNextPage:()=>u(e.currentPage>=d.value?d.value:e.currentPage+1),gotoPreviousPage:()=>u(e.currentPage<=1?1:e.currentPage-1),showDots:(e="left")=>{const t="left"===e?1:d.value,a="left"===e?2:d.value-1;return!s.value.includes(t)||!s.value.includes(a)}}}});const E={key:0,class:"dt-bg-white dt-px-4 dt-py-3 dt-flex dt-items-center dt-justify-between dt-border-t dt-border-gray-200 sm:dt-px-6"},R={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},z={class:"dt-text-sm dt-text-gray-700"},A=I(" Showing "),V=I(" to "),G=I(" of "),H=I(" results. "),J={key:0},K={class:"dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"},U=o("span",{class:"dt-sr-only"},"Go to first",-1),W=I(" « "),X=o("span",{class:"dt-sr-only"},"Previous",-1),Y=I(" ‹ "),Z=I(" 1 "),ee=I(" ... "),te=I(" ... "),ae=o("span",{class:"dt-sr-only"},"Next",-1),ne=I(" › "),de=o("span",{class:"dt-sr-only"},"Go to Last",-1),le=I(" » ");M.render=function(e,t,a,n,d,l){const i=m("pagination-link");return e.totalPages?(r(),s("div",E,[o("div",R,[y(o("div",null,[o("p",z,[f(e.$slots,"pagination-info",{currentStart:e.currentStart,currentEnd:e.currentEnd,total:e.total},(()=>[A,o("span",{class:"dt-font-medium",textContent:h(e.currentStart)},null,8,["textContent"]),V,o("span",{class:"dt-font-medium",textContent:h(e.currentEnd)},null,8,["textContent"]),G,o("span",{class:"dt-font-medium",textContent:h(e.total)},null,8,["textContent"]),H]))])],512),[[P,e.total]]),e.totalPages>1?(r(),s("div",J,[o("nav",K,[o(i,{disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:x(e.gotoFirstPage,["prevent"])},{default:w((()=>[U,W])),_:1},8,["disabled","onClick"]),o(i,{disabled:e.isInFirstPage,onClick:x(e.gotoPreviousPage,["prevent"])},{default:w((()=>[X,Y])),_:1},8,["disabled","onClick"]),e.showDots("left")?(r(),s(C,{key:0},[o(i,{class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:x(e.gotoFirstPage,["prevent"])},{default:w((()=>[Z])),_:1},8,["disabled","active","onClick"]),o(i,{class:"sm:dt-hidden"},{default:w((()=>[ee])),_:1})],64)):k("",!0),(r(!0),s(C,null,_(e.pages,((t,a)=>(r(),s(i,{key:`pages_${a}`,class:"dt-hidden md:dt-inline-block",active:t===e.currentPage,disabled:t===e.currentPage,onClick:x((a=>e.goToPageNumber(t)),["prevent"])},{default:w((()=>[I(h(t),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(r(),s(C,{key:1},[o(i,{class:"sm:dt-hidden"},{default:w((()=>[te])),_:1}),o(i,{class:"sm:dt-hidden",disabled:e.isInLastPage,active:e.isInLastPage,onClick:x(e.gotoLastPage,["prevent"])},{default:w((()=>[I(h(e.totalPages),1)])),_:1},8,["disabled","active","onClick"])],64)):k("",!0),o(i,{disabled:e.isInLastPage,onClick:x(e.gotoNextPage,["prevent"])},{default:w((()=>[ae,ne])),_:1},8,["disabled","onClick"]),o(i,{disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:x(e.gotoLastPage,["prevent"])},{default:w((()=>[de,le])),_:1},8,["disabled","onClick"])])])):k("",!0)])])):k("",!0)};const re={},se={class:"dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};re.render=function(e,t){return r(),s("td",se,[f(e.$slots,"default")])};const oe={},ie={scope:"col",class:"dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};oe.render=function(e,t){return r(),s("th",ie,[f(e.$slots,"default")])};const ue=[5,10,15,25,50,75,100],ce=i({components:{SearchIcon:$,Loading:j,Pagination:M,TableBody:re,TableHead:oe},props:{rows:{type:Array,required:!0},columns:{type:Object,required:!1,default:null},pagination:{type:Object,required:!1,default:null},striped:{type:Boolean,required:!1,default:!1},sn:{type:Boolean,required:!1,default:!1},filter:{type:Boolean,required:!1,default:!1},loading:{type:Boolean,required:!1,default:!1},perPageOptions:{type:Array,required:!1,default:()=>ue},query:{type:Object,required:!1,default:()=>({})}},emits:["loadData"],setup(e,{emit:t}){var a,n;const d=q({page:(null==(a=e.pagination)?void 0:a.page)||1,search:e.query.search||"",per_page:(null==(n=e.pagination)?void 0:n.per_page)||10}),r=p((()=>!!e.pagination)),s=p((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),o=p((()=>e.rows)),i=p((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>l(l({},e),{[t]:t})),{}))),u=p((()=>r.value?d.value.per_page*(d.value.page-1):0));O((()=>l({},d.value)),(()=>{t("loadData",d.value)}),{deep:!0,immediate:!0});const c=((e,t=400)=>{let a;return(...n)=>{clearTimeout(a),a=setTimeout((()=>e(...n)),t)}})((e=>{d.value=l(l({},d.value),{page:1,search:e.target.value})}));return{tableQuery:d,showPagination:r,totalData:s,tableRows:o,tableColumns:i,paginatedRowIndex:u,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{d.value.page=e},handleOnSearchChange:c,handleOnChange:e=>{const{name:t,value:a}=e.target;d.value=l(l({},d.value),{page:1,[t]:a})}}}});const ge=g("data-v-0bb37481");u("data-v-0bb37481");const pe={class:"data-table dt-flex dt-flex-col"},be={class:"dt-align-middle dt-min-w-full"},ve={key:0,class:"dt-filter-wrapper dt-mb-3 dt-w-full"},fe={class:"dt-w-64"},me=o("label",{for:"email",class:"dt-sr-only"},"Search",-1),ye={class:"dt-relative dt-rounded-md dt-shadow-sm"},he={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"},Pe={class:"table-wrapper dt-relative dt-shadow dt-overflow-hidden dt-border-b dt-border-gray-200 sm:dt-rounded-lg"},xe={key:1,class:"pagination-wrapper md:dt-flex smdt-flex-col dt-bg-white dt-items-center"},we={class:"dt-pr-4 dt-w-full dt-pb-3 dt-flex dt-justify-end sm:dt-pr-6 sm:dt-pb-0 sm:dt-w-auto"},Ce={class:""},ke=o("label",{for:"location",class:"dt-sr-only"},"Per page",-1),_e={class:"table-container dt-overflow-auto"},Ie={class:"dt-min-w-full dt-divide-y dt-divide-gray-200"},qe={class:"dt-bg-gray-50"},Oe={key:2,class:"pagination-wrapper"};c();const $e=ge(((e,t,a,n,d,l)=>{const i=m("search-icon"),u=m("Loading"),c=m("pagination"),g=m("table-head"),p=m("table-body");return r(),s("div",pe,[o("div",be,[e.filter?(r(),s("div",ve,[o("div",fe,[me,o("div",ye,[o("input",{value:e.tableQuery.search,type:"search",name:"search",class:"focus:dt-ring-0 dt-block dt-w-full dt-pr-10 sm:dt-text-sm dt-border-gray-300 dt-rounded-md",onInput:t[1]||(t[1]=(...t)=>e.handleOnSearchChange&&e.handleOnSearchChange(...t))},null,40,["value"]),o("div",he,[o(i,{class:"dt-text-gray-400"})])])])])):k("",!0),o("div",Pe,[e.loading?f(e.$slots,"loading",{key:0},(()=>[o(u)]),{},!0):k("",!0),e.showPagination?(r(),s("div",xe,[o(c,{class:"dt-flex-1",total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"]),o("div",we,[o("div",Ce,[ke,o("select",{value:e.tableQuery.per_page,name:"per_page",class:"dt-block dt-w-full dt-pl-3 dt-pr-10 dt-py-2 dt-text-base dt-border-gray-300 sm:dt-text-sm dt-rounded-md",onInput:t[2]||(t[2]=(...t)=>e.handleOnChange&&e.handleOnChange(...t))},[(r(!0),s(C,null,_(e.perPageOptions,(t=>(r(),s("option",{key:`per_page_${t}`,value:t,selected:t===e.tableQuery.per_page,textContent:h(t)},null,8,["value","selected","textContent"])))),128))],40,["value"])])])])):k("",!0),o("div",_e,[o("table",Ie,[o("thead",qe,[o("tr",null,[e.sn?f(e.$slots,"thead-sn",{key:0},(()=>[o(g,{textContent:h("S.N.")},null,8,["textContent"])]),{},!0):k("",!0),f(e.$slots,"thead",{column:e.tableColumns},(()=>[(r(!0),s(C,null,_(e.tableColumns,((e,t)=>(r(),s(g,{key:`datatable-thead-th-${t}`,textContent:h(e)},null,8,["textContent"])))),128))]),!0)])]),o("tbody",null,[(r(!0),s(C,null,_(e.tableRows,((t,a)=>(r(),s("tr",{key:`datatable-tbody-${e.uniqueId()}-${a}`,class:e.striped&&a%2?"dt-bg-gray-50":"dt-bg-white"},[e.sn?f(e.$slots,"tbody-sn",{key:0,sn:a+1},(()=>[o(p,{textContent:h(a+1+e.paginatedRowIndex)},null,8,["textContent"])]),!0):k("",!0),f(e.$slots,"tbody",{index:a,row:t},(()=>[(r(!0),s(C,null,_(e.tableColumns,((a,n)=>(r(),s(p,{key:`datatable-tbody-td-${e.uniqueId()}-${n}`,name:a,textContent:h(t[n])},null,8,["name","textContent"])))),128))]),!0)],2)))),128))])])]),e.showPagination?(r(),s("div",Oe,[o(c,{total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"])])):k("",!0)])])])}));ce.render=$e,ce.__scopeId="data-v-0bb37481";export{ce as DataTable,M as Pagination,T as PaginationLink,re as TableBody,oe as TableHead}; |
@@ -1,1 +0,1 @@ | ||
var __defProp=Object.defineProperty,__hasOwnProp=Object.prototype.hasOwnProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__assign=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e};!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@jobinsjp/vue3-datatable"]={},e.Vue)}(this,(function(e,t){"use strict";const a={},o={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},r=t.createVNode("path",{"fill-rule":"evenodd",d:"M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z","clip-rule":"evenodd"},null,-1);a.render=function(e,a){return t.openBlock(),t.createBlock("svg",o,[r])};var d=t.defineComponent({name:"Loading"});const n=t.withScopeId("data-v-f17dff8e");t.pushScopeId("data-v-f17dff8e");const l={class:"spinner dt-absolute dt-h-full dt-w-full dt-flex dt-justify-center"},s=t.createVNode("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1),c=t.createVNode("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1);t.popScopeId();const i=n(((e,a,o,r,d,n)=>(t.openBlock(),t.createBlock("div",l,[s,c]))));d.render=i,d.__scopeId="data-v-f17dff8e";var u=t.defineComponent({name:"PaginationLink",props:{active:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1}},setup:e=>({linkClasses:t.computed((()=>e.active?"dt-bg-gray-200 dt-border-gray-300 dt-text-gray-800 hover:dt-bg-gray-200":e.disabled?"dt-cursor-not-allowed dt-text-gray-400":"dt-border-gray-300 dt-bg-white dt-text-gray-500 hover:dt-bg-gray-50"))})});u.render=function(e,a,o,r,d,n){return t.openBlock(),t.createBlock("a",t.mergeProps({href:"#",class:["dt-relative dt-inline-flex dt-items-center dt-px-4 dt-py-2 dt-border dt-text-sm dt-font-medium",e.linkClasses]},t.toHandlers(__assign({},e.$attrs))),[t.renderSlot(e.$slots,"default")],16)};const p="left";var g=t.defineComponent({name:"Pagination",components:{PaginationLink:u},props:{total:{type:Number,required:!0},perPage:{type:Number,required:!0},currentPage:{type:Number,required:!1,default:1},maxVisibleButtons:{type:Number,required:!1,default:5}},emits:["changed"],setup(e,{emit:a}){const o=t.computed((()=>(e.currentPage-1)*e.perPage+1)),r=t.computed((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),d=t.computed((()=>Math.ceil(e.total/e.perPage))),n=t.computed((()=>1===e.currentPage?1:e.currentPage===d.value?d.value-e.maxVisibleButtons+1:e.currentPage-1)),l=t.computed((()=>Math.min(n.value+e.maxVisibleButtons-1,d.value))),s=t.computed((()=>{const e=[];for(let t=n.value;t<=l.value;t+=1)t>0&&e.push(t);return e})),c=t.computed((()=>1===e.currentPage)),i=t.computed((()=>e.currentPage===d.value)),u=e=>{a("changed",e)};return{currentStart:o,currentEnd:r,totalPages:d,pages:s,isInFirstPage:c,isInLastPage:i,goToPageNumber:u,gotoFirstPage:()=>u(1),gotoLastPage:()=>u(d.value),gotoNextPage:()=>u(e.currentPage>=d.value?d.value:e.currentPage+1),gotoPreviousPage:()=>u(e.currentPage<=1?1:e.currentPage-1),showDots:(e=p)=>{const t=e===p?1:d.value,a=e===p?2:d.value-1;return!s.value.includes(t)||!s.value.includes(a)}}}});const m={key:0,class:"dt-bg-white dt-px-4 dt-py-3 dt-flex dt-items-center dt-justify-between dt-border-t dt-border-gray-200 sm:dt-px-6"},f={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},b={class:"dt-text-sm dt-text-gray-700"},v=t.createTextVNode(" Showing "),y=t.createTextVNode(" to "),h=t.createTextVNode(" of "),x=t.createTextVNode(" results. "),k={key:0},w={class:"dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"},N=t.createVNode("span",{class:"dt-sr-only"},"Go to first",-1),C=t.createTextVNode(" « "),P=t.createVNode("span",{class:"dt-sr-only"},"Previous",-1),V=t.createTextVNode(" ‹ "),_=t.createTextVNode(" 1 "),B=t.createTextVNode(" ... "),S=t.createTextVNode(" ... "),I=t.createVNode("span",{class:"dt-sr-only"},"Next",-1),T=t.createTextVNode(" › "),O=t.createVNode("span",{class:"dt-sr-only"},"Go to Last",-1),q=t.createTextVNode(" » ");g.render=function(e,a,o,r,d,n){const l=t.resolveComponent("pagination-link");return e.totalPages?(t.openBlock(),t.createBlock("div",m,[t.createVNode("div",f,[t.withDirectives(t.createVNode("div",null,[t.createVNode("p",b,[t.renderSlot(e.$slots,"pagination-info",{currentStart:e.currentStart,currentEnd:e.currentEnd,total:e.total},(()=>[v,t.createVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentStart)},null,8,["textContent"]),y,t.createVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentEnd)},null,8,["textContent"]),h,t.createVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.total)},null,8,["textContent"]),x]))])],512),[[t.vShow,e.total]]),e.totalPages>1?(t.openBlock(),t.createBlock("div",k,[t.createVNode("nav",w,[t.createVNode(l,{disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[N,C])),_:1},8,["disabled","onClick"]),t.createVNode(l,{disabled:e.isInFirstPage,onClick:t.withModifiers(e.gotoPreviousPage,["prevent"])},{default:t.withCtx((()=>[P,V])),_:1},8,["disabled","onClick"]),e.showDots("left")?(t.openBlock(),t.createBlock(t.Fragment,{key:0},[t.createVNode(l,{class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[_])),_:1},8,["disabled","active","onClick"]),t.createVNode(l,{class:"sm:dt-hidden"},{default:t.withCtx((()=>[B])),_:1})],64)):t.createCommentVNode("",!0),(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.pages,((a,o)=>(t.openBlock(),t.createBlock(l,{key:`pages_${o}`,class:"dt-hidden md:dt-inline-block",active:a===e.currentPage,disabled:a===e.currentPage,onClick:t.withModifiers((t=>e.goToPageNumber(a)),["prevent"])},{default:t.withCtx((()=>[t.createTextVNode(t.toDisplayString(a),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(t.openBlock(),t.createBlock(t.Fragment,{key:1},[t.createVNode(l,{class:"sm:dt-hidden"},{default:t.withCtx((()=>[S])),_:1}),t.createVNode(l,{class:"sm:dt-hidden",disabled:e.isInLastPage,active:e.isInLastPage,onClick:t.withModifiers(e.gotoLastPage,["prevent"])},{default:t.withCtx((()=>[t.createTextVNode(t.toDisplayString(e.totalPages),1)])),_:1},8,["disabled","active","onClick"])],64)):t.createCommentVNode("",!0),t.createVNode(l,{disabled:e.isInLastPage,onClick:t.withModifiers(e.gotoNextPage,["prevent"])},{default:t.withCtx((()=>[I,T])),_:1},8,["disabled","onClick"]),t.createVNode(l,{disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:t.withModifiers(e.gotoLastPage,["prevent"])},{default:t.withCtx((()=>[O,q])),_:1},8,["disabled","onClick"])])])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)};const D={},L={class:"dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};D.render=function(e,a){return t.openBlock(),t.createBlock("td",L,[t.renderSlot(e.$slots,"default")])};const $={},j={scope:"col",class:"dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};$.render=function(e,a){return t.openBlock(),t.createBlock("th",j,[t.renderSlot(e.$slots,"default")])};const F=[5,10,15,25,50,75,100],M=t.defineComponent({components:{SearchIcon:a,Loading:d,Pagination:g,TableBody:D,TableHead:$},props:{rows:{type:Array,required:!0},columns:{type:Object,required:!1,default:null},pagination:{type:Object,required:!1,default:null},striped:{type:Boolean,required:!1,default:!1},sn:{type:Boolean,required:!1,default:!1},filter:{type:Boolean,required:!1,default:!1},loading:{type:Boolean,required:!1,default:!1},perPageOptions:{type:Array,required:!1,default:()=>F},query:{type:Object,required:!1,default:()=>({})}},emits:["loadData"],setup(e,{emit:a}){var o,r;const d=t.ref({page:(null==(o=e.pagination)?void 0:o.page)||1,search:e.query.search||"",per_page:(null==(r=e.pagination)?void 0:r.per_page)||10}),n=t.computed((()=>!!e.pagination)),l=t.computed((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),s=t.computed((()=>e.rows)),c=t.computed((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>__assign(__assign({},e),{[t]:t})),{}))),i=t.computed((()=>n.value?d.value.per_page*(d.value.page-1):0));t.watch((()=>__assign({},d.value)),(()=>{a("loadData",d.value)}),{deep:!0,immediate:!0});const u=((e,t=400)=>{let a;return(...o)=>{clearTimeout(a),a=setTimeout((()=>e(...o)),t)}})((e=>{d.value=__assign(__assign({},d.value),{page:1,search:e.target.value})}));return{tableQuery:d,showPagination:n,totalData:l,tableRows:s,tableColumns:c,paginatedRowIndex:i,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{d.value.page=e},handleOnSearchChange:u,handleOnChange:e=>{const{name:t,value:a}=e.target;d.value=__assign(__assign({},d.value),{page:1,[t]:a})}}}});const Q=t.withScopeId("data-v-0bb37481");t.pushScopeId("data-v-0bb37481");const E={class:"data-table dt-flex dt-flex-col"},R={class:"dt-align-middle dt-min-w-full"},z={key:0,class:"dt-filter-wrapper dt-mb-3 dt-w-full"},A={class:"dt-w-64"},H=t.createVNode("label",{for:"email",class:"dt-sr-only"},"Search",-1),G={class:"dt-relative dt-rounded-md dt-shadow-sm"},J={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"},K={class:"table-wrapper dt-relative dt-shadow dt-overflow-hidden dt-border-b dt-border-gray-200 sm:dt-rounded-lg"},U={key:1,class:"pagination-wrapper md:dt-flex smdt-flex-col dt-bg-white dt-items-center"},W={class:"dt-pr-4 dt-w-full dt-pb-3 dt-flex dt-justify-end sm:dt-pr-6 sm:dt-pb-0 sm:dt-w-auto"},X={class:""},Y=t.createVNode("label",{for:"location",class:"dt-sr-only"},"Per page",-1),Z={class:"table-container dt-overflow-auto"},ee={class:"dt-min-w-full dt-divide-y dt-divide-gray-200"},te={class:"dt-bg-gray-50"},ae={key:2,class:"pagination-wrapper"};t.popScopeId();const oe=Q(((e,a,o,r,d,n)=>{const l=t.resolveComponent("search-icon"),s=t.resolveComponent("Loading"),c=t.resolveComponent("pagination"),i=t.resolveComponent("table-head"),u=t.resolveComponent("table-body");return t.openBlock(),t.createBlock("div",E,[t.createVNode("div",R,[e.filter?(t.openBlock(),t.createBlock("div",z,[t.createVNode("div",A,[H,t.createVNode("div",G,[t.createVNode("input",{value:e.tableQuery.search,type:"search",name:"search",class:"focus:dt-ring-0 dt-block dt-w-full dt-pr-10 sm:dt-text-sm dt-border-gray-300 dt-rounded-md",onInput:a[1]||(a[1]=(...t)=>e.handleOnSearchChange&&e.handleOnSearchChange(...t))},null,40,["value"]),t.createVNode("div",J,[t.createVNode(l,{class:"dt-text-gray-400"})])])])])):t.createCommentVNode("",!0),t.createVNode("div",K,[e.loading?t.renderSlot(e.$slots,"loading",{key:0},(()=>[t.createVNode(s)]),{},!0):t.createCommentVNode("",!0),e.showPagination?(t.openBlock(),t.createBlock("div",U,[t.createVNode(c,{class:"dt-flex-1",total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"]),t.createVNode("div",W,[t.createVNode("div",X,[Y,t.createVNode("select",{value:e.tableQuery.per_page,name:"per_page",class:"dt-block dt-w-full dt-pl-3 dt-pr-10 dt-py-2 dt-text-base dt-border-gray-300 sm:dt-text-sm dt-rounded-md",onInput:a[2]||(a[2]=(...t)=>e.handleOnChange&&e.handleOnChange(...t))},[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.perPageOptions,(a=>(t.openBlock(),t.createBlock("option",{key:`per_page_${a}`,value:a,selected:a===e.tableQuery.per_page,textContent:t.toDisplayString(a)},null,8,["value","selected","textContent"])))),128))],40,["value"])])])])):t.createCommentVNode("",!0),t.createVNode("div",Z,[t.createVNode("table",ee,[t.createVNode("thead",te,[t.createVNode("tr",null,[e.sn?t.renderSlot(e.$slots,"thead-sn",{key:0},(()=>[t.createVNode(i,{textContent:t.toDisplayString("S.N.")},null,8,["textContent"])]),{},!0):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"thead",{column:e.tableColumns},(()=>[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.tableColumns,((e,a)=>(t.openBlock(),t.createBlock(i,{key:`datatable-thead-th-${a}`,textContent:t.toDisplayString(e)},null,8,["textContent"])))),128))]),!0)])]),t.createVNode("tbody",null,[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.tableRows,((a,o)=>(t.openBlock(),t.createBlock("tr",{key:`datatable-tbody-${e.uniqueId()}-${o}`,class:e.striped&&o%2?"dt-bg-gray-50":"dt-bg-white"},[e.sn?t.renderSlot(e.$slots,"tbody-sn",{key:0,sn:o+1},(()=>[t.createVNode(u,{textContent:t.toDisplayString(o+1+e.paginatedRowIndex)},null,8,["textContent"])]),!0):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"tbody",{index:o,row:a},(()=>[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.tableColumns,((o,r)=>(t.openBlock(),t.createBlock(u,{key:`datatable-tbody-td-${e.uniqueId()}-${r}`,name:o,textContent:t.toDisplayString(a[r])},null,8,["name","textContent"])))),128))]),!0)],2)))),128))])])]),e.showPagination?(t.openBlock(),t.createBlock("div",ae,[t.createVNode(c,{total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"])])):t.createCommentVNode("",!0)])])])}));M.render=oe,M.__scopeId="data-v-0bb37481",e.DataTable=M,e.TableBody=D,e.TableHead=$,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); | ||
var __defProp=Object.defineProperty,__hasOwnProp=Object.prototype.hasOwnProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__assign=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e};!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@jobinsjp/vue3-datatable"]={},e.Vue)}(this,(function(e,t){"use strict";const a={},o={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},r=t.createVNode("path",{"fill-rule":"evenodd",d:"M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z","clip-rule":"evenodd"},null,-1);a.render=function(e,a){return t.openBlock(),t.createBlock("svg",o,[r])};var d=t.defineComponent({name:"Loading"});const n=t.withScopeId("data-v-f17dff8e");t.pushScopeId("data-v-f17dff8e");const l={class:"spinner dt-absolute dt-h-full dt-w-full dt-flex dt-justify-center"},s=t.createVNode("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1),i=t.createVNode("div",{class:"spinner-item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"},null,-1);t.popScopeId();const c=n(((e,a,o,r,d,n)=>(t.openBlock(),t.createBlock("div",l,[s,i]))));d.render=c,d.__scopeId="data-v-f17dff8e";var u=t.defineComponent({name:"PaginationLink",props:{active:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1}},setup:e=>({linkClasses:t.computed((()=>e.active?"dt-bg-gray-200 dt-border-gray-300 dt-text-gray-800 hover:dt-bg-gray-200":e.disabled?"dt-cursor-not-allowed dt-text-gray-400":"dt-border-gray-300 dt-bg-white dt-text-gray-500 hover:dt-bg-gray-50"))})});u.render=function(e,a,o,r,d,n){return t.openBlock(),t.createBlock("a",t.mergeProps({href:"#",class:["dt-relative dt-inline-flex dt-items-center dt-px-4 dt-py-2 dt-border dt-text-sm dt-font-medium",e.linkClasses]},t.toHandlers(__assign({},e.$attrs))),[t.renderSlot(e.$slots,"default")],16)};const p="left";var g=t.defineComponent({name:"Pagination",components:{PaginationLink:u},props:{total:{type:Number,required:!0},perPage:{type:Number,required:!0},currentPage:{type:Number,required:!1,default:1},maxVisibleButtons:{type:Number,required:!1,default:5}},emits:["changed"],setup(e,{emit:a}){const o=t.computed((()=>(e.currentPage-1)*e.perPage+1)),r=t.computed((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),d=t.computed((()=>Math.ceil(e.total/e.perPage))),n=t.computed((()=>1===e.currentPage?1:e.currentPage===d.value?d.value-e.maxVisibleButtons+1:e.currentPage-1)),l=t.computed((()=>Math.min(n.value+e.maxVisibleButtons-1,d.value))),s=t.computed((()=>{const e=[];for(let t=n.value;t<=l.value;t+=1)t>0&&e.push(t);return e})),i=t.computed((()=>1===e.currentPage)),c=t.computed((()=>e.currentPage===d.value)),u=e=>{a("changed",e)};return{currentStart:o,currentEnd:r,totalPages:d,pages:s,isInFirstPage:i,isInLastPage:c,goToPageNumber:u,gotoFirstPage:()=>u(1),gotoLastPage:()=>u(d.value),gotoNextPage:()=>u(e.currentPage>=d.value?d.value:e.currentPage+1),gotoPreviousPage:()=>u(e.currentPage<=1?1:e.currentPage-1),showDots:(e=p)=>{const t=e===p?1:d.value,a=e===p?2:d.value-1;return!s.value.includes(t)||!s.value.includes(a)}}}});const m={key:0,class:"dt-bg-white dt-px-4 dt-py-3 dt-flex dt-items-center dt-justify-between dt-border-t dt-border-gray-200 sm:dt-px-6"},f={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},b={class:"dt-text-sm dt-text-gray-700"},v=t.createTextVNode(" Showing "),y=t.createTextVNode(" to "),h=t.createTextVNode(" of "),x=t.createTextVNode(" results. "),k={key:0},w={class:"dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"},N=t.createVNode("span",{class:"dt-sr-only"},"Go to first",-1),P=t.createTextVNode(" « "),C=t.createVNode("span",{class:"dt-sr-only"},"Previous",-1),V=t.createTextVNode(" ‹ "),_=t.createTextVNode(" 1 "),B=t.createTextVNode(" ... "),S=t.createTextVNode(" ... "),I=t.createVNode("span",{class:"dt-sr-only"},"Next",-1),T=t.createTextVNode(" › "),O=t.createVNode("span",{class:"dt-sr-only"},"Go to Last",-1),q=t.createTextVNode(" » ");g.render=function(e,a,o,r,d,n){const l=t.resolveComponent("pagination-link");return e.totalPages?(t.openBlock(),t.createBlock("div",m,[t.createVNode("div",f,[t.withDirectives(t.createVNode("div",null,[t.createVNode("p",b,[t.renderSlot(e.$slots,"pagination-info",{currentStart:e.currentStart,currentEnd:e.currentEnd,total:e.total},(()=>[v,t.createVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentStart)},null,8,["textContent"]),y,t.createVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentEnd)},null,8,["textContent"]),h,t.createVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.total)},null,8,["textContent"]),x]))])],512),[[t.vShow,e.total]]),e.totalPages>1?(t.openBlock(),t.createBlock("div",k,[t.createVNode("nav",w,[t.createVNode(l,{disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[N,P])),_:1},8,["disabled","onClick"]),t.createVNode(l,{disabled:e.isInFirstPage,onClick:t.withModifiers(e.gotoPreviousPage,["prevent"])},{default:t.withCtx((()=>[C,V])),_:1},8,["disabled","onClick"]),e.showDots("left")?(t.openBlock(),t.createBlock(t.Fragment,{key:0},[t.createVNode(l,{class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[_])),_:1},8,["disabled","active","onClick"]),t.createVNode(l,{class:"sm:dt-hidden"},{default:t.withCtx((()=>[B])),_:1})],64)):t.createCommentVNode("",!0),(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.pages,((a,o)=>(t.openBlock(),t.createBlock(l,{key:`pages_${o}`,class:"dt-hidden md:dt-inline-block",active:a===e.currentPage,disabled:a===e.currentPage,onClick:t.withModifiers((t=>e.goToPageNumber(a)),["prevent"])},{default:t.withCtx((()=>[t.createTextVNode(t.toDisplayString(a),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(t.openBlock(),t.createBlock(t.Fragment,{key:1},[t.createVNode(l,{class:"sm:dt-hidden"},{default:t.withCtx((()=>[S])),_:1}),t.createVNode(l,{class:"sm:dt-hidden",disabled:e.isInLastPage,active:e.isInLastPage,onClick:t.withModifiers(e.gotoLastPage,["prevent"])},{default:t.withCtx((()=>[t.createTextVNode(t.toDisplayString(e.totalPages),1)])),_:1},8,["disabled","active","onClick"])],64)):t.createCommentVNode("",!0),t.createVNode(l,{disabled:e.isInLastPage,onClick:t.withModifiers(e.gotoNextPage,["prevent"])},{default:t.withCtx((()=>[I,T])),_:1},8,["disabled","onClick"]),t.createVNode(l,{disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:t.withModifiers(e.gotoLastPage,["prevent"])},{default:t.withCtx((()=>[O,q])),_:1},8,["disabled","onClick"])])])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)};const D={},L={class:"dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};D.render=function(e,a){return t.openBlock(),t.createBlock("td",L,[t.renderSlot(e.$slots,"default")])};const $={},j={scope:"col",class:"dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};$.render=function(e,a){return t.openBlock(),t.createBlock("th",j,[t.renderSlot(e.$slots,"default")])};const F=[5,10,15,25,50,75,100],M=t.defineComponent({components:{SearchIcon:a,Loading:d,Pagination:g,TableBody:D,TableHead:$},props:{rows:{type:Array,required:!0},columns:{type:Object,required:!1,default:null},pagination:{type:Object,required:!1,default:null},striped:{type:Boolean,required:!1,default:!1},sn:{type:Boolean,required:!1,default:!1},filter:{type:Boolean,required:!1,default:!1},loading:{type:Boolean,required:!1,default:!1},perPageOptions:{type:Array,required:!1,default:()=>F},query:{type:Object,required:!1,default:()=>({})}},emits:["loadData"],setup(e,{emit:a}){var o,r;const d=t.ref({page:(null==(o=e.pagination)?void 0:o.page)||1,search:e.query.search||"",per_page:(null==(r=e.pagination)?void 0:r.per_page)||10}),n=t.computed((()=>!!e.pagination)),l=t.computed((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),s=t.computed((()=>e.rows)),i=t.computed((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>__assign(__assign({},e),{[t]:t})),{}))),c=t.computed((()=>n.value?d.value.per_page*(d.value.page-1):0));t.watch((()=>__assign({},d.value)),(()=>{a("loadData",d.value)}),{deep:!0,immediate:!0});const u=((e,t=400)=>{let a;return(...o)=>{clearTimeout(a),a=setTimeout((()=>e(...o)),t)}})((e=>{d.value=__assign(__assign({},d.value),{page:1,search:e.target.value})}));return{tableQuery:d,showPagination:n,totalData:l,tableRows:s,tableColumns:i,paginatedRowIndex:c,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{d.value.page=e},handleOnSearchChange:u,handleOnChange:e=>{const{name:t,value:a}=e.target;d.value=__assign(__assign({},d.value),{page:1,[t]:a})}}}});const Q=t.withScopeId("data-v-0bb37481");t.pushScopeId("data-v-0bb37481");const E={class:"data-table dt-flex dt-flex-col"},R={class:"dt-align-middle dt-min-w-full"},z={key:0,class:"dt-filter-wrapper dt-mb-3 dt-w-full"},A={class:"dt-w-64"},H=t.createVNode("label",{for:"email",class:"dt-sr-only"},"Search",-1),G={class:"dt-relative dt-rounded-md dt-shadow-sm"},J={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"},K={class:"table-wrapper dt-relative dt-shadow dt-overflow-hidden dt-border-b dt-border-gray-200 sm:dt-rounded-lg"},U={key:1,class:"pagination-wrapper md:dt-flex smdt-flex-col dt-bg-white dt-items-center"},W={class:"dt-pr-4 dt-w-full dt-pb-3 dt-flex dt-justify-end sm:dt-pr-6 sm:dt-pb-0 sm:dt-w-auto"},X={class:""},Y=t.createVNode("label",{for:"location",class:"dt-sr-only"},"Per page",-1),Z={class:"table-container dt-overflow-auto"},ee={class:"dt-min-w-full dt-divide-y dt-divide-gray-200"},te={class:"dt-bg-gray-50"},ae={key:2,class:"pagination-wrapper"};t.popScopeId();const oe=Q(((e,a,o,r,d,n)=>{const l=t.resolveComponent("search-icon"),s=t.resolveComponent("Loading"),i=t.resolveComponent("pagination"),c=t.resolveComponent("table-head"),u=t.resolveComponent("table-body");return t.openBlock(),t.createBlock("div",E,[t.createVNode("div",R,[e.filter?(t.openBlock(),t.createBlock("div",z,[t.createVNode("div",A,[H,t.createVNode("div",G,[t.createVNode("input",{value:e.tableQuery.search,type:"search",name:"search",class:"focus:dt-ring-0 dt-block dt-w-full dt-pr-10 sm:dt-text-sm dt-border-gray-300 dt-rounded-md",onInput:a[1]||(a[1]=(...t)=>e.handleOnSearchChange&&e.handleOnSearchChange(...t))},null,40,["value"]),t.createVNode("div",J,[t.createVNode(l,{class:"dt-text-gray-400"})])])])])):t.createCommentVNode("",!0),t.createVNode("div",K,[e.loading?t.renderSlot(e.$slots,"loading",{key:0},(()=>[t.createVNode(s)]),{},!0):t.createCommentVNode("",!0),e.showPagination?(t.openBlock(),t.createBlock("div",U,[t.createVNode(i,{class:"dt-flex-1",total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"]),t.createVNode("div",W,[t.createVNode("div",X,[Y,t.createVNode("select",{value:e.tableQuery.per_page,name:"per_page",class:"dt-block dt-w-full dt-pl-3 dt-pr-10 dt-py-2 dt-text-base dt-border-gray-300 sm:dt-text-sm dt-rounded-md",onInput:a[2]||(a[2]=(...t)=>e.handleOnChange&&e.handleOnChange(...t))},[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.perPageOptions,(a=>(t.openBlock(),t.createBlock("option",{key:`per_page_${a}`,value:a,selected:a===e.tableQuery.per_page,textContent:t.toDisplayString(a)},null,8,["value","selected","textContent"])))),128))],40,["value"])])])])):t.createCommentVNode("",!0),t.createVNode("div",Z,[t.createVNode("table",ee,[t.createVNode("thead",te,[t.createVNode("tr",null,[e.sn?t.renderSlot(e.$slots,"thead-sn",{key:0},(()=>[t.createVNode(c,{textContent:t.toDisplayString("S.N.")},null,8,["textContent"])]),{},!0):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"thead",{column:e.tableColumns},(()=>[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.tableColumns,((e,a)=>(t.openBlock(),t.createBlock(c,{key:`datatable-thead-th-${a}`,textContent:t.toDisplayString(e)},null,8,["textContent"])))),128))]),!0)])]),t.createVNode("tbody",null,[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.tableRows,((a,o)=>(t.openBlock(),t.createBlock("tr",{key:`datatable-tbody-${e.uniqueId()}-${o}`,class:e.striped&&o%2?"dt-bg-gray-50":"dt-bg-white"},[e.sn?t.renderSlot(e.$slots,"tbody-sn",{key:0,sn:o+1},(()=>[t.createVNode(u,{textContent:t.toDisplayString(o+1+e.paginatedRowIndex)},null,8,["textContent"])]),!0):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"tbody",{index:o,row:a},(()=>[(t.openBlock(!0),t.createBlock(t.Fragment,null,t.renderList(e.tableColumns,((o,r)=>(t.openBlock(),t.createBlock(u,{key:`datatable-tbody-td-${e.uniqueId()}-${r}`,name:o,textContent:t.toDisplayString(a[r])},null,8,["name","textContent"])))),128))]),!0)],2)))),128))])])]),e.showPagination?(t.openBlock(),t.createBlock("div",ae,[t.createVNode(i,{total:e.totalData,"current-page":e.tableQuery.page,"per-page":parseInt(e.tableQuery.per_page.toString()),onChanged:e.handlePageChange},null,8,["total","current-page","per-page","onChanged"])])):t.createCommentVNode("",!0)])])])}));M.render=oe,M.__scopeId="data-v-0bb37481",e.DataTable=M,e.Pagination=g,e.PaginationLink=u,e.TableBody=D,e.TableHead=$,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); |
{ | ||
"name": "@jobinsjp/vue3-datatable", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "DataTable component with basic pagination, search filters etc for Vue3", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
59596