primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 6.56 kB
JavaScript
import t from"primevue/paginator";import{ObjectUtils as e}from"primevue/utils";import r from"primevue/basecomponent";import{resolveComponent as a,openBlock as o,createElementBlock as n,mergeProps as i,renderSlot as s,createCommentVNode as l,createBlock as p,normalizeClass as u,createSlots as d,withCtx as g,createElementVNode as c,Fragment as f,renderList as m}from"vue";function y(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(t,e){if(t){if("string"==typeof t)return P(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?P(t,e):void 0}}function w(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function v(t){if(Array.isArray(t))return P(t)}function P(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,a=new Array(e);r<e;r++)a[r]=t[r];return a}var S={name:"DataView",extends:{name:"BaseDataView",extends:r,props:{value:{type:Array,default:null},layout:{type:String,default:"list"},rows:{type:Number,default:0},first:{type:Number,default:0},totalRecords:{type:Number,default:0},paginator:{type:Boolean,default:!1},paginatorPosition:{type:String,default:"bottom"},alwaysShowPaginator:{type:Boolean,default:!0},paginatorTemplate:{type:String,default:"FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"},pageLinkSize:{type:Number,default:5},rowsPerPageOptions:{type:Array,default:null},currentPageReportTemplate:{type:String,default:"({currentPage} of {totalPages})"},sortField:{type:[String,Function],default:null},sortOrder:{type:Number,default:null},lazy:{type:Boolean,default:!1},dataKey:{type:String,default:null}},css:{classes:{root:function(t){var e=t.props;return["p-dataview p-component",{"p-dataview-list":"list"===e.layout,"p-dataview-grid":"grid"===e.layout}]},header:"p-dataview-header",paginator:function(t){var e=t.instance;return e.paginatorTop?"p-paginator-top":e.paginatorBottom?"p-paginator-bottom":""},content:"p-dataview-content",grid:"p-grid p-nogutter grid grid-nogutter",column:"p-col col",emptyMessage:"p-dataview-emptymessage",footer:"p-dataview-footer"}},provide:function(){return{$parentInstance:this}}},emits:["update:first","update:rows","page"],data:function(){return{d_first:this.first,d_rows:this.rows}},watch:{first:function(t){this.d_first=t},rows:function(t){this.d_rows=t},sortField:function(){this.resetPage()},sortOrder:function(){this.resetPage()}},methods:{getKey:function(t,r){return this.dataKey?e.resolveFieldData(t,this.dataKey):r},onPage:function(t){this.d_first=t.first,this.d_rows=t.rows,this.$emit("update:first",this.d_first),this.$emit("update:rows",this.d_rows),this.$emit("page",t)},sort:function(){var t,r=this;if(this.value){var a=v(t=this.value)||w(t)||h(t)||y(),o=new Intl.Collator(void 0,{numeric:!0}).compare;return a.sort((function(t,a){var n=e.resolveFieldData(t,r.sortField),i=e.resolveFieldData(a,r.sortField),s=null;return s=null==n&&null!=i?-1:null!=n&&null==i?1:null==n&&null==i?0:"string"==typeof n&&"string"==typeof i?o(n,i):n<i?-1:n>i?1:0,r.sortOrder*s})),a}return null},resetPage:function(){this.d_first=0,this.$emit("update:first",this.d_first)}},computed:{getTotalRecords:function(){return this.totalRecords?this.totalRecords:this.value?this.value.length:0},empty:function(){return!this.value||0===this.value.length},paginatorTop:function(){return this.paginator&&("bottom"!==this.paginatorPosition||"both"===this.paginatorPosition)},paginatorBottom:function(){return this.paginator&&("top"!==this.paginatorPosition||"both"===this.paginatorPosition)},items:function(){if(this.value&&this.value.length){var t=this.value;if(t&&t.length&&this.sortField&&(t=this.sort()),this.paginator){var e=this.lazy?0:this.d_first;return t.slice(e,e+this.d_rows)}return t}return null}},components:{DVPaginator:t}};S.render=function(t,e,r,y,h,w){var v=a("DVPaginator");return o(),n("div",i({class:t.cx("root")},t.ptm("root"),{"data-pc-name":"dataview"}),[t.$slots.header?(o(),n("div",i({key:0,class:t.cx("header")},t.ptm("header")),[s(t.$slots,"header")],16)):l("",!0),w.paginatorTop?(o(),p(v,{key:1,rows:h.d_rows,first:h.d_first,totalRecords:w.getTotalRecords,pageLinkSize:t.pageLinkSize,template:t.paginatorTemplate,rowsPerPageOptions:t.rowsPerPageOptions,currentPageReportTemplate:t.currentPageReportTemplate,class:u(t.cx("paginator")),alwaysShow:t.alwaysShowPaginator,onPage:e[0]||(e[0]=function(t){return w.onPage(t)}),unstyled:t.unstyled,pt:t.ptm("paginator")},d({_:2},[t.$slots.paginatorstart?{name:"start",fn:g((function(){return[s(t.$slots,"paginatorstart")]})),key:"0"}:void 0,t.$slots.paginatorend?{name:"end",fn:g((function(){return[s(t.$slots,"paginatorend")]})),key:"1"}:void 0]),1032,["rows","first","totalRecords","pageLinkSize","template","rowsPerPageOptions","currentPageReportTemplate","class","alwaysShow","unstyled","pt"])):l("",!0),c("div",i({class:t.cx("content")},t.ptm("content")),[c("div",i({class:t.cx("grid")},t.ptm("grid")),[(o(!0),n(f,null,m(w.items,(function(e,r){return o(),n(f,{key:w.getKey(e,r)},[t.$slots.list&&"list"===t.layout?s(t.$slots,"list",{key:0,data:e,index:r}):l("",!0),t.$slots.grid&&"grid"===t.layout?s(t.$slots,"grid",{key:1,data:e,index:r}):l("",!0)],64)})),128)),w.empty?(o(),n("div",i({key:0,class:t.cx("column")},t.ptm("column")),[c("div",i({class:t.cx("emptyMessage")},t.ptm("emptyMessage")),[s(t.$slots,"empty")],16)],16)):l("",!0)],16)],16),w.paginatorBottom?(o(),p(v,{key:2,rows:h.d_rows,first:h.d_first,totalRecords:w.getTotalRecords,pageLinkSize:t.pageLinkSize,template:t.paginatorTemplate,rowsPerPageOptions:t.rowsPerPageOptions,currentPageReportTemplate:t.currentPageReportTemplate,class:u(t.cx("paginator")),alwaysShow:t.alwaysShowPaginator,onPage:e[1]||(e[1]=function(t){return w.onPage(t)}),unstyled:t.unstyled,pt:t.ptm("paginator")},d({_:2},[t.$slots.paginatorstart?{name:"start",fn:g((function(){return[s(t.$slots,"paginatorstart")]})),key:"0"}:void 0,t.$slots.paginatorend?{name:"end",fn:g((function(){return[s(t.$slots,"paginatorend")]})),key:"1"}:void 0]),1032,["rows","first","totalRecords","pageLinkSize","template","rowsPerPageOptions","currentPageReportTemplate","class","alwaysShow","unstyled","pt"])):l("",!0),t.$slots.footer?(o(),n("div",i({key:3,class:t.cx("footer")},t.ptm("footer")),[s(t.$slots,"footer")],16)):l("",!0)],16)};export{S as default};