UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 5.76 kB
"use strict";var t=require("primevue/basecomponent"),e=require("primevue/paginator"),r=require("primevue/utils"),a=require("vue");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=o(t),i=o(e),l={name:"DataView",extends:s.default,emits:["update:first","update:rows","page"],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}},data(){return{d_first:this.first,d_rows:this.rows}},watch:{first(t){this.d_first=t},rows(t){this.d_rows=t},sortField(){this.resetPage()},sortOrder(){this.resetPage()}},methods:{getKey(t,e){return this.dataKey?r.ObjectUtils.resolveFieldData(t,this.dataKey):e},onPage(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(){if(this.value){const t=[...this.value];return t.sort(((t,e)=>{let a=r.ObjectUtils.resolveFieldData(t,this.sortField),o=r.ObjectUtils.resolveFieldData(e,this.sortField),s=null;return s=null==a&&null!=o?-1:null!=a&&null==o?1:null==a&&null==o?0:"string"==typeof a&&"string"==typeof o?a.localeCompare(o,void 0,{numeric:!0}):a<o?-1:a>o?1:0,this.sortOrder*s})),t}return null},resetPage(){this.d_first=0,this.$emit("update:first",this.d_first)}},computed:{containerClass(){return["p-dataview p-component",{"p-dataview-list":"list"===this.layout,"p-dataview-grid":"grid"===this.layout}]},getTotalRecords(){return this.totalRecords?this.totalRecords:this.value?this.value.length:0},empty(){return!this.value||0===this.value.length},paginatorTop(){return this.paginator&&("bottom"!==this.paginatorPosition||"both"===this.paginatorPosition)},paginatorBottom(){return this.paginator&&("top"!==this.paginatorPosition||"both"===this.paginatorPosition)},items(){if(this.value&&this.value.length){let t=this.value;if(t&&t.length&&this.sortField&&(t=this.sort()),this.paginator){const e=this.lazy?0:this.d_first;return t.slice(e,e+this.d_rows)}return t}return null}},components:{DVPaginator:i.default}};l.render=function(t,e,r,o,s,i){const l=a.resolveComponent("DVPaginator");return a.openBlock(),a.createElementBlock("div",a.mergeProps({class:i.containerClass},t.ptm("root")),[t.$slots.header?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:0,class:"p-dataview-header"},t.ptm("header")),[a.renderSlot(t.$slots,"header")],16)):a.createCommentVNode("",!0),i.paginatorTop?(a.openBlock(),a.createBlock(l,{key:1,rows:s.d_rows,first:s.d_first,totalRecords:i.getTotalRecords,pageLinkSize:r.pageLinkSize,template:r.paginatorTemplate,rowsPerPageOptions:r.rowsPerPageOptions,currentPageReportTemplate:r.currentPageReportTemplate,class:a.normalizeClass({"p-paginator-top":i.paginatorTop}),alwaysShow:r.alwaysShowPaginator,onPage:e[0]||(e[0]=t=>i.onPage(t)),pt:t.ptm("paginator")},a.createSlots({_:2},[t.$slots.paginatorstart?{name:"start",fn:a.withCtx((()=>[a.renderSlot(t.$slots,"paginatorstart")])),key:"0"}:void 0,t.$slots.paginatorend?{name:"end",fn:a.withCtx((()=>[a.renderSlot(t.$slots,"paginatorend")])),key:"1"}:void 0]),1032,["rows","first","totalRecords","pageLinkSize","template","rowsPerPageOptions","currentPageReportTemplate","class","alwaysShow","pt"])):a.createCommentVNode("",!0),a.createElementVNode("div",a.mergeProps({class:"p-dataview-content"},t.ptm("content")),[a.createElementVNode("div",a.mergeProps({class:"p-grid p-nogutter grid grid-nogutter"},t.ptm("grid")),[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(i.items,((e,o)=>(a.openBlock(),a.createElementBlock(a.Fragment,{key:i.getKey(e,o)},[t.$slots.list&&"list"===r.layout?a.renderSlot(t.$slots,"list",{key:0,data:e,index:o}):a.createCommentVNode("",!0),t.$slots.grid&&"grid"===r.layout?a.renderSlot(t.$slots,"grid",{key:1,data:e,index:o}):a.createCommentVNode("",!0)],64)))),128)),i.empty?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:0,class:"p-col col"},t.ptm("column")),[a.createElementVNode("div",a.mergeProps({class:"p-dataview-emptymessage"},t.ptm("emptyMessage")),[a.renderSlot(t.$slots,"empty")],16)],16)):a.createCommentVNode("",!0)],16)],16),i.paginatorBottom?(a.openBlock(),a.createBlock(l,{key:2,rows:s.d_rows,first:s.d_first,totalRecords:i.getTotalRecords,pageLinkSize:r.pageLinkSize,template:r.paginatorTemplate,rowsPerPageOptions:r.rowsPerPageOptions,currentPageReportTemplate:r.currentPageReportTemplate,class:a.normalizeClass({"p-paginator-bottom":i.paginatorBottom}),alwaysShow:r.alwaysShowPaginator,onPage:e[1]||(e[1]=t=>i.onPage(t)),pt:t.ptm("root")},a.createSlots({_:2},[t.$slots.paginatorstart?{name:"start",fn:a.withCtx((()=>[a.renderSlot(t.$slots,"paginatorstart")])),key:"0"}:void 0,t.$slots.paginatorend?{name:"end",fn:a.withCtx((()=>[a.renderSlot(t.$slots,"paginatorend")])),key:"1"}:void 0]),1032,["rows","first","totalRecords","pageLinkSize","template","rowsPerPageOptions","currentPageReportTemplate","class","alwaysShow","pt"])):a.createCommentVNode("",!0),t.$slots.footer?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:3,class:"p-dataview-footer"},t.ptm("footer")),[a.renderSlot(t.$slots,"footer")],16)):a.createCommentVNode("",!0)],16)},module.exports=l;