siegel
Version:
Web application development ecosystem
1 lines • 1.19 kB
JavaScript
import e from"../../../../common/is/exists/index.js";export default function(t,n,o){let r,i,l,h,{entities:{byID:a,sorted:s},pinnedEntities:c,columnsConfig:f,postProcessBodyRow:m,withFooter:u}=t,d=c?.sorted,{searchByField:g,sortByField:p,toggledColumns:I,showPerPage:M,currentPage:S}=n,b=s;if(Object.entries(g).forEach(([t,n])=>{r||(r={},f.forEach(({ID:e},t)=>{r[e]=t}));let o=r[t];if(e(o)){let t=f[o];e(t.onFilter)&&(b=t.onFilter(b,a,n))}}),e(p.ID)){let{value:t,ID:n}=p,o=r?r[n]:f.findIndex(e=>e.ID==n),i=f[o];e(i.onSort)&&(b=i.onSort(b.slice(),a,t),d&&=i.onSort(d.slice(),c.byID,t))}let x=b.length;if(u){let e=Math.ceil(x/M)||1;S>e&&(n.currentPage=e),l=Math.min((i=(n.currentPage-1)*M)+M,x),o&&(i+=o.from,l=Math.min(l,i+(o.to-o.from)))}else o?(i=o.from,l=Math.min(o.to,x)):(i=0,l=x);d?.length>0?(h=Array.from(new Set(b=b.splice(0,i).concat(d,b))),u&&(l+=d.length)):h=b;let y=new Set,D=[];for(let e=i;e<l;e++){let t=b[e];if(y.has(t)){l=Math.min(b.length,l+1);continue}y.add(t);let n=a[t],o=[];f.forEach(e=>{I.has(e.ID)||o.push(e.showValue(n))});let r=[{children:o,attributes:{key:t}}];m?.(r,n,e),r.length>1?r.forEach(e=>{D.push(e)}):D.push(r[0])}return{from:i,to:l,resultIDs:h,body:D}}