UNPKG

@sebastiandotdev/vue3-datatable

Version:

Vue3 Datatable - fully customizable & easy to use datatable library

2 lines (1 loc) 31.2 kB
"use strict";const e=require("vue"),Be={class:"bh-filter-menu bh-absolute bh-z-[1] bh-bg-white bh-shadow-md bh-rounded-md bh-top-full bh-right-0 bh-w-32 bh-mt-1"},Ne=e.defineComponent({__name:"column-filter",props:{columnFilterLang:{default:()=>({no_filter:"No filter",contain:"Contain",not_contain:"Not contain",equal:"Equal",not_equal:"Not equal",start_with:"Starts with",end_with:"Ends with",greater_than:"Greater than",greater_than_equal:"Greater than or equal",less_than:"Less than",less_than_equal:"Less than or equal",is_null:"Is null",is_not_null:"Not null"})},column:{}},emits:["close","filterChange"],setup(_,{emit:p}){const r=_;e.onBeforeUnmount(()=>{document.removeEventListener("click",n)}),e.onMounted(()=>{document.addEventListener("click",n)});const v=p,n=()=>{v("close")},c=C=>{r.column.condition=C,C===""&&(r.column.value=""),v("filterChange",r.column)};return(C,a)=>(e.openBlock(),e.createElementBlock("div",Be,[e.createElementVNode("div",{class:"bh-text-[13px] bh-font-normal bh-rounded bh-overflow-hidden",onClick:e.withModifiers(n,["stop"])},[e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition===""}),onClick:a[0]||(a[0]=u=>c(""))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.no_filter)??"No filter"),3),r.column.type==="string"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="contain"}),onClick:a[1]||(a[1]=u=>c("contain"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.contain)??"Contain"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="not_contain"}),onClick:a[2]||(a[2]=u=>c("not_contain"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.not_contain)??"Not contain"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="equal"}),onClick:a[3]||(a[3]=u=>c("equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.equal)??"Equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="not_equal"}),onClick:a[4]||(a[4]=u=>c("not_equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.not_equal)??"Not equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="start_with"}),onClick:a[5]||(a[5]=u=>c("start_with"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.start_with)??"Starts with"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="end_with"}),onClick:a[6]||(a[6]=u=>c("end_with"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.end_with)??"Ends with"),3)],64)):r.column.type==="number"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="equal"}),onClick:a[7]||(a[7]=u=>c("equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.equal)??"Equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="not_equal"}),onClick:a[8]||(a[8]=u=>c("not_equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.not_equal)??"Not equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="greater_than"}),onClick:a[9]||(a[9]=u=>c("greater_than"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.greater_than)??"Greater than"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="greater_than_equal"}),onClick:a[10]||(a[10]=u=>c("greater_than_equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.greater_than_equal)??"Greater than or equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="less_than"}),onClick:a[11]||(a[11]=u=>c("less_than"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.less_than)??"Less than"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="less_than_equal"}),onClick:a[12]||(a[12]=u=>c("less_than_equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.less_than_equal)??"Less than or equal"),3)],64)):r.column.type==="date"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="equal"}),onClick:a[13]||(a[13]=u=>c("equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.equal)??"Equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="not_equal"}),onClick:a[14]||(a[14]=u=>c("not_equal"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.not_equal)??"Not equal"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="greater_than"}),onClick:a[15]||(a[15]=u=>c("greater_than"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.greater_than)??"Greater than"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="less_than"}),onClick:a[16]||(a[16]=u=>c("less_than"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.less_than)??"Less than"),3)],64)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="is_null"}),onClick:a[17]||(a[17]=u=>c("is_null"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.is_null)??"Is null"),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({active:r.column.condition==="is_not_null"}),onClick:a[18]||(a[18]=u=>c("is_not_null"))},e.toDisplayString((r.columnFilterLang&&r.columnFilterLang.is_not_null)??"Not null"),3)])]))}}),R=(_,p)=>{const r=_.__vccOpts||_;for(const[v,n]of p)r[v]=n;return r},Ee={},Fe={version:"1.1",viewBox:"0 0 17 12",xmlns:"http://www.w3.org/2000/svg"};function Se(_,p){return e.openBlock(),e.createElementBlock("svg",Fe,p[0]||(p[0]=[e.createElementVNode("g",{fill:"none","fill-rule":"evenodd"},[e.createElementVNode("g",{transform:"translate(-9 -11)",fill:"currentColor","fill-rule":"nonzero"},[e.createElementVNode("path",{d:"m25.576 11.414c0.56558 0.55188 0.56558 1.4439 0 1.9961l-9.404 9.176c-0.28213 0.27529-0.65247 0.41385-1.0228 0.41385-0.37034 0-0.74068-0.13855-1.0228-0.41385l-4.7019-4.588c-0.56584-0.55188-0.56584-1.4442 0-1.9961 0.56558-0.55214 1.4798-0.55214 2.0456 0l3.679 3.5899 8.3812-8.1779c0.56558-0.55214 1.4798-0.55214 2.0456 0z"})])],-1)]))}const ne=R(Ee,[["render",Se]]),Ve={},Le={viewBox:"0 0 24 24",width:"24",height:"24",stroke:"currentColor","stroke-width":"3",fill:"none","stroke-linecap":"round","stroke-linejoin":"round",class:"css-i6dzq1"};function ze(_,p){return e.openBlock(),e.createElementBlock("svg",Le,p[0]||(p[0]=[e.createElementVNode("line",{x1:"5",y1:"12",x2:"19",y2:"12"},null,-1)]))}const qe=R(Ve,[["render",ze]]),xe={},$e={viewBox:"0 0 24 24",width:"24",height:"24",stroke:"currentColor","stroke-width":"1.5",fill:"none","stroke-linecap":"round","stroke-linejoin":"round",class:"css-i6dzq1"};function Me(_,p){return e.openBlock(),e.createElementBlock("svg",$e,p[0]||(p[0]=[e.createElementVNode("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"},null,-1)]))}const De=R(xe,[["render",Me]]),Ae={key:"hdrrow"},Re={class:"bh-checkbox"},Te=["onClick"],Oe={width:"16",height:"16",viewBox:"0 0 14 14",fill:"none"},Pe={key:0,class:"bh-filter bh-relative"},He=["onUpdate:modelValue"],Ue=["onUpdate:modelValue"],Ie=["onUpdate:modelValue"],Ge=["onUpdate:modelValue"],Ke=["onClick"],le=e.defineComponent({__name:"column-header",props:{all:{},currentSortColumn:{},currentSortDirection:{},isOpenFilter:{},isFooter:{type:Boolean},checkAll:{type:[Number,null,Boolean]},columnFilterLang:{}},emits:["selectAll","sortChange","filterChange","toggleFilterMenu"],setup(_,{emit:p}){const r=e.ref(null),v=_,n=e.ref(v.isOpenFilter),c=p,C=()=>{r.value&&(r.value.indeterminate=v.checkAll!==0?!v.checkAll:!1,r.value.checked=v.checkAll)};return e.watch(()=>v.checkAll,C),(a,u)=>(e.openBlock(),e.createElementBlock("tr",Ae,[v.all.hasCheckbox?(e.openBlock(),e.createElementBlock("th",{key:"chkall",class:e.normalizeClass(["bh-w-px",{"bh-sticky bh-bg-blue-light bh-z-[1]":v.all.stickyHeader||v.all.stickyFirstColumn,"bh-top-0":v.all.stickyHeader,"bh-left-0":v.all.stickyFirstColumn}])},[e.createElementVNode("div",Re,[e.createElementVNode("input",{ref_key:"selectedAll",ref:r,type:"checkbox",onClick:u[0]||(u[0]=e.withModifiers(d=>{var y;return c("selectAll",(y=d.target)==null?void 0:y.checked)},["stop"]))},null,512),e.createElementVNode("div",null,[e.createVNode(ne,{class:"check"}),e.createVNode(qe,{class:"intermediate"})])])],2)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(v.all.columns,(d,y)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[d.hide?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("th",{key:d.field,class:e.normalizeClass(["bh-select-none bh-z-[1]",[v.all.sortable&&d.sort?"bh-cursor-pointer":"",y===0&&v.all.stickyFirstColumn?"bh-sticky bh-left-0 bh-bg-blue-light":"",v.all.hasCheckbox&&y===0&&v.all.stickyFirstColumn?"bh-left-[52px]":""]]),style:e.normalizeStyle({width:d.width,"min-width":d.minWidth,"max-width":d.maxWidth})},[e.createElementVNode("div",{class:e.normalizeClass(["bh-flex bh-items-center",[d.headerClass?d.headerClass:""]]),onClick:k=>v.all.sortable&&d.sort&&c("sortChange",d.field)},[e.createTextVNode(e.toDisplayString(d.title)+" ",1),v.all.sortable&&d.sort?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(["bh-ml-3 bh-sort bh-flex bh-items-center",[v.currentSortColumn,v.currentSortDirection]])},[(e.openBlock(),e.createElementBlock("svg",Oe,[e.createElementVNode("polygon",{points:"3.11,6.25 10.89,6.25 7,1.75 ",fill:"currentColor",class:e.normalizeClass(["bh-text-black/20",[a.currentSortColumn===d.field&&a.currentSortDirection==="asc"?"!bh-text-primary":""]])},null,2),e.createElementVNode("polygon",{points:"7,12.25 10.89,7.75 3.11,7.75 ",fill:"currentColor",class:e.normalizeClass(["bh-text-black/20",[a.currentSortColumn===d.field&&a.currentSortDirection==="desc"?"!bh-text-primary":""]])},null,2)]))],2)):e.createCommentVNode("",!0)],10,Te),v.all.columnFilter&&!v.isFooter?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[d.filter?(e.openBlock(),e.createElementBlock("div",Pe,[d.type==="string"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:0,"onUpdate:modelValue":k=>d.value=k,type:"text",class:"bh-form-control",onKeyup:u[1]||(u[1]=k=>c("filterChange"))},null,40,He)),[[e.vModelText,d.value,void 0,{trim:!0}]]):e.createCommentVNode("",!0),d.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,"onUpdate:modelValue":k=>d.value=k,type:"number",class:"bh-form-control",onKeyup:u[2]||(u[2]=k=>c("filterChange"))},null,40,Ue)),[[e.vModelText,d.value,void 0,{number:!0,trim:!0}]]):d.type==="date"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,"onUpdate:modelValue":k=>d.value=k,type:"date",class:"bh-form-control",onChange:u[3]||(u[3]=k=>c("filterChange"))},null,40,Ie)),[[e.vModelText,d.value]]):d.type==="bool"?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:3,"onUpdate:modelValue":k=>d.value=k,class:"bh-form-control",onChange:u[4]||(u[4]=k=>c("filterChange")),onClick:u[5]||(u[5]=k=>n.value=null)},u[8]||(u[8]=[e.createElementVNode("option",{value:void 0},"All",-1),e.createElementVNode("option",{value:!0},"True",-1),e.createElementVNode("option",{value:!1},"False",-1)]),40,Ge)),[[e.vModelSelect,d.value]]):e.createCommentVNode("",!0),d.type!=="bool"?(e.openBlock(),e.createElementBlock("button",{key:4,type:"button",onClick:e.withModifiers(k=>c("toggleFilterMenu",d),["stop"])},[e.createVNode(De,{class:"bh-w-4"})],8,Ke)):e.createCommentVNode("",!0),e.withDirectives(e.createVNode(Ne,{column:d,type:d.type,columnFilterLang:v.columnFilterLang,onClose:u[6]||(u[6]=k=>c("toggleFilterMenu",null)),onFilterChange:u[7]||(u[7]=k=>c("filterChange"))},null,8,["column","type","columnFilterLang"]),[[e.vShow,n.value===d.field]])])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0)],6))],64))),256))]))}}),Je={},We={width:"84",height:"84",viewBox:"0 0 24 24",class:"bh-loader bh-text-primary"};function Ye(_,p){return e.openBlock(),e.createElementBlock("svg",We,p[0]||(p[0]=[e.createStaticVNode('<circle cx="18" cy="12" r="0" fill="currentColor"><animate attributeName="r" begin=".67" calcMode="spline" dur="1.5s" keySplines="0.2 0.2 0.4 0.8;0.2 0.2 0.4 0.8;0.2 0.2 0.4 0.8" repeatCount="indefinite" values="0;2;0;0"></animate></circle><circle cx="12" cy="12" r="0" fill="currentColor"><animate attributeName="r" begin=".33" calcMode="spline" dur="1.5s" keySplines="0.2 0.2 0.4 0.8;0.2 0.2 0.4 0.8;0.2 0.2 0.4 0.8" repeatCount="indefinite" values="0;2;0;0"></animate></circle><circle cx="6" cy="12" r="0" fill="currentColor"><animate attributeName="r" begin="0" calcMode="spline" dur="1.5s" keySplines="0.2 0.2 0.4 0.8;0.2 0.2 0.4 0.8;0.2 0.2 0.4 0.8" repeatCount="indefinite" values="0;2;0;0"></animate></circle>',3)]))}const Qe=R(Je,[["render",Ye]]),Xe={class:"bh-datatable bh-antialiased bh-relative bh-text-black bh-text-sm bh-font-normal"},Ze=["onClick"],je={class:"bh-checkbox"},et=["value"],tt=["innerHTML"],lt={key:1},nt=["colspan"],ot=["colspan"],at={key:0,class:"bh-absolute bh-inset-0 bh-bg-blue-light/50 bh-grid bh-place-content-center"},rt={class:"bh-flex bh-items-center bh-flex-wrap bh-flex-col sm:bh-flex-row bh-gap-4"},it={class:"bh-pagination-info bh-flex bh-items-center"},st={class:"bh-mr-2"},ut=["value"],ct={class:"bh-pagination-number sm:bh-ml-auto bh-inline-flex bh-items-center bh-space-x-1"},dt=["innerHTML"],mt=["innerHTML"],vt=["onClick"],ht=["innerHTML"],ft=["innerHTML"],pt=e.defineComponent({__name:"custom-table",props:{columns:{default:()=>[]},rows:{default:()=>[]},isServerMode:{type:Boolean,default:!1},totalRows:{default:0},skin:{default:"bh-table-striped bh-table-hover"},loading:{type:Boolean,default:!1},hasCheckbox:{type:Boolean,default:!1},search:{default:""},page:{default:1},pageSize:{default:10},pageSizeOptions:{default:()=>[10,20,30,50,100]},showPageSize:{type:Boolean,default:!0},rowClass:{},cellClass:{},sortable:{type:Boolean,default:!1},sortColumn:{default:"id"},sortDirection:{default:"asc"},columnFilter:{type:Boolean,default:!1},columnFilterLang:{default:()=>({no_filter:"No filter",contain:"Contain",not_contain:"Not contain",equal:"Equal",not_equal:"Not equal",start_with:"Starts with",end_with:"Ends with",greater_than:"Greater than",greater_than_equal:"Greater than or equal",less_than:"Less than",less_than_equal:"Less than or equal",is_null:"Is null",is_not_null:"Not null"})},pagination:{type:Boolean,default:!0},showNumbers:{type:Boolean,default:!0},showNumbersCount:{default:5},showFirstPage:{type:Boolean,default:!0},showLastPage:{type:Boolean,default:!0},firstArrow:{},lastArrow:{},nextArrow:{},previousArrow:{},paginationInfo:{default:"Showing {0} to {1} of {2} entries"},noDataContent:{default:"No data available"},stickyHeader:{type:Boolean,default:!1},height:{default:"500px"},stickyFirstColumn:{type:Boolean,default:!1},cloneHeaderInFooter:{type:Boolean,default:!1},selectRowOnClick:{type:Boolean,default:!1},columnChooser:{type:Boolean,default:!1}},emits:["change","sortChange","searchChange","pageChange","pageSizeChange","rowSelect","filterChange","rowClick","rowDBClick"],setup(_,{expose:p,emit:r}){var X,Z;const v=e.useSlots(),n=_,c=r;for(const t of n.columns||[]){const l=((X=t.type)==null?void 0:X.toLowerCase())||"string";t.type=l,t.isUnique=t.isUnique!==void 0?t.isUnique:!1,t.hide=t.hide!==void 0?t.hide:!1,t.filter=t.filter!==void 0?t.filter:!0,t.search=t.search!==void 0?t.search:!0,t.sort=t.sort!==void 0?t.sort:!0,t.html=t.html!==void 0?t.html:!1,t.condition=!l||l==="string"?"contain":"equal"}const C=e.ref([]),a=e.ref(n.page),u=e.ref(n.pagination?n.pageSize:(Z=n.rows)==null?void 0:Z.length),d=n.pageSize,y=e.ref(n.sortColumn),k=n.sortColumn,S=e.ref(n.sortDirection),oe=n.sortDirection,B=e.ref(n.totalRows),w=e.ref([]),T=e.ref(null),L=e.ref(n.loading),z=e.ref(n.search),ae=JSON.parse(JSON.stringify(n.columns)),q=e.ref(null),P=e.ref(null);let $=e.ref(0);const re=e.ref(230);e.onMounted(()=>{F()}),p({reset(){ke()},getSelectedRows(){return Ce()},getColumnFilters(){return be()},clearSelectedRows(){return ye()},selectRow(t){Y(t)},unselectRow(t){Q(t)},isRowSelected(t){return A(t)},getFilteredRows(){return I()}});const ie=(t,...l)=>t.replace(/{(\d+)}/g,(i,h)=>typeof l[h]<"u"?l[h]:i),b=e.computed(()=>{const t=n.columns.find(l=>l.isUnique);return(t==null?void 0:t.field)||null}),E=e.computed(()=>{const t=u.value<1?1:Math.ceil(B.value/u.value);return Math.max(t||0,1)}),H=e.computed(()=>(a.value-1)*u.value+1),U=e.computed(()=>{const t=a.value*u.value;return B.value>=t?t:B.value}),se=e.computed(()=>{let t,l;return typeof n.showNumbersCount<"u"&&n.showNumbersCount<E.value?(t=Math.max(a.value-Math.floor(n.showNumbersCount/2),1),l=t+n.showNumbersCount-1,l>E.value&&(l=E.value,t=l-n.showNumbersCount+1)):(t=1,l=E.value),Array.from(Array(l+1-t).keys()).map(g=>t+g)}),I=()=>{var g,M,j;let t=n.rows||[];if(!n.isServerMode){if((g=n.columns)==null||g.forEach(o=>{o.filter&&(o.value!==void 0&&o.value!==null&&o.value!==""||o.condition==="is_null"||o.condition=="is_not_null")&&(o.type==="string"?(o.value&&!o.condition&&(o.condition="contain"),o.condition==="contain"?t=t.filter(s=>{var f;return(f=m(s,o.field))==null?void 0:f.toString().toLowerCase().includes(o.value.toLowerCase())}):o.condition==="not_contain"?t=t.filter(s=>{var f;return!((f=m(s,o.field))!=null&&f.toString().toLowerCase().includes(o.value.toLowerCase()))}):o.condition==="equal"?t=t.filter(s=>{var f;return((f=m(s,o.field))==null?void 0:f.toString().toLowerCase())===o.value.toLowerCase()}):o.condition==="not_equal"?t=t.filter(s=>{var f;return((f=m(s,o.field))==null?void 0:f.toString().toLowerCase())!==o.value.toLowerCase()}):o.condition=="start_with"?t=t.filter(s=>{var f;return((f=m(s,o.field))==null?void 0:f.toString().toLowerCase().indexOf(o.value.toLowerCase()))===0}):o.condition=="end_with"&&(t=t.filter(s=>{var f;return((f=m(s,o.field))==null?void 0:f.toString().toLowerCase().substr(o.value.length*-1))===o.value.toLowerCase()}))):o.type==="number"?(o.value&&!o.condition&&(o.condition="equal"),o.condition==="equal"?t=t.filter(s=>m(s,o.field)&&parseFloat(m(s,o.field))===parseFloat(o.value)):o.condition==="not_equal"?t=t.filter(s=>m(s,o.field)&&parseFloat(m(s,o.field))!==parseFloat(o.value)):o.condition==="greater_than"?t=t.filter(s=>m(s,o.field)&&parseFloat(m(s,o.field))>parseFloat(o.value)):o.condition==="greater_than_equal"?t=t.filter(s=>m(s,o.field)&&parseFloat(m(s,o.field))>=parseFloat(o.value)):o.condition==="less_than"?t=t.filter(s=>m(s,o.field)&&parseFloat(m(s,o.field))<parseFloat(o.value)):o.condition==="less_than_equal"&&(t=t.filter(s=>m(s,o.field)&&parseFloat(m(s,o.field))<=parseFloat(o.value)))):o.type==="date"?(o.value&&!o.condition&&(o.condition="equal"),o.condition==="equal"?t=t.filter(s=>m(s,o.field)&&D(m(s,o.field))===o.value):o.condition==="not_equal"?t=t.filter(s=>m(s,o.field)&&D(m(s,o.field))!==o.value):o.condition==="greater_than"?t=t.filter(s=>m(s,o.field)&&D(m(s,o.field))>o.value):o.condition==="less_than"&&(t=t.filter(s=>m(s,o.field)&&D(m(s,o.field))<o.value))):o.type==="bool"&&(t=t.filter(s=>m(s,o.field)===o.value)),o.condition==="is_null"?(t=t.filter(s=>m(s,o.field)==null||m(s,o.field)==""),o.value=""):o.condition==="is_not_null"&&(o.value="",t=t.filter(s=>m(s,o.field))))}),z.value&&(t!=null&&t.length)){let o=[];const s=(n.columns||[]).filter(f=>f.search&&!f.hide).map(f=>f.field);for(var l=0;l<(t==null?void 0:t.length);l++)for(var i=0;i<s.length;i++)if((M=m(t[l],s[i]))!=null&&M.toString().toLowerCase().includes(z.value.toLowerCase())){o.push(t[l]);break}t=o}var h=new Intl.Collator(void 0,{numeric:((j=n.columns.find(o=>o.field==y.value))==null?void 0:j.type)==="number",sensitivity:"base"});const we=S.value==="desc"?-1:1;t.sort((o,s)=>{var ee,te;const f=(ee=y.value)==null?void 0:ee.split(".").reduce((V,O)=>V==null?void 0:V[O],o),_e=(te=y.value)==null?void 0:te.split(".").reduce((V,O)=>V==null?void 0:V[O],s);return h.compare(f,_e)*we})}return t},F=()=>{let t=[],l=I();n.isServerMode?(B.value=n.totalRows||0,t=l):(B.value=(l==null?void 0:l.length)||0,t=l.slice(H.value-1,U.value)),C.value=t||[]};e.watch(()=>n.loading,()=>{L.value=n.loading});const G=t=>{t?q.value===t.field?q.value=null:q.value=t.field:q.value=null},ue=()=>{if(a.value==1)return!1;a.value--},ce=t=>{a.value=t},de=()=>{if(a.value>=E.value)return!1;a.value++},me=()=>{N(!1),n.isServerMode?x("page"):(F(),c("pageChange",a.value))};e.watch(()=>a.value,me);const ve=()=>{n.isServerMode||(a.value=1),N(!1),F()};e.watch(()=>n.rows,ve);const he=()=>{N(!1),n.isServerMode?a.value===1?x("pagesize",!0):a.value=1:(a.value=1,F(),c("pageSizeChange",u.value))};e.watch(()=>u.value,he);const K=t=>{let l="asc";t==y.value&&S.value==="asc"&&(l="desc");let i=(a.value-1)*u.value,h=u.value;y.value=t,S.value=l,N(!1),F(),n.isServerMode?x("sort"):c("sortChange",{offset:i,limit:h,field:t,direction:l})},J=t=>{T.value=t.length&&C.value.length&&t.length===C.value.length;const l=C.value.filter((i,h)=>w.value.includes(b.value?i[b.value]:h));c("rowSelect",l)};e.watch(()=>w.value,J);const N=t=>{t?w.value=C.value.map((l,i)=>b.value?l[b.value]:i):w.value=[]},W=()=>{N(!1),n.isServerMode?a.value===1?x("filter",!0):a.value=1:(a.value=1,F(),c("filterChange",n.columns))},fe=()=>{N(!1),n.isServerMode?a.value===1?x("search",!0):a.value=1:(a.value=1,F(),c("searchChange",z.value))};e.watch(()=>n.search,()=>{z.value=n.search,fe()});const m=(t,l)=>l==null?void 0:l.split(".").reduce((i,h)=>i==null?void 0:i[h],t),D=t=>{try{if(!t)return"";const l=new Date(t),i=l.getDate(),h=l.getMonth()+1;return l.getFullYear()+"-"+(h>9?h:"0"+h)+"-"+(i>9?i:"0"+i)}catch{}return""},pe=(t,l)=>{$.value++,$.value===1?P.value=setTimeout(()=>{$.value=0,n.selectRowOnClick&&(A(l)?Q(l):Y(l),J(w.value)),c("rowClick",t)},re.value):$.value===2&&(clearTimeout(P.value),$.value=0,c("rowDBClick",t))},x=(t,l=!1)=>{if(n.isServerMode){ge();const i={current_page:l?1:a.value,pagesize:u.value,offset:(a.value-1)*u.value,sort_column:y.value,sort_direction:S.value,search:z.value,column_filters:n.columns,change_type:t};c("change",i)}},ge=()=>{for(let t=0;t<n.columns.length;t++){let l=n.columns[t];l.filter&&(l.value!==void 0&&l.value!==null&&l.value!==""||l.condition==="is_null"||l.condition==="is_not_null")&&(l.type==="string"&&l.value&&!l.condition&&(l.condition="contain"),l.type==="number"&&l.value&&!l.condition&&(l.condition="equal"),l.type==="date"&&l.value&&!l.condition&&(l.condition="equal"))}},ke=()=>{N(!1);for(let t=0;t<n.columns.length;t++)n.columns[t]=ae[t];z.value="",u.value=d,y.value=k,S.value=oe,n.isServerMode?a.value===1?x("reset",!0):a.value=1:(a.value=1,F())},Ce=()=>C.value.filter((l,i)=>w.value.includes(b.value?l[b.value]:i)),be=()=>n.columns,ye=()=>{w.value=[]},Y=t=>{if(!A(t)){const l=C.value.find((i,h)=>h===t);w.value.push(b.value?l[b.value]:t)}},Q=t=>{if(A(t)){const l=C.value.find((i,h)=>h===t);w.value=w.value.filter(i=>i!==(b.value?l[b.value]:t))}},A=t=>{const l=C.value.find((i,h)=>h===t);return l?w.value.includes(b.value?l[b.value]:t):!1};return(t,l)=>(e.openBlock(),e.createElementBlock("div",Xe,[e.createElementVNode("div",{class:e.normalizeClass(["bh-table-responsive",{"bh-min-h-[300px]":L.value}]),style:e.normalizeStyle({height:n.height||""})},[e.createElementVNode("table",{class:e.normalizeClass([n.skin])},[e.createElementVNode("thead",{class:e.normalizeClass({"bh-sticky bh-top-0 bh-z-10":n.stickyHeader})},[e.createVNode(le,{all:n,currentSortColumn:y.value,currentSortDirection:S.value,isOpenFilter:q.value,checkAll:T.value,columnFilterLang:n.columnFilterLang,onSelectAll:N,onSortChange:K,onFilterChange:W,onToggleFilterMenu:G},null,8,["currentSortColumn","currentSortDirection","isOpenFilter","checkAll","columnFilterLang"])],2),e.createElementVNode("tbody",null,[B.value?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(C.value,(i,h)=>(e.openBlock(),e.createElementBlock("tr",{key:i[b.value]!=null?i[b.value]:h,class:e.normalizeClass([typeof n.rowClass=="function"?n.rowClass(i):n.rowClass,n.selectRowOnClick?"bh-cursor-pointer":""]),onClick:e.withModifiers(g=>pe(i,h),["prevent"])},[n.hasCheckbox?(e.openBlock(),e.createElementBlock("td",{key:0,class:e.normalizeClass({"bh-sticky bh-left-0 bh-bg-blue-light":n.stickyFirstColumn})},[e.createElementVNode("div",je,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":l[0]||(l[0]=g=>w.value=g),type:"checkbox",value:i[b.value]?i[b.value]:h,onClick:l[1]||(l[1]=e.withModifiers(()=>{},["stop"]))},null,8,et),[[e.vModelCheckbox,w.value]]),e.createElementVNode("div",null,[e.createVNode(ne,{class:"check"})])])],2)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.columns,(g,M)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[g.hide?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("td",{key:g.field,class:e.normalizeClass([typeof n.cellClass=="function"?t.cellClass(i):n.cellClass,M===0&&n.stickyFirstColumn?"bh-sticky bh-left-0 bh-bg-blue-light":"",n.hasCheckbox&&M===0&&n.stickyFirstColumn?"bh-left-[52px]":"",g.cellClass?g.cellClass:""])},[e.unref(v)[g.field]?e.renderSlot(t.$slots,g.field,{key:0,value:i}):g.cellRenderer?(e.openBlock(),e.createElementBlock("div",{key:1,innerHTML:typeof g.cellRenderer=="function"&&g.cellRenderer(i)},null,8,tt)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createTextVNode(e.toDisplayString(m(i,g.field)),1)],64))],2))],64))),256))],10,Ze))),128)):e.createCommentVNode("",!0),!B.value&&!L.value?(e.openBlock(),e.createElementBlock("tr",lt,[e.createElementVNode("td",{colspan:n.columns.length+1},e.toDisplayString(n.noDataContent),9,nt)])):e.createCommentVNode("",!0),!B.value&&L.value?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:2},e.renderList(n.pageSize,i=>(e.openBlock(),e.createElementBlock("tr",{key:i,class:"!bh-bg-white bh-h-11 !bh-border-transparent"},[e.createElementVNode("td",{colspan:n.columns.length+1,class:"!bh-p-0 !bh-border-transparent"},l[5]||(l[5]=[e.createElementVNode("div",{class:"bh-skeleton-box bh-h-8"},null,-1)]),8,ot)]))),128)):e.createCommentVNode("",!0)]),n.cloneHeaderInFooter?(e.openBlock(),e.createElementBlock("tfoot",{key:0,class:e.normalizeClass({"bh-sticky bh-bottom-0":n.stickyHeader})},[e.createVNode(le,{all:n,currentSortColumn:y.value,currentSortDirection:S.value,isOpenFilter:q.value,isFooter:!0,checkAll:T.value,onSelectAll:N,onSortChange:K,onFilterChange:W,onToggleFilterMenu:G},null,8,["currentSortColumn","currentSortDirection","isOpenFilter","checkAll"])],2)):e.createCommentVNode("",!0)],2),B.value&&L.value?(e.openBlock(),e.createElementBlock("div",at,[e.createVNode(Qe)])):e.createCommentVNode("",!0)],6),n.pagination&&B.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["bh-pagination bh-py-5",{"bh-pointer-events-none":L.value}])},[e.createElementVNode("div",rt,[e.createElementVNode("div",it,[e.createElementVNode("span",st,e.toDisplayString(ie(n.paginationInfo,B.value?H.value:0,U.value,B.value)),1),n.showPageSize?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:0,"onUpdate:modelValue":l[2]||(l[2]=i=>u.value=i),class:"bh-pagesize"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.pageSizeOptions,i=>(e.openBlock(),e.createElementBlock("option",{value:i,key:i},e.toDisplayString(i),9,ut))),128))],512)),[[e.vModelSelect,u.value]]):e.createCommentVNode("",!0)]),e.createElementVNode("div",ct,[n.showFirstPage?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(["bh-page-item first-page",{disabled:a.value<=1}]),onClick:l[3]||(l[3]=i=>a.value=1)},[n.firstArrow?(e.openBlock(),e.createElementBlock("span",{key:0,innerHTML:n.firstArrow},null,8,dt)):e.renderSlot(t.$slots,"firstArrow",{key:1},()=>[l[6]||(l[6]=e.createElementVNode("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 16 16"},[e.createElementVNode("g",{fill:"currentColor","fill-rule":"evenodd"},[e.createElementVNode("path",{d:"M8.354 1.646a.5.5 0 0 1 0 .708L2.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"}),e.createElementVNode("path",{d:"M12.354 1.646a.5.5 0 0 1 0 .708L6.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"})])],-1))])],2)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["bh-page-item previous-page",{disabled:a.value<=1}]),onClick:ue},[n.previousArrow?(e.openBlock(),e.createElementBlock("span",{key:0,innerHTML:n.previousArrow},null,8,mt)):e.renderSlot(t.$slots,"previousArrow",{key:1},()=>[l[7]||(l[7]=e.createElementVNode("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 16 16"},[e.createElementVNode("path",{fill:"currentColor","fill-rule":"evenodd",d:"M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"})],-1))])],2),n.showNumbers?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(se.value,i=>(e.openBlock(),e.createElementBlock("button",{key:i,type:"button",class:e.normalizeClass(["bh-page-item",{disabled:a.value===i,"bh-active":i===a.value}]),onClick:h=>ce(i)},e.toDisplayString(i),11,vt))),128)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["bh-page-item next-page",{disabled:a.value>=E.value}]),onClick:de},[n.nextArrow?(e.openBlock(),e.createElementBlock("span",{key:0,innerHTML:n.nextArrow},null,8,ht)):e.renderSlot(t.$slots,"nextArrow",{key:1},()=>[l[8]||(l[8]=e.createElementVNode("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 16 16"},[e.createElementVNode("path",{fill:"currentColor","fill-rule":"evenodd",d:"M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8L4.646 2.354a.5.5 0 0 1 0-.708z"})],-1))])],2),n.showLastPage?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",class:e.normalizeClass(["bh-page-item last-page",{disabled:a.value>=E.value}]),onClick:l[4]||(l[4]=i=>a.value=E.value)},[n.lastArrow?(e.openBlock(),e.createElementBlock("span",{key:0,innerHTML:n.lastArrow},null,8,ft)):e.renderSlot(t.$slots,"lastArrow",{key:1},()=>[l[9]||(l[9]=e.createElementVNode("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 16 16"},[e.createElementVNode("g",{fill:"currentColor","fill-rule":"evenodd"},[e.createElementVNode("path",{d:"M3.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L9.293 8L3.646 2.354a.5.5 0 0 1 0-.708z"}),e.createElementVNode("path",{d:"M7.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L13.293 8L7.646 2.354a.5.5 0 0 1 0-.708z"})])],-1))])],2)):e.createCommentVNode("",!0)])])],2)):e.createCommentVNode("",!0)]))}});module.exports=pt;