@jobinsjp/vue3-datatable
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -1,1 +0,1 @@ | ||
var e=Object.defineProperty,t=Object.defineProperties,a=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,d=(t,a,n)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[a]=n,o=(e,t)=>{for(var a in t||(t={}))r.call(t,a)&&d(e,a,t[a]);if(n)for(var a of n(t))l.call(t,a)&&d(e,a,t[a]);return e},i=(e,n)=>t(e,a(n));import{defineComponent as s,openBlock as u,createElementBlock as p,createElementVNode as g,mergeProps as c,resolveComponent as f,createVNode as v,pushScopeId as b,popScopeId as m,renderSlot as y,computed as _,toHandlers as h,createBlock as P,withCtx as w,toDisplayString as x,createCommentVNode as C,withModifiers as k,Fragment as I,renderList as T,createTextVNode as q,normalizeClass as $,ref as B,watch as S}from"vue";var O=s({name:"SearchIcon"});const L={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},j=[g("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)];O.render=function(e,t,a,n,r,l){return u(),p("svg",L,j)};var N=s({name:"SearchInput",props:{value:{type:String,required:!0}}});const F=["value"];N.render=function(e,t,a,n,r,l){return u(),p("input",c({value:e.value,type:"search",name:"search",class:"dt__filter__search dt-block dt-border dt-border-gray-300 dt-pr-10 dt-px-2 dt-py-2\n dt-rounded-md dt-w-full dt-outline-none focus:dt-ring-1 focus:dt-ring-inset sm:dt-text-sm"},e.$attrs),null,16,F)};var z=s({name:"Filter",components:{SearchInput:N,SearchIcon:O},props:{search:{type:String,required:!0}},emits:["input"]});const D={class:"dt__filter dt-mb-3 dt-w-full"},W={class:"dt-w-64"},H=g("label",{for:"email",class:"dt-sr-only"},"Search",-1),Q={class:"dt-relative dt-rounded-md dt-shadow-sm"},R={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"};z.render=function(e,t,a,n,r,l){const d=f("SearchInput"),o=f("SearchIcon");return u(),p("div",D,[g("div",W,[H,g("div",Q,[v(d,{value:e.search,onInput:t[0]||(t[0]=t=>e.$emit("input",t.target.value))},null,8,["value"]),g("div",R,[v(o,{class:"dt-text-gray-400"})])])])])};var M=s({name:"Loading"});b("data-v-685865e4");const A={class:"dt__loading dt-absolute dt-h-full dt-w-full"},E=[g("div",{class:"dt-flex dt-justify-center dt-items-center"},[g("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"}),g("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"})],-1)];m(),M.render=function(e,t,a,n,r,l){return u(),p("div",A,E)},M.__scopeId="data-v-685865e4";var V=s({name:"BottomPaginationWrapper"});const G={class:"dt__pagination_wrapper--bottom dt-bg-white dt-shadow-inner"},U={class:"dt-px-4 sm:dt-px-6 dt-py-4"};V.render=function(e,t,a,n,r,l){return u(),p("div",G,[g("div",U,[y(e.$slots,"default")])])};var J=s({name:"PaginationButtons"});const K={class:"dt__pagination__nav dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"};J.render=function(e,t,a,n,r,l){return u(),p("nav",K,[y(e.$slots,"default")])};var X=s({name:"PaginationInfo"});const Y={class:"dt__pagination__info"},Z={class:"dt-text-sm dt-text-gray-700"};X.render=function(e,t,a,n,r,l){return u(),p("div",Y,[g("p",Z,[y(e.$slots,"default")])])};var ee=s({name:"PaginationLink",props:{active:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1}},setup:e=>({linkClasses:_((()=>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"))})});ee.render=function(e,t,a,n,r,l){return u(),p("a",c({href:"#",class:["dt__pagination__link dt-relative dt-inline-flex dt-items-center dt-px-4 dt-py-2 dt-border dt-text-sm dt-font-medium",e.linkClasses]},h(o({},e.$attrs))),[y(e.$slots,"default")],16)};var te=s({name:"Pagination",components:{PaginationButtons:J,PaginationInfo:X,PaginationLink:ee},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=_((()=>(e.currentPage-1)*e.perPage+1)),n=_((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),r=_((()=>Math.ceil(e.total/e.perPage))),l=_((()=>1===e.currentPage?1:e.currentPage===r.value?r.value-e.maxVisibleButtons+1:e.currentPage-1)),d=_((()=>Math.min(l.value+e.maxVisibleButtons-1,r.value))),o=_((()=>{const e=[];for(let t=l.value;t<=d.value;t+=1)t>0&&e.push(t);return e})),i=_((()=>1===e.currentPage)),s=_((()=>e.currentPage===r.value)),u=e=>{t("changed",e)};return{currentStart:a,currentEnd:n,totalPages:r,pages:o,isInFirstPage:i,isInLastPage:s,goToPageNumber:u,gotoFirstPage:()=>u(1),gotoLastPage:()=>u(r.value),gotoNextPage:()=>u(e.currentPage>=r.value?r.value:e.currentPage+1),gotoPreviousPage:()=>u(e.currentPage<=1?1:e.currentPage-1),showDots:(e="left")=>{const t="left"===e?1:r.value,a="left"===e?2:r.value-1;return!o.value.includes(t)||!o.value.includes(a)}}}});const ae={key:0,class:"dt__pagination dt-bg-white dt-flex dt-items-center dt-justify-between"},ne={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},re=q(" Showing "),le=["textContent"],de=q(" to "),oe=["textContent"],ie=q(" of "),se=["textContent"],ue=q(" results. "),pe=g("span",{class:"dt-sr-only"},"Go to first",-1),ge=q(" « "),ce=g("span",{class:"dt-sr-only"},"Previous",-1),fe=q(" ‹ "),ve=q(" 1 "),be=q(" ... "),me=q(" ... "),ye=g("span",{class:"dt-sr-only"},"Next",-1),_e=q(" › "),he=g("span",{class:"dt-sr-only"},"Go to Last",-1),Pe=q(" » ");te.render=function(e,t,a,n,r,l){const d=f("PaginationInfo"),o=f("pagination-link"),i=f("PaginationButtons");return e.totalPages?(u(),p("div",ae,[g("div",ne,[e.total?(u(),P(d,{key:0},{default:w((()=>[y(e.$slots,"pagination-info",{start:e.currentStart,end:e.currentEnd,total:e.total},(()=>[re,g("span",{class:"dt-font-medium",textContent:x(e.currentStart)},null,8,le),de,g("span",{class:"dt-font-medium",textContent:x(e.currentEnd)},null,8,oe),ie,g("span",{class:"dt-font-medium",textContent:x(e.total)},null,8,se),ue]))])),_:3})):C("",!0),e.totalPages>1?(u(),P(i,{key:1},{default:w((()=>[v(o,{key:"page_first",disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:k(e.gotoFirstPage,["prevent"])},{default:w((()=>[pe,ge])),_:1},8,["disabled","onClick"]),v(o,{key:"page_previous",disabled:e.isInFirstPage,onClick:k(e.gotoPreviousPage,["prevent"])},{default:w((()=>[ce,fe])),_:1},8,["disabled","onClick"]),e.showDots("left")?(u(),p(I,{key:0},[v(o,{key:"page_1",class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:k(e.gotoFirstPage,["prevent"])},{default:w((()=>[ve])),_:1},8,["disabled","active","onClick"]),v(o,{key:"page_divider_left",class:"sm:dt-hidden"},{default:w((()=>[be])),_:1})],64)):C("",!0),(u(!0),p(I,null,T(e.pages,(t=>(u(),P(o,{key:`pages_${t}`,class:"dt-hidden md:dt-inline-block",active:t===e.currentPage,disabled:t===e.currentPage,onClick:k((a=>e.goToPageNumber(t)),["prevent"])},{default:w((()=>[q(x(t),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(u(),p(I,{key:1},[v(o,{key:"page_divider_right",class:"sm:dt-hidden"},{default:w((()=>[me])),_:1}),v(o,{key:`page_${e.totalPages}`,class:"sm:dt-hidden",disabled:e.isInLastPage,active:e.isInLastPage,onClick:k(e.gotoLastPage,["prevent"])},{default:w((()=>[q(x(e.totalPages),1)])),_:1},8,["disabled","active","onClick"])],64)):C("",!0),v(o,{key:"page_next",disabled:e.isInLastPage,onClick:k(e.gotoNextPage,["prevent"])},{default:w((()=>[ye,_e])),_:1},8,["disabled","onClick"]),v(o,{key:"page_last",disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:k(e.gotoLastPage,["prevent"])},{default:w((()=>[he,Pe])),_:1},8,["disabled","onClick"])])),_:1})):C("",!0)])])):C("",!0)};var we=s({name:"PaginationSize",props:{value:{type:[Number,String],required:!0},options:{type:Array,required:!0}},emits:["input"]});const xe={class:"dt__pagination_size_wrapper dt-w-full dt-flex dt-justify-end sm:dt-w-auto"},Ce=g("label",{for:"location",class:"dt-sr-only"},"Per page",-1),ke=["value"],Ie=["value","selected","textContent"];we.render=function(e,t,a,n,r,l){return u(),p("div",xe,[g("div",null,[Ce,g("select",{value:e.value,name:"per_page",class:"dt__pagination_size dt-block dt-w-full dt-pl-3 dt-pr-5 dt-py-2 dt-text-base dt-border\n dt-border-gray-300 sm:dt-text-sm dt-rounded-md dt-outline-none focus:dt-ring-1 focus:dt-ring-inset",onInput:t[0]||(t[0]=t=>e.$emit("input",t.target.value))},[(u(!0),p(I,null,T(e.options,(t=>(u(),p("option",{key:`per_page_${t}`,value:t,selected:t===e.value,textContent:x(t)},null,8,Ie)))),128))],40,ke)])])};var Te=s({name:"TopPaginationWrapper",props:{withPagination:{type:Boolean,required:!1,default:!1}}});Te.render=function(e,t,a,n,r,l){return u(),p("div",{class:$(["dt__pagination_wrapper--top md:dt-flex xs:dt-flex-col dt-items-center",{"dt-bg-white dt-py-4 dt-px-4 sm:dt-px-6":e.withPagination}])},[y(e.$slots,"default")],2)};var qe=s({name:"TableBodyCell"});const $e={class:"dt__table__tbody_td dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};qe.render=function(e,t,a,n,r,l){return u(),p("td",$e,[y(e.$slots,"default")])};var Be=s({name:"TableHeadCell"});const Se={scope:"col",class:"dt__table__thead__th dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};Be.render=function(e,t,a,n,r,l){return u(),p("th",Se,[y(e.$slots,"default")])};var Oe=s({name:"TableRow",props:{rowIndex:{type:Number,required:!0},striped:{type:Boolean,required:!1,default:!1}}});Oe.render=function(e,t,a,n,r,l){return u(),p("tr",{class:$(["dt__table__row",e.striped&&e.rowIndex%2?"dt-bg-gray-50":"dt-bg-white"])},[y(e.$slots,"default")],2)};var Le=s({name:"TableWrapper"});const je={class:"dt__table_wrapper dt-overflow-auto"},Ne={class:"dt__table dt-min-w-full dt-divide-y dt-divide-gray-200"};Le.render=function(e,t,a,n,r,l){return u(),p("div",je,[g("table",Ne,[y(e.$slots,"default")])])};var Fe=s({name:"TBody"});const ze={class:"dt__table__tbody"};Fe.render=function(e,t,a,n,r,l){return u(),p("tbody",ze,[y(e.$slots,"default")])};var De=s({name:"THead"});const We={class:"dt__table__thead dt-bg-gray-50"},He={class:"dt__table__thead__tr"};De.render=function(e,t,a,n,r,l){return u(),p("thead",We,[g("tr",He,[y(e.$slots,"default")])])};const Qe=[5,10,15,25,50,75,100],Re=s({name:"DataTable",components:{TableHeadCell:Be,TableBodyCell:qe,TBody:Fe,TableRow:Oe,THead:De,BottomPaginationWrapper:V,TableWrapper:Le,PaginationSize:we,TopPaginationWrapper:Te,Filter:z,Loading:M,Pagination:te},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:()=>Qe},query:{type:Object,required:!1,default:()=>({})},topPagination:{type:Boolean,required:!1,default:!1},bottomPagination:{type:Boolean,required:!1,default:!0}},emits:["loadData"],setup(e,{emit:t}){var a,n;const r=B({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}),l=_((()=>!!e.pagination)),d=_((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),s=_((()=>e.rows)),u=_((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>{return i(o({},e),{[t]:(a=t,a.toLowerCase().replace(/[-_]/g," ").split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" "))});var a}),{}))),p=_((()=>l.value?r.value.per_page*(r.value.page-1):0));S((()=>o({},r.value)),(()=>{t("loadData",r.value)}),{deep:!0,immediate:!0});const g=((e,t=400)=>{let a;return(...n)=>{clearTimeout(a),a=setTimeout((()=>e(...n)),t)}})((e=>{r.value=i(o({},r.value),{page:1,search:e})}));return{tableQuery:r,showPagination:l,totalData:d,tableRows:s,tableColumns:u,paginatedRowIndex:p,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{r.value.page=e},handleOnSearchChange:g,handleOnPaginationSizeChange:e=>{r.value=i(o({},r.value),{page:1,per_page:e})}}}});const Me={class:"data-table dt-flex dt-flex-col"},Ae={class:"dt-align-middle dt-min-w-full"},Ee={class:"dt__wrapper dt-relative dt-overflow-hidden sm:dt-rounded-lg"};Re.render=function(e,t,a,n,r,l){const d=f("Filter"),o=f("Loading"),i=f("Pagination"),s=f("PaginationSize"),c=f("TopPaginationWrapper"),b=f("TableHeadCell"),m=f("THead"),_=f("TableBodyCell"),h=f("TableRow"),k=f("TBody"),q=f("TableWrapper"),$=f("pagination"),B=f("BottomPaginationWrapper");return u(),p("div",Me,[g("div",Ae,[e.filter&&e.topPagination?(u(),P(d,{key:0,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):C("",!0),g("div",Ee,[e.loading?y(e.$slots,"loading",{key:0},(()=>[v(o)])):C("",!0),e.showPagination?(u(),P(c,{key:1,"with-pagination":e.topPagination},{default:w((()=>[e.topPagination?(u(),P(i,{key:0,class:"dt-flex-1 dt-pr-4",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"])):C("",!0),e.filter&&!e.topPagination?(u(),P(d,{key:1,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):C("",!0),v(s,{value:e.tableQuery.per_page,options:e.perPageOptions,onInput:e.handleOnPaginationSizeChange},null,8,["value","options","onInput"])])),_:1},8,["with-pagination"])):C("",!0),v(q,null,{default:w((()=>[v(m,null,{default:w((()=>[e.sn?y(e.$slots,"thead-sn",{key:0},(()=>[v(b,{textContent:x("S.N.")},null,8,["textContent"])])):C("",!0),y(e.$slots,"thead",{column:e.tableColumns},(()=>[(u(!0),p(I,null,T(e.tableColumns,((e,t)=>(u(),P(b,{key:`datatable-thead-th-${t}`,textContent:x(e)},null,8,["textContent"])))),128))]))])),_:3}),v(k,null,{default:w((()=>[(u(!0),p(I,null,T(e.tableRows,((t,a)=>(u(),P(h,{key:`datatable-row-${e.uniqueId()}-${a}`,"row-index":a,striped:e.striped},{default:w((()=>[e.sn?y(e.$slots,"tbody-sn",{key:0,sn:a+1},(()=>[v(_,{textContent:x(a+1+e.paginatedRowIndex)},null,8,["textContent"])])):C("",!0),y(e.$slots,"tbody",{index:a,row:t},(()=>[(u(!0),p(I,null,T(e.tableColumns,((a,n)=>(u(),P(_,{key:`datatable-tbody-td-${e.uniqueId()}-${n}`,name:a,textContent:x(t[n])},null,8,["name","textContent"])))),128))]))])),_:2},1032,["row-index","striped"])))),128))])),_:3})])),_:3}),e.showPagination&&e.bottomPagination?(u(),P(B,{key:2},{default:w((()=>[v($,{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"])])),_:1})):C("",!0)])])])};export{Re as DataTable,te as Pagination,ee as PaginationLink,qe as TableBody,qe as TableBodyCell,Be as TableHead,Be as TableHeadCell}; | ||
var e=Object.defineProperty,t=Object.defineProperties,a=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,d=(t,a,n)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[a]=n,o=(e,t)=>{for(var a in t||(t={}))r.call(t,a)&&d(e,a,t[a]);if(n)for(var a of n(t))l.call(t,a)&&d(e,a,t[a]);return e},i=(e,n)=>t(e,a(n));import{defineComponent as s,openBlock as u,createElementBlock as p,createElementVNode as c,mergeProps as g,resolveComponent as b,createVNode as f,pushScopeId as v,popScopeId as m,renderSlot as y,computed as _,toHandlers as h,createBlock as P,withCtx as w,toDisplayString as x,createCommentVNode as C,withModifiers as k,Fragment as I,renderList as q,createTextVNode as B,normalizeClass as $,ref as T,watch as S}from"vue";var O=s({name:"SearchIcon"});const L={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},j=[c("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)];O.render=function(e,t,a,n,r,l){return u(),p("svg",L,j)};var N=s({name:"SearchInput",props:{value:{type:String,required:!0}}});const F=["value"];N.render=function(e,t,a,n,r,l){return u(),p("input",g({value:e.value,type:"search",name:"search",class:"dt__filter__search dt-block dt-border dt-border-gray-300 dt-pr-10 dt-px-2 dt-py-2\n dt-rounded-md dt-w-full dt-outline-none focus:dt-ring-1 focus:dt-ring-inset sm:dt-text-sm"},e.$attrs),null,16,F)};var R=s({name:"Filter",components:{SearchInput:N,SearchIcon:O},props:{search:{type:String,required:!0}},emits:["input"]});const z={class:"dt__filter dt-mb-3 dt-w-full"},D={class:"dt-w-64"},H=c("label",{for:"email",class:"dt-sr-only"},"Search",-1),W={class:"dt-relative dt-rounded-md dt-shadow-sm"},Q={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"};R.render=function(e,t,a,n,r,l){const d=b("SearchInput"),o=b("SearchIcon");return u(),p("div",z,[c("div",D,[H,c("div",W,[f(d,{value:e.search,onInput:t[0]||(t[0]=t=>e.$emit("input",t.target.value))},null,8,["value"]),c("div",Q,[f(o,{class:"dt-text-gray-400"})])])])])};var M=s({name:"Loading"});v("data-v-685865e4");const A={class:"dt__loading dt-absolute dt-h-full dt-w-full"},E=[c("div",{class:"dt-flex dt-justify-center dt-items-center"},[c("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"}),c("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"})],-1)];m(),M.render=function(e,t,a,n,r,l){return u(),p("div",A,E)},M.__scopeId="data-v-685865e4";var V=s({name:"BottomPaginationWrapper"});const G={class:"dt__pagination_wrapper--bottom dt-bg-white dt-shadow-inner"},U={class:"dt-px-4 sm:dt-px-6 dt-py-4"};V.render=function(e,t,a,n,r,l){return u(),p("div",G,[c("div",U,[y(e.$slots,"default")])])};var J=s({name:"PaginationButtons"});const K={class:"dt__pagination__nav dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"};J.render=function(e,t,a,n,r,l){return u(),p("nav",K,[y(e.$slots,"default")])};var X=s({name:"PaginationInfo"});const Y={class:"dt__pagination__info"},Z={class:"dt-text-sm dt-text-gray-700"};X.render=function(e,t,a,n,r,l){return u(),p("div",Y,[c("p",Z,[y(e.$slots,"default")])])};var ee=s({name:"PaginationLink",props:{active:{type:Boolean,required:!1,default:!1},disabled:{type:Boolean,required:!1,default:!1}},setup:e=>({linkClasses:_((()=>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"))})});ee.render=function(e,t,a,n,r,l){return u(),p("a",g({href:"#",class:["dt__pagination__link dt-relative dt-inline-flex dt-items-center dt-px-4 dt-py-2 dt-border dt-text-sm dt-font-medium",e.linkClasses]},h(o({},e.$attrs))),[y(e.$slots,"default")],16)};var te=s({name:"Pagination",components:{PaginationButtons:J,PaginationInfo:X,PaginationLink:ee},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=_((()=>(e.currentPage-1)*e.perPage+1)),n=_((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),r=_((()=>Math.ceil(e.total/e.perPage))),l=_((()=>1===e.currentPage?1:e.currentPage===r.value?r.value-e.maxVisibleButtons+1:e.currentPage-1)),d=_((()=>Math.min(l.value+e.maxVisibleButtons-1,r.value))),o=_((()=>{const e=[];for(let t=l.value;t<=d.value;t+=1)t>0&&e.push(t);return e})),i=_((()=>1===e.currentPage)),s=_((()=>e.currentPage===r.value)),u=e=>{t("changed",e)};return{currentStart:a,currentEnd:n,totalPages:r,pages:o,isInFirstPage:i,isInLastPage:s,goToPageNumber:u,gotoFirstPage:()=>u(1),gotoLastPage:()=>u(r.value),gotoNextPage:()=>u(e.currentPage>=r.value?r.value:e.currentPage+1),gotoPreviousPage:()=>u(e.currentPage<=1?1:e.currentPage-1),showDots:(e="left")=>{const t="left"===e?1:r.value,a="left"===e?2:r.value-1;return!o.value.includes(t)||!o.value.includes(a)}}}});const ae={key:0,class:"dt__pagination dt-bg-white dt-flex dt-items-center dt-justify-between"},ne={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},re=B(" Showing "),le=["textContent"],de=B(" to "),oe=["textContent"],ie=B(" of "),se=["textContent"],ue=B(" results. "),pe=c("span",{class:"dt-sr-only"},"Go to first",-1),ce=B(" « "),ge=c("span",{class:"dt-sr-only"},"Previous",-1),be=B(" ‹ "),fe=B(" 1 "),ve=B(" ... "),me=B(" ... "),ye=c("span",{class:"dt-sr-only"},"Next",-1),_e=B(" › "),he=c("span",{class:"dt-sr-only"},"Go to Last",-1),Pe=B(" » ");te.render=function(e,t,a,n,r,l){const d=b("PaginationInfo"),o=b("pagination-link"),i=b("PaginationButtons");return e.totalPages?(u(),p("div",ae,[c("div",ne,[e.total?(u(),P(d,{key:0},{default:w((()=>[y(e.$slots,"pagination-info",{start:e.currentStart,end:e.currentEnd,total:e.total},(()=>[re,c("span",{class:"dt-font-medium",textContent:x(e.currentStart)},null,8,le),de,c("span",{class:"dt-font-medium",textContent:x(e.currentEnd)},null,8,oe),ie,c("span",{class:"dt-font-medium",textContent:x(e.total)},null,8,se),ue]))])),_:3})):C("",!0),e.totalPages>1?(u(),P(i,{key:1},{default:w((()=>[f(o,{key:"page_first",disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:k(e.gotoFirstPage,["prevent"])},{default:w((()=>[pe,ce])),_:1},8,["disabled","onClick"]),f(o,{key:"page_previous",disabled:e.isInFirstPage,onClick:k(e.gotoPreviousPage,["prevent"])},{default:w((()=>[ge,be])),_:1},8,["disabled","onClick"]),e.showDots("left")?(u(),p(I,{key:0},[f(o,{key:"page_1",class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:k(e.gotoFirstPage,["prevent"])},{default:w((()=>[fe])),_:1},8,["disabled","active","onClick"]),f(o,{key:"page_divider_left",class:"sm:dt-hidden"},{default:w((()=>[ve])),_:1})],64)):C("",!0),(u(!0),p(I,null,q(e.pages,(t=>(u(),P(o,{key:`pages_${t}`,class:"dt-hidden md:dt-inline-block",active:t===e.currentPage,disabled:t===e.currentPage,onClick:k((a=>e.goToPageNumber(t)),["prevent"])},{default:w((()=>[B(x(t),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(u(),p(I,{key:1},[f(o,{key:"page_divider_right",class:"sm:dt-hidden"},{default:w((()=>[me])),_:1}),f(o,{key:`page_${e.totalPages}`,class:"sm:dt-hidden",disabled:e.isInLastPage,active:e.isInLastPage,onClick:k(e.gotoLastPage,["prevent"])},{default:w((()=>[B(x(e.totalPages),1)])),_:1},8,["disabled","active","onClick"])],64)):C("",!0),f(o,{key:"page_next",disabled:e.isInLastPage,onClick:k(e.gotoNextPage,["prevent"])},{default:w((()=>[ye,_e])),_:1},8,["disabled","onClick"]),f(o,{key:"page_last",disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:k(e.gotoLastPage,["prevent"])},{default:w((()=>[he,Pe])),_:1},8,["disabled","onClick"])])),_:1})):C("",!0)])])):C("",!0)};var we=s({name:"PaginationSize",props:{value:{type:[Number,String],required:!0},options:{type:Array,required:!0}},emits:["input"]});const xe={class:"dt__pagination_size_wrapper dt-w-full dt-flex dt-justify-end sm:dt-w-auto"},Ce=c("label",{for:"location",class:"dt-sr-only"},"Per page",-1),ke=["value"],Ie=["value","selected","textContent"];we.render=function(e,t,a,n,r,l){return u(),p("div",xe,[c("div",null,[Ce,c("select",{value:e.value,name:"per_page",class:"dt__pagination_size dt-block dt-w-full dt-pl-3 dt-pr-5 dt-py-2 dt-text-base dt-border\n dt-border-gray-300 sm:dt-text-sm dt-rounded-md dt-outline-none focus:dt-ring-1 focus:dt-ring-inset",onInput:t[0]||(t[0]=t=>e.$emit("input",t.target.value))},[(u(!0),p(I,null,q(e.options,(t=>(u(),p("option",{key:`per_page_${t}`,value:t,selected:t===e.value,textContent:x(t)},null,8,Ie)))),128))],40,ke)])])};var qe=s({name:"TopPaginationWrapper",props:{withPagination:{type:Boolean,required:!1,default:!1}}});qe.render=function(e,t,a,n,r,l){return u(),p("div",{class:$(["dt__pagination_wrapper--top md:dt-flex xs:dt-flex-col dt-items-center",{"dt-bg-white dt-py-4 dt-px-4 sm:dt-px-6":e.withPagination}])},[y(e.$slots,"default")],2)};var Be=s({name:"TableBodyCell"});const $e={class:"dt__table__tbody_td dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};Be.render=function(e,t,a,n,r,l){return u(),p("td",$e,[y(e.$slots,"default")])};var Te=s({name:"TableHeadCell"});const Se={scope:"col",class:"dt__table__thead__th dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};Te.render=function(e,t,a,n,r,l){return u(),p("th",Se,[y(e.$slots,"default")])};var Oe=s({name:"TableRow",props:{rowIndex:{type:[Number,String],required:!1,default:0},striped:{type:Boolean,required:!1,default:!1},hoverable:{type:Boolean,required:!1,default:!1},nonClickable:{type:Boolean,required:!1,default:!1}},emits:["clicked"],setup:e=>({formattedRowIndex:T(parseInt(e.rowIndex)||0)})});Oe.render=function(e,t,a,n,r,l){return u(),p("tr",{class:$(["dt__table__row",{"dt-bg-white":!e.striped||e.striped&&e.formattedRowIndex%2==0,"dt-bg-gray-50":e.striped&&e.formattedRowIndex%2,"hover:dt-bg-gray-100":e.hoverable,"dt-cursor-pointer":e.hoverable&&!e.nonClickable}]),onClick:t[0]||(t[0]=k((t=>e.$emit("clicked")),["stop"]))},[y(e.$slots,"default")],2)};var Le=s({name:"TableWrapper"});const je={class:"dt__table_wrapper dt-overflow-auto"},Ne={class:"dt__table dt-min-w-full dt-divide-y dt-divide-gray-200"};Le.render=function(e,t,a,n,r,l){return u(),p("div",je,[c("table",Ne,[y(e.$slots,"default")])])};var Fe=s({name:"TBody"});const Re={class:"dt__table__tbody"};Fe.render=function(e,t,a,n,r,l){return u(),p("tbody",Re,[y(e.$slots,"default")])};var ze=s({name:"THead"});const De={class:"dt__table__thead dt-bg-gray-50"},He={class:"dt__table__thead__tr"};ze.render=function(e,t,a,n,r,l){return u(),p("thead",De,[c("tr",He,[y(e.$slots,"default")])])};const We=[5,10,15,25,50,75,100],Qe=s({name:"DataTable",components:{TableHeadCell:Te,TableBodyCell:Be,TBody:Fe,TableRow:Oe,THead:ze,BottomPaginationWrapper:V,TableWrapper:Le,PaginationSize:we,TopPaginationWrapper:qe,Filter:R,Loading:M,Pagination:te},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:()=>We},query:{type:Object,required:!1,default:()=>({})},topPagination:{type:Boolean,required:!1,default:!1},bottomPagination:{type:Boolean,required:!1,default:!0},hoverable:{type:Boolean,required:!1,default:!1},nonClickable:{type:Boolean,required:!1,default:!1}},emits:["loadData","rowClicked"],setup(e,{emit:t}){var a,n;const r=T({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}),l=_((()=>!!e.pagination)),d=_((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),s=_((()=>e.rows)),u=_((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>{return i(o({},e),{[t]:(a=t,a.toLowerCase().replace(/[-_]/g," ").split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" "))});var a}),{}))),p=_((()=>l.value?r.value.per_page*(r.value.page-1):0));S((()=>o({},r.value)),(()=>{t("loadData",r.value)}),{deep:!0,immediate:!0});const c=((e,t=400)=>{let a;return(...n)=>{clearTimeout(a),a=setTimeout((()=>e(...n)),t)}})((e=>{r.value=i(o({},r.value),{page:1,search:e})}));return{tableQuery:r,showPagination:l,totalData:d,tableRows:s,tableColumns:u,paginatedRowIndex:p,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{r.value.page=e},handleOnSearchChange:c,handleOnPaginationSizeChange:e=>{r.value=i(o({},r.value),{page:1,per_page:e})},rowClickHandler:a=>{!e.nonClickable&&e.hoverable&&t("rowClicked",a)}}}});const Me={class:"data-table dt-flex dt-flex-col"},Ae={class:"dt-align-middle dt-min-w-full"},Ee={class:"dt__wrapper dt-relative dt-overflow-hidden sm:dt-rounded-lg"};Qe.render=function(e,t,a,n,r,l){const d=b("Filter"),o=b("Loading"),i=b("Pagination"),s=b("PaginationSize"),g=b("TopPaginationWrapper"),v=b("TableHeadCell"),m=b("THead"),_=b("TableBodyCell"),h=b("TableRow"),k=b("TBody"),B=b("TableWrapper"),$=b("pagination"),T=b("BottomPaginationWrapper");return u(),p("div",Me,[c("div",Ae,[e.filter&&e.topPagination?(u(),P(d,{key:0,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):C("",!0),c("div",Ee,[e.loading?y(e.$slots,"loading",{key:0},(()=>[f(o)])):C("",!0),e.showPagination?(u(),P(g,{key:1,"with-pagination":e.topPagination},{default:w((()=>[e.topPagination?(u(),P(i,{key:0,class:"dt-flex-1 dt-pr-4",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"])):C("",!0),e.filter&&!e.topPagination?(u(),P(d,{key:1,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):C("",!0),f(s,{value:e.tableQuery.per_page,options:e.perPageOptions,onInput:e.handleOnPaginationSizeChange},null,8,["value","options","onInput"])])),_:1},8,["with-pagination"])):C("",!0),f(B,null,{default:w((()=>[f(m,null,{default:w((()=>[e.sn?y(e.$slots,"thead-sn",{key:0},(()=>[f(v,{textContent:x("S.N.")},null,8,["textContent"])])):C("",!0),y(e.$slots,"thead",{column:e.tableColumns},(()=>[(u(!0),p(I,null,q(e.tableColumns,((e,t)=>(u(),P(v,{key:`datatable-thead-th-${t}`,textContent:x(e)},null,8,["textContent"])))),128))]))])),_:3}),f(k,null,{default:w((()=>[(u(!0),p(I,null,q(e.tableRows,((t,a)=>(u(),P(h,{key:`datatable-row-${e.uniqueId()}-${a}`,hoverable:e.hoverable,"non-clickable":e.nonClickable,"row-index":a,striped:e.striped,onClicked:a=>e.rowClickHandler(t)},{default:w((()=>[e.sn?y(e.$slots,"tbody-sn",{key:0,sn:a+1},(()=>[f(_,{textContent:x(a+1+e.paginatedRowIndex)},null,8,["textContent"])])):C("",!0),y(e.$slots,"tbody",{index:a,row:t},(()=>[(u(!0),p(I,null,q(e.tableColumns,((a,n)=>(u(),P(_,{key:`datatable-tbody-td-${e.uniqueId()}-${n}`,name:a,textContent:x(t[n])},null,8,["name","textContent"])))),128))]))])),_:2},1032,["hoverable","non-clickable","row-index","striped","onClicked"])))),128)),0===e.tableRows.length?(u(),P(h,{key:0,"row-index":0},{default:w((()=>[y(e.$slots,"empty")])),_:3})):C("",!0)])),_:3})])),_:3}),e.showPagination&&e.bottomPagination?(u(),P(T,{key:2},{default:w((()=>[f($,{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"])])),_:1})):C("",!0)])])])};export{Qe as DataTable,te as Pagination,ee as PaginationLink,Be as TableBody,Be as TableBodyCell,Te as TableHead,Te as TableHeadCell}; |
@@ -1,1 +0,1 @@ | ||
var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,n)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__spreadValues=(e,t)=>{for(var n in t||(t={}))__hasOwnProp.call(t,n)&&__defNormalProp(e,n,t[n]);if(__getOwnPropSymbols)for(var n of __getOwnPropSymbols(t))__propIsEnum.call(t,n)&&__defNormalProp(e,n,t[n]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));!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";var n=t.defineComponent({name:"SearchIcon"});const a={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},o=[t.createElementVNode("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)];n.render=function(e,n,r,l,d,i){return t.openBlock(),t.createElementBlock("svg",a,o)};var r=t.defineComponent({name:"SearchInput",props:{value:{type:String,required:!0}}});const l=["value"];r.render=function(e,n,a,o,r,d){return t.openBlock(),t.createElementBlock("input",t.mergeProps({value:e.value,type:"search",name:"search",class:"dt__filter__search dt-block dt-border dt-border-gray-300 dt-pr-10 dt-px-2 dt-py-2\n dt-rounded-md dt-w-full dt-outline-none focus:dt-ring-1 focus:dt-ring-inset sm:dt-text-sm"},e.$attrs),null,16,l)};var d=t.defineComponent({name:"Filter",components:{SearchInput:r,SearchIcon:n},props:{search:{type:String,required:!0}},emits:["input"]});const i={class:"dt__filter dt-mb-3 dt-w-full"},s={class:"dt-w-64"},c=t.createElementVNode("label",{for:"email",class:"dt-sr-only"},"Search",-1),p={class:"dt-relative dt-rounded-md dt-shadow-sm"},u={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"};d.render=function(e,n,a,o,r,l){const d=t.resolveComponent("SearchInput"),m=t.resolveComponent("SearchIcon");return t.openBlock(),t.createElementBlock("div",i,[t.createElementVNode("div",s,[c,t.createElementVNode("div",p,[t.createVNode(d,{value:e.search,onInput:n[0]||(n[0]=t=>e.$emit("input",t.target.value))},null,8,["value"]),t.createElementVNode("div",u,[t.createVNode(m,{class:"dt-text-gray-400"})])])])])};var m=t.defineComponent({name:"Loading"});t.pushScopeId("data-v-685865e4");const g={class:"dt__loading dt-absolute dt-h-full dt-w-full"},f=[t.createElementVNode("div",{class:"dt-flex dt-justify-center dt-items-center"},[t.createElementVNode("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"}),t.createElementVNode("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"})],-1)];t.popScopeId(),m.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("div",g,f)},m.__scopeId="data-v-685865e4";var _=t.defineComponent({name:"BottomPaginationWrapper"});const v={class:"dt__pagination_wrapper--bottom dt-bg-white dt-shadow-inner"},y={class:"dt-px-4 sm:dt-px-6 dt-py-4"};_.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("div",v,[t.createElementVNode("div",y,[t.renderSlot(e.$slots,"default")])])};var b=t.defineComponent({name:"PaginationButtons"});const h={class:"dt__pagination__nav dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"};b.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("nav",h,[t.renderSlot(e.$slots,"default")])};var k=t.defineComponent({name:"PaginationInfo"});const C={class:"dt__pagination__info"},P={class:"dt-text-sm dt-text-gray-700"};k.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("div",C,[t.createElementVNode("p",P,[t.renderSlot(e.$slots,"default")])])};var w=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"))})});w.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("a",t.mergeProps({href:"#",class:["dt__pagination__link 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(__spreadValues({},e.$attrs))),[t.renderSlot(e.$slots,"default")],16)};const x="left";var B=t.defineComponent({name:"Pagination",components:{PaginationButtons:b,PaginationInfo:k,PaginationLink:w},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:n}){const a=t.computed((()=>(e.currentPage-1)*e.perPage+1)),o=t.computed((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),r=t.computed((()=>Math.ceil(e.total/e.perPage))),l=t.computed((()=>1===e.currentPage?1:e.currentPage===r.value?r.value-e.maxVisibleButtons+1:e.currentPage-1)),d=t.computed((()=>Math.min(l.value+e.maxVisibleButtons-1,r.value))),i=t.computed((()=>{const e=[];for(let t=l.value;t<=d.value;t+=1)t>0&&e.push(t);return e})),s=t.computed((()=>1===e.currentPage)),c=t.computed((()=>e.currentPage===r.value)),p=e=>{n("changed",e)};return{currentStart:a,currentEnd:o,totalPages:r,pages:i,isInFirstPage:s,isInLastPage:c,goToPageNumber:p,gotoFirstPage:()=>p(1),gotoLastPage:()=>p(r.value),gotoNextPage:()=>p(e.currentPage>=r.value?r.value:e.currentPage+1),gotoPreviousPage:()=>p(e.currentPage<=1?1:e.currentPage-1),showDots:(e=x)=>{const t=e===x?1:r.value,n=e===x?2:r.value-1;return!i.value.includes(t)||!i.value.includes(n)}}}});const N={key:0,class:"dt__pagination dt-bg-white dt-flex dt-items-center dt-justify-between"},V={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},S=t.createTextVNode(" Showing "),E=["textContent"],T=t.createTextVNode(" to "),I=["textContent"],q=t.createTextVNode(" of "),$=["textContent"],O=t.createTextVNode(" results. "),D=t.createElementVNode("span",{class:"dt-sr-only"},"Go to first",-1),L=t.createTextVNode(" « "),j=t.createElementVNode("span",{class:"dt-sr-only"},"Previous",-1),F=t.createTextVNode(" ‹ "),M=t.createTextVNode(" 1 "),z=t.createTextVNode(" ... "),H=t.createTextVNode(" ... "),W=t.createElementVNode("span",{class:"dt-sr-only"},"Next",-1),Q=t.createTextVNode(" › "),R=t.createElementVNode("span",{class:"dt-sr-only"},"Go to Last",-1),A=t.createTextVNode(" » ");B.render=function(e,n,a,o,r,l){const d=t.resolveComponent("PaginationInfo"),i=t.resolveComponent("pagination-link"),s=t.resolveComponent("PaginationButtons");return e.totalPages?(t.openBlock(),t.createElementBlock("div",N,[t.createElementVNode("div",V,[e.total?(t.openBlock(),t.createBlock(d,{key:0},{default:t.withCtx((()=>[t.renderSlot(e.$slots,"pagination-info",{start:e.currentStart,end:e.currentEnd,total:e.total},(()=>[S,t.createElementVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentStart)},null,8,E),T,t.createElementVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentEnd)},null,8,I),q,t.createElementVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.total)},null,8,$),O]))])),_:3})):t.createCommentVNode("",!0),e.totalPages>1?(t.openBlock(),t.createBlock(s,{key:1},{default:t.withCtx((()=>[t.createVNode(i,{key:"page_first",disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[D,L])),_:1},8,["disabled","onClick"]),t.createVNode(i,{key:"page_previous",disabled:e.isInFirstPage,onClick:t.withModifiers(e.gotoPreviousPage,["prevent"])},{default:t.withCtx((()=>[j,F])),_:1},8,["disabled","onClick"]),e.showDots("left")?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createVNode(i,{key:"page_1",class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[M])),_:1},8,["disabled","active","onClick"]),t.createVNode(i,{key:"page_divider_left",class:"sm:dt-hidden"},{default:t.withCtx((()=>[z])),_:1})],64)):t.createCommentVNode("",!0),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.pages,(n=>(t.openBlock(),t.createBlock(i,{key:`pages_${n}`,class:"dt-hidden md:dt-inline-block",active:n===e.currentPage,disabled:n===e.currentPage,onClick:t.withModifiers((t=>e.goToPageNumber(n)),["prevent"])},{default:t.withCtx((()=>[t.createTextVNode(t.toDisplayString(n),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(t.openBlock(),t.createElementBlock(t.Fragment,{key:1},[t.createVNode(i,{key:"page_divider_right",class:"sm:dt-hidden"},{default:t.withCtx((()=>[H])),_:1}),t.createVNode(i,{key:`page_${e.totalPages}`,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(i,{key:"page_next",disabled:e.isInLastPage,onClick:t.withModifiers(e.gotoNextPage,["prevent"])},{default:t.withCtx((()=>[W,Q])),_:1},8,["disabled","onClick"]),t.createVNode(i,{key:"page_last",disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:t.withModifiers(e.gotoLastPage,["prevent"])},{default:t.withCtx((()=>[R,A])),_:1},8,["disabled","onClick"])])),_:1})):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)};var G=t.defineComponent({name:"PaginationSize",props:{value:{type:[Number,String],required:!0},options:{type:Array,required:!0}},emits:["input"]});const U={class:"dt__pagination_size_wrapper dt-w-full dt-flex dt-justify-end sm:dt-w-auto"},J=t.createElementVNode("label",{for:"location",class:"dt-sr-only"},"Per page",-1),K=["value"],X=["value","selected","textContent"];G.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("div",U,[t.createElementVNode("div",null,[J,t.createElementVNode("select",{value:e.value,name:"per_page",class:"dt__pagination_size dt-block dt-w-full dt-pl-3 dt-pr-5 dt-py-2 dt-text-base dt-border\n dt-border-gray-300 sm:dt-text-sm dt-rounded-md dt-outline-none focus:dt-ring-1 focus:dt-ring-inset",onInput:n[0]||(n[0]=t=>e.$emit("input",t.target.value))},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.options,(n=>(t.openBlock(),t.createElementBlock("option",{key:`per_page_${n}`,value:n,selected:n===e.value,textContent:t.toDisplayString(n)},null,8,X)))),128))],40,K)])])};var Y=t.defineComponent({name:"TopPaginationWrapper",props:{withPagination:{type:Boolean,required:!1,default:!1}}});Y.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["dt__pagination_wrapper--top md:dt-flex xs:dt-flex-col dt-items-center",{"dt-bg-white dt-py-4 dt-px-4 sm:dt-px-6":e.withPagination}])},[t.renderSlot(e.$slots,"default")],2)};var Z=t.defineComponent({name:"TableBodyCell"});const ee={class:"dt__table__tbody_td dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};Z.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("td",ee,[t.renderSlot(e.$slots,"default")])};var te=t.defineComponent({name:"TableHeadCell"});const ne={scope:"col",class:"dt__table__thead__th dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};te.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("th",ne,[t.renderSlot(e.$slots,"default")])};var ae=t.defineComponent({name:"TableRow",props:{rowIndex:{type:Number,required:!0},striped:{type:Boolean,required:!1,default:!1}}});ae.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("tr",{class:t.normalizeClass(["dt__table__row",e.striped&&e.rowIndex%2?"dt-bg-gray-50":"dt-bg-white"])},[t.renderSlot(e.$slots,"default")],2)};var oe=t.defineComponent({name:"TableWrapper"});const re={class:"dt__table_wrapper dt-overflow-auto"},le={class:"dt__table dt-min-w-full dt-divide-y dt-divide-gray-200"};oe.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("div",re,[t.createElementVNode("table",le,[t.renderSlot(e.$slots,"default")])])};var de=t.defineComponent({name:"TBody"});const ie={class:"dt__table__tbody"};de.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("tbody",ie,[t.renderSlot(e.$slots,"default")])};var se=t.defineComponent({name:"THead"});const ce={class:"dt__table__thead dt-bg-gray-50"},pe={class:"dt__table__thead__tr"};se.render=function(e,n,a,o,r,l){return t.openBlock(),t.createElementBlock("thead",ce,[t.createElementVNode("tr",pe,[t.renderSlot(e.$slots,"default")])])};const ue=[5,10,15,25,50,75,100],me=t.defineComponent({name:"DataTable",components:{TableHeadCell:te,TableBodyCell:Z,TBody:de,TableRow:ae,THead:se,BottomPaginationWrapper:_,TableWrapper:oe,PaginationSize:G,TopPaginationWrapper:Y,Filter:d,Loading:m,Pagination:B},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:()=>({})},topPagination:{type:Boolean,required:!1,default:!1},bottomPagination:{type:Boolean,required:!1,default:!0}},emits:["loadData"],setup(e,{emit:n}){var a,o;const r=t.ref({page:(null==(a=e.pagination)?void 0:a.page)||1,search:e.query.search||"",per_page:(null==(o=e.pagination)?void 0:o.per_page)||10}),l=t.computed((()=>!!e.pagination)),d=t.computed((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),i=t.computed((()=>e.rows)),s=t.computed((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>{return __spreadProps(__spreadValues({},e),{[t]:(n=t,n.toLowerCase().replace(/[-_]/g," ").split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" "))});var n}),{}))),c=t.computed((()=>l.value?r.value.per_page*(r.value.page-1):0));t.watch((()=>__spreadValues({},r.value)),(()=>{n("loadData",r.value)}),{deep:!0,immediate:!0});const p=((e,t=400)=>{let n;return(...a)=>{clearTimeout(n),n=setTimeout((()=>e(...a)),t)}})((e=>{r.value=__spreadProps(__spreadValues({},r.value),{page:1,search:e})}));return{tableQuery:r,showPagination:l,totalData:d,tableRows:i,tableColumns:s,paginatedRowIndex:c,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{r.value.page=e},handleOnSearchChange:p,handleOnPaginationSizeChange:e=>{r.value=__spreadProps(__spreadValues({},r.value),{page:1,per_page:e})}}}});const ge={class:"data-table dt-flex dt-flex-col"},fe={class:"dt-align-middle dt-min-w-full"},_e={class:"dt__wrapper dt-relative dt-overflow-hidden sm:dt-rounded-lg"};me.render=function(e,n,a,o,r,l){const d=t.resolveComponent("Filter"),i=t.resolveComponent("Loading"),s=t.resolveComponent("Pagination"),c=t.resolveComponent("PaginationSize"),p=t.resolveComponent("TopPaginationWrapper"),u=t.resolveComponent("TableHeadCell"),m=t.resolveComponent("THead"),g=t.resolveComponent("TableBodyCell"),f=t.resolveComponent("TableRow"),_=t.resolveComponent("TBody"),v=t.resolveComponent("TableWrapper"),y=t.resolveComponent("pagination"),b=t.resolveComponent("BottomPaginationWrapper");return t.openBlock(),t.createElementBlock("div",ge,[t.createElementVNode("div",fe,[e.filter&&e.topPagination?(t.openBlock(),t.createBlock(d,{key:0,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):t.createCommentVNode("",!0),t.createElementVNode("div",_e,[e.loading?t.renderSlot(e.$slots,"loading",{key:0},(()=>[t.createVNode(i)])):t.createCommentVNode("",!0),e.showPagination?(t.openBlock(),t.createBlock(p,{key:1,"with-pagination":e.topPagination},{default:t.withCtx((()=>[e.topPagination?(t.openBlock(),t.createBlock(s,{key:0,class:"dt-flex-1 dt-pr-4",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),e.filter&&!e.topPagination?(t.openBlock(),t.createBlock(d,{key:1,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):t.createCommentVNode("",!0),t.createVNode(c,{value:e.tableQuery.per_page,options:e.perPageOptions,onInput:e.handleOnPaginationSizeChange},null,8,["value","options","onInput"])])),_:1},8,["with-pagination"])):t.createCommentVNode("",!0),t.createVNode(v,null,{default:t.withCtx((()=>[t.createVNode(m,null,{default:t.withCtx((()=>[e.sn?t.renderSlot(e.$slots,"thead-sn",{key:0},(()=>[t.createVNode(u,{textContent:t.toDisplayString("S.N.")},null,8,["textContent"])])):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"thead",{column:e.tableColumns},(()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.tableColumns,((e,n)=>(t.openBlock(),t.createBlock(u,{key:`datatable-thead-th-${n}`,textContent:t.toDisplayString(e)},null,8,["textContent"])))),128))]))])),_:3}),t.createVNode(_,null,{default:t.withCtx((()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.tableRows,((n,a)=>(t.openBlock(),t.createBlock(f,{key:`datatable-row-${e.uniqueId()}-${a}`,"row-index":a,striped:e.striped},{default:t.withCtx((()=>[e.sn?t.renderSlot(e.$slots,"tbody-sn",{key:0,sn:a+1},(()=>[t.createVNode(g,{textContent:t.toDisplayString(a+1+e.paginatedRowIndex)},null,8,["textContent"])])):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"tbody",{index:a,row:n},(()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.tableColumns,((a,o)=>(t.openBlock(),t.createBlock(g,{key:`datatable-tbody-td-${e.uniqueId()}-${o}`,name:a,textContent:t.toDisplayString(n[o])},null,8,["name","textContent"])))),128))]))])),_:2},1032,["row-index","striped"])))),128))])),_:3})])),_:3}),e.showPagination&&e.bottomPagination?(t.openBlock(),t.createBlock(b,{key:2},{default:t.withCtx((()=>[t.createVNode(y,{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"])])),_:1})):t.createCommentVNode("",!0)])])])},e.DataTable=me,e.Pagination=B,e.PaginationLink=w,e.TableBody=Z,e.TableBodyCell=Z,e.TableHead=te,e.TableHeadCell=te,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); | ||
var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));!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";var o=t.defineComponent({name:"SearchIcon"});const n={xmlns:"http://www.w3.org/2000/svg",class:"dt-h-5 dt-w-5",viewBox:"0 0 20 20",fill:"currentColor"},a=[t.createElementVNode("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)];o.render=function(e,o,r,l,d,i){return t.openBlock(),t.createElementBlock("svg",n,a)};var r=t.defineComponent({name:"SearchInput",props:{value:{type:String,required:!0}}});const l=["value"];r.render=function(e,o,n,a,r,d){return t.openBlock(),t.createElementBlock("input",t.mergeProps({value:e.value,type:"search",name:"search",class:"dt__filter__search dt-block dt-border dt-border-gray-300 dt-pr-10 dt-px-2 dt-py-2\n dt-rounded-md dt-w-full dt-outline-none focus:dt-ring-1 focus:dt-ring-inset sm:dt-text-sm"},e.$attrs),null,16,l)};var d=t.defineComponent({name:"Filter",components:{SearchInput:r,SearchIcon:o},props:{search:{type:String,required:!0}},emits:["input"]});const i={class:"dt__filter dt-mb-3 dt-w-full"},s={class:"dt-w-64"},c=t.createElementVNode("label",{for:"email",class:"dt-sr-only"},"Search",-1),p={class:"dt-relative dt-rounded-md dt-shadow-sm"},u={class:"dt-absolute dt-inset-y-0 dt-right-0 dt-pr-3 dt-flex dt-items-center dt-pointer-events-none"};d.render=function(e,o,n,a,r,l){const d=t.resolveComponent("SearchInput"),m=t.resolveComponent("SearchIcon");return t.openBlock(),t.createElementBlock("div",i,[t.createElementVNode("div",s,[c,t.createElementVNode("div",p,[t.createVNode(d,{value:e.search,onInput:o[0]||(o[0]=t=>e.$emit("input",t.target.value))},null,8,["value"]),t.createElementVNode("div",u,[t.createVNode(m,{class:"dt-text-gray-400"})])])])])};var m=t.defineComponent({name:"Loading"});t.pushScopeId("data-v-685865e4");const g={class:"dt__loading dt-absolute dt-h-full dt-w-full"},f=[t.createElementVNode("div",{class:"dt-flex dt-justify-center dt-items-center"},[t.createElementVNode("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"}),t.createElementVNode("div",{class:"dt__loading_item dt-absolute dt-w-20 dt-h-20 dt-rounded-full"})],-1)];t.popScopeId(),m.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("div",g,f)},m.__scopeId="data-v-685865e4";var _=t.defineComponent({name:"BottomPaginationWrapper"});const v={class:"dt__pagination_wrapper--bottom dt-bg-white dt-shadow-inner"},b={class:"dt-px-4 sm:dt-px-6 dt-py-4"};_.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("div",v,[t.createElementVNode("div",b,[t.renderSlot(e.$slots,"default")])])};var y=t.defineComponent({name:"PaginationButtons"});const h={class:"dt__pagination__nav dt-relative dt-z-0 dt-inline-flex dt-rounded-md dt-shadow-sm dt--space-x-px","aria-label":"Pagination"};y.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("nav",h,[t.renderSlot(e.$slots,"default")])};var k=t.defineComponent({name:"PaginationInfo"});const C={class:"dt__pagination__info"},P={class:"dt-text-sm dt-text-gray-700"};k.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("div",C,[t.createElementVNode("p",P,[t.renderSlot(e.$slots,"default")])])};var w=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"))})});w.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("a",t.mergeProps({href:"#",class:["dt__pagination__link 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(__spreadValues({},e.$attrs))),[t.renderSlot(e.$slots,"default")],16)};const x="left";var B=t.defineComponent({name:"Pagination",components:{PaginationButtons:y,PaginationInfo:k,PaginationLink:w},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:o}){const n=t.computed((()=>(e.currentPage-1)*e.perPage+1)),a=t.computed((()=>e.total>e.currentPage*e.perPage?e.currentPage*e.perPage:e.total)),r=t.computed((()=>Math.ceil(e.total/e.perPage))),l=t.computed((()=>1===e.currentPage?1:e.currentPage===r.value?r.value-e.maxVisibleButtons+1:e.currentPage-1)),d=t.computed((()=>Math.min(l.value+e.maxVisibleButtons-1,r.value))),i=t.computed((()=>{const e=[];for(let t=l.value;t<=d.value;t+=1)t>0&&e.push(t);return e})),s=t.computed((()=>1===e.currentPage)),c=t.computed((()=>e.currentPage===r.value)),p=e=>{o("changed",e)};return{currentStart:n,currentEnd:a,totalPages:r,pages:i,isInFirstPage:s,isInLastPage:c,goToPageNumber:p,gotoFirstPage:()=>p(1),gotoLastPage:()=>p(r.value),gotoNextPage:()=>p(e.currentPage>=r.value?r.value:e.currentPage+1),gotoPreviousPage:()=>p(e.currentPage<=1?1:e.currentPage-1),showDots:(e=x)=>{const t=e===x?1:r.value,o=e===x?2:r.value-1;return!i.value.includes(t)||!i.value.includes(o)}}}});const N={key:0,class:"dt__pagination dt-bg-white dt-flex dt-items-center dt-justify-between"},V={class:"dt-hidden sm:dt-flex-1 sm:dt-flex sm:dt-items-center sm:dt-justify-between"},S=t.createTextVNode(" Showing "),E=["textContent"],T=t.createTextVNode(" to "),I=["textContent"],q=t.createTextVNode(" of "),$=["textContent"],O=t.createTextVNode(" results. "),D=t.createElementVNode("span",{class:"dt-sr-only"},"Go to first",-1),L=t.createTextVNode(" « "),j=t.createElementVNode("span",{class:"dt-sr-only"},"Previous",-1),F=t.createTextVNode(" ‹ "),M=t.createTextVNode(" 1 "),z=t.createTextVNode(" ... "),H=t.createTextVNode(" ... "),R=t.createElementVNode("span",{class:"dt-sr-only"},"Next",-1),W=t.createTextVNode(" › "),Q=t.createElementVNode("span",{class:"dt-sr-only"},"Go to Last",-1),A=t.createTextVNode(" » ");B.render=function(e,o,n,a,r,l){const d=t.resolveComponent("PaginationInfo"),i=t.resolveComponent("pagination-link"),s=t.resolveComponent("PaginationButtons");return e.totalPages?(t.openBlock(),t.createElementBlock("div",N,[t.createElementVNode("div",V,[e.total?(t.openBlock(),t.createBlock(d,{key:0},{default:t.withCtx((()=>[t.renderSlot(e.$slots,"pagination-info",{start:e.currentStart,end:e.currentEnd,total:e.total},(()=>[S,t.createElementVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentStart)},null,8,E),T,t.createElementVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.currentEnd)},null,8,I),q,t.createElementVNode("span",{class:"dt-font-medium",textContent:t.toDisplayString(e.total)},null,8,$),O]))])),_:3})):t.createCommentVNode("",!0),e.totalPages>1?(t.openBlock(),t.createBlock(s,{key:1},{default:t.withCtx((()=>[t.createVNode(i,{key:"page_first",disabled:e.isInFirstPage,class:"dt-rounded-l-md",onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[D,L])),_:1},8,["disabled","onClick"]),t.createVNode(i,{key:"page_previous",disabled:e.isInFirstPage,onClick:t.withModifiers(e.gotoPreviousPage,["prevent"])},{default:t.withCtx((()=>[j,F])),_:1},8,["disabled","onClick"]),e.showDots("left")?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createVNode(i,{key:"page_1",class:"dt-block sm:dt-hidden",disabled:e.isInFirstPage,active:e.isInFirstPage,onClick:t.withModifiers(e.gotoFirstPage,["prevent"])},{default:t.withCtx((()=>[M])),_:1},8,["disabled","active","onClick"]),t.createVNode(i,{key:"page_divider_left",class:"sm:dt-hidden"},{default:t.withCtx((()=>[z])),_:1})],64)):t.createCommentVNode("",!0),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.pages,(o=>(t.openBlock(),t.createBlock(i,{key:`pages_${o}`,class:"dt-hidden md:dt-inline-block",active:o===e.currentPage,disabled:o===e.currentPage,onClick:t.withModifiers((t=>e.goToPageNumber(o)),["prevent"])},{default:t.withCtx((()=>[t.createTextVNode(t.toDisplayString(o),1)])),_:2},1032,["active","disabled","onClick"])))),128)),e.showDots("right")?(t.openBlock(),t.createElementBlock(t.Fragment,{key:1},[t.createVNode(i,{key:"page_divider_right",class:"sm:dt-hidden"},{default:t.withCtx((()=>[H])),_:1}),t.createVNode(i,{key:`page_${e.totalPages}`,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(i,{key:"page_next",disabled:e.isInLastPage,onClick:t.withModifiers(e.gotoNextPage,["prevent"])},{default:t.withCtx((()=>[R,W])),_:1},8,["disabled","onClick"]),t.createVNode(i,{key:"page_last",disabled:e.isInLastPage,class:"dt-rounded-r-md",onClick:t.withModifiers(e.gotoLastPage,["prevent"])},{default:t.withCtx((()=>[Q,A])),_:1},8,["disabled","onClick"])])),_:1})):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)};var G=t.defineComponent({name:"PaginationSize",props:{value:{type:[Number,String],required:!0},options:{type:Array,required:!0}},emits:["input"]});const U={class:"dt__pagination_size_wrapper dt-w-full dt-flex dt-justify-end sm:dt-w-auto"},J=t.createElementVNode("label",{for:"location",class:"dt-sr-only"},"Per page",-1),K=["value"],X=["value","selected","textContent"];G.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("div",U,[t.createElementVNode("div",null,[J,t.createElementVNode("select",{value:e.value,name:"per_page",class:"dt__pagination_size dt-block dt-w-full dt-pl-3 dt-pr-5 dt-py-2 dt-text-base dt-border\n dt-border-gray-300 sm:dt-text-sm dt-rounded-md dt-outline-none focus:dt-ring-1 focus:dt-ring-inset",onInput:o[0]||(o[0]=t=>e.$emit("input",t.target.value))},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.options,(o=>(t.openBlock(),t.createElementBlock("option",{key:`per_page_${o}`,value:o,selected:o===e.value,textContent:t.toDisplayString(o)},null,8,X)))),128))],40,K)])])};var Y=t.defineComponent({name:"TopPaginationWrapper",props:{withPagination:{type:Boolean,required:!1,default:!1}}});Y.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["dt__pagination_wrapper--top md:dt-flex xs:dt-flex-col dt-items-center",{"dt-bg-white dt-py-4 dt-px-4 sm:dt-px-6":e.withPagination}])},[t.renderSlot(e.$slots,"default")],2)};var Z=t.defineComponent({name:"TableBodyCell"});const ee={class:"dt__table__tbody_td dt-px-6 dt-py-4 dt-whitespace-nowrap dt-text-sm dt-font-medium dt-text-gray-500"};Z.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("td",ee,[t.renderSlot(e.$slots,"default")])};var te=t.defineComponent({name:"TableHeadCell"});const oe={scope:"col",class:"dt__table__thead__th dt-px-6 dt-py-3 dt-text-left dt-text-xs dt-font-medium dt-text-gray-500 dt-uppercase dt-tracking-wider"};te.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("th",oe,[t.renderSlot(e.$slots,"default")])};var ne=t.defineComponent({name:"TableRow",props:{rowIndex:{type:[Number,String],required:!1,default:0},striped:{type:Boolean,required:!1,default:!1},hoverable:{type:Boolean,required:!1,default:!1},nonClickable:{type:Boolean,required:!1,default:!1}},emits:["clicked"],setup:e=>({formattedRowIndex:t.ref(parseInt(e.rowIndex)||0)})});ne.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("tr",{class:t.normalizeClass(["dt__table__row",{"dt-bg-white":!e.striped||e.striped&&e.formattedRowIndex%2==0,"dt-bg-gray-50":e.striped&&e.formattedRowIndex%2,"hover:dt-bg-gray-100":e.hoverable,"dt-cursor-pointer":e.hoverable&&!e.nonClickable}]),onClick:o[0]||(o[0]=t.withModifiers((t=>e.$emit("clicked")),["stop"]))},[t.renderSlot(e.$slots,"default")],2)};var ae=t.defineComponent({name:"TableWrapper"});const re={class:"dt__table_wrapper dt-overflow-auto"},le={class:"dt__table dt-min-w-full dt-divide-y dt-divide-gray-200"};ae.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("div",re,[t.createElementVNode("table",le,[t.renderSlot(e.$slots,"default")])])};var de=t.defineComponent({name:"TBody"});const ie={class:"dt__table__tbody"};de.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("tbody",ie,[t.renderSlot(e.$slots,"default")])};var se=t.defineComponent({name:"THead"});const ce={class:"dt__table__thead dt-bg-gray-50"},pe={class:"dt__table__thead__tr"};se.render=function(e,o,n,a,r,l){return t.openBlock(),t.createElementBlock("thead",ce,[t.createElementVNode("tr",pe,[t.renderSlot(e.$slots,"default")])])};const ue=[5,10,15,25,50,75,100],me=t.defineComponent({name:"DataTable",components:{TableHeadCell:te,TableBodyCell:Z,TBody:de,TableRow:ne,THead:se,BottomPaginationWrapper:_,TableWrapper:ae,PaginationSize:G,TopPaginationWrapper:Y,Filter:d,Loading:m,Pagination:B},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:()=>({})},topPagination:{type:Boolean,required:!1,default:!1},bottomPagination:{type:Boolean,required:!1,default:!0},hoverable:{type:Boolean,required:!1,default:!1},nonClickable:{type:Boolean,required:!1,default:!1}},emits:["loadData","rowClicked"],setup(e,{emit:o}){var n,a;const r=t.ref({page:(null==(n=e.pagination)?void 0:n.page)||1,search:e.query.search||"",per_page:(null==(a=e.pagination)?void 0:a.per_page)||10}),l=t.computed((()=>!!e.pagination)),d=t.computed((()=>{var t;return(null==(t=e.pagination)?void 0:t.total)||e.rows.length})),i=t.computed((()=>e.rows)),s=t.computed((()=>e.columns?e.columns:0===e.rows.length?{}:Object.keys(e.rows[0]).reduce(((e,t)=>{return __spreadProps(__spreadValues({},e),{[t]:(o=t,o.toLowerCase().replace(/[-_]/g," ").split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" "))});var o}),{}))),c=t.computed((()=>l.value?r.value.per_page*(r.value.page-1):0));t.watch((()=>__spreadValues({},r.value)),(()=>{o("loadData",r.value)}),{deep:!0,immediate:!0});const p=((e,t=400)=>{let o;return(...n)=>{clearTimeout(o),o=setTimeout((()=>e(...n)),t)}})((e=>{r.value=__spreadProps(__spreadValues({},r.value),{page:1,search:e})}));return{tableQuery:r,showPagination:l,totalData:d,tableRows:i,tableColumns:s,paginatedRowIndex:c,uniqueId:()=>Math.floor(100*Math.random()),handlePageChange:e=>{r.value.page=e},handleOnSearchChange:p,handleOnPaginationSizeChange:e=>{r.value=__spreadProps(__spreadValues({},r.value),{page:1,per_page:e})},rowClickHandler:t=>{!e.nonClickable&&e.hoverable&&o("rowClicked",t)}}}});const ge={class:"data-table dt-flex dt-flex-col"},fe={class:"dt-align-middle dt-min-w-full"},_e={class:"dt__wrapper dt-relative dt-overflow-hidden sm:dt-rounded-lg"};me.render=function(e,o,n,a,r,l){const d=t.resolveComponent("Filter"),i=t.resolveComponent("Loading"),s=t.resolveComponent("Pagination"),c=t.resolveComponent("PaginationSize"),p=t.resolveComponent("TopPaginationWrapper"),u=t.resolveComponent("TableHeadCell"),m=t.resolveComponent("THead"),g=t.resolveComponent("TableBodyCell"),f=t.resolveComponent("TableRow"),_=t.resolveComponent("TBody"),v=t.resolveComponent("TableWrapper"),b=t.resolveComponent("pagination"),y=t.resolveComponent("BottomPaginationWrapper");return t.openBlock(),t.createElementBlock("div",ge,[t.createElementVNode("div",fe,[e.filter&&e.topPagination?(t.openBlock(),t.createBlock(d,{key:0,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):t.createCommentVNode("",!0),t.createElementVNode("div",_e,[e.loading?t.renderSlot(e.$slots,"loading",{key:0},(()=>[t.createVNode(i)])):t.createCommentVNode("",!0),e.showPagination?(t.openBlock(),t.createBlock(p,{key:1,"with-pagination":e.topPagination},{default:t.withCtx((()=>[e.topPagination?(t.openBlock(),t.createBlock(s,{key:0,class:"dt-flex-1 dt-pr-4",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),e.filter&&!e.topPagination?(t.openBlock(),t.createBlock(d,{key:1,search:e.tableQuery.search,onInput:e.handleOnSearchChange},null,8,["search","onInput"])):t.createCommentVNode("",!0),t.createVNode(c,{value:e.tableQuery.per_page,options:e.perPageOptions,onInput:e.handleOnPaginationSizeChange},null,8,["value","options","onInput"])])),_:1},8,["with-pagination"])):t.createCommentVNode("",!0),t.createVNode(v,null,{default:t.withCtx((()=>[t.createVNode(m,null,{default:t.withCtx((()=>[e.sn?t.renderSlot(e.$slots,"thead-sn",{key:0},(()=>[t.createVNode(u,{textContent:t.toDisplayString("S.N.")},null,8,["textContent"])])):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"thead",{column:e.tableColumns},(()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.tableColumns,((e,o)=>(t.openBlock(),t.createBlock(u,{key:`datatable-thead-th-${o}`,textContent:t.toDisplayString(e)},null,8,["textContent"])))),128))]))])),_:3}),t.createVNode(_,null,{default:t.withCtx((()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.tableRows,((o,n)=>(t.openBlock(),t.createBlock(f,{key:`datatable-row-${e.uniqueId()}-${n}`,hoverable:e.hoverable,"non-clickable":e.nonClickable,"row-index":n,striped:e.striped,onClicked:t=>e.rowClickHandler(o)},{default:t.withCtx((()=>[e.sn?t.renderSlot(e.$slots,"tbody-sn",{key:0,sn:n+1},(()=>[t.createVNode(g,{textContent:t.toDisplayString(n+1+e.paginatedRowIndex)},null,8,["textContent"])])):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"tbody",{index:n,row:o},(()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.tableColumns,((n,a)=>(t.openBlock(),t.createBlock(g,{key:`datatable-tbody-td-${e.uniqueId()}-${a}`,name:n,textContent:t.toDisplayString(o[a])},null,8,["name","textContent"])))),128))]))])),_:2},1032,["hoverable","non-clickable","row-index","striped","onClicked"])))),128)),0===e.tableRows.length?(t.openBlock(),t.createBlock(f,{key:0,"row-index":0},{default:t.withCtx((()=>[t.renderSlot(e.$slots,"empty")])),_:3})):t.createCommentVNode("",!0)])),_:3})])),_:3}),e.showPagination&&e.bottomPagination?(t.openBlock(),t.createBlock(y,{key:2},{default:t.withCtx((()=>[t.createVNode(b,{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"])])),_:1})):t.createCommentVNode("",!0)])])])},e.DataTable=me,e.Pagination=B,e.PaginationLink=w,e.TableBody=Z,e.TableBodyCell=Z,e.TableHead=te,e.TableHeadCell=te,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); |
{ | ||
"name": "@jobinsjp/vue3-datatable", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "DataTable component with basic pagination, search filters etc for Vue3", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
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
56474
200