tablevu 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/babel.config.json +3 -0
- package/dist/get.js +1 -1
- package/dist/table.js +1 -1
- package/package.json +4 -3
- package/src/get.js +2 -5
- package/src/table.js +18 -21
package/README.md
CHANGED
|
@@ -23,7 +23,11 @@ npm install tablevu
|
|
|
23
23
|
## Usage
|
|
24
24
|
* **data** : Array or Server side parameters
|
|
25
25
|
|
|
26
|
-
* **
|
|
26
|
+
* **grouping** : Grouping data specific column or function
|
|
27
|
+
|
|
28
|
+
* **filter** : Reactive filter value
|
|
29
|
+
|
|
30
|
+
* **search** : Reactive search value
|
|
27
31
|
|
|
28
32
|
* **rowid** : Key value for row.
|
|
29
33
|
|
|
@@ -47,7 +51,9 @@ npm install tablevu
|
|
|
47
51
|
* **width** : Column width
|
|
48
52
|
|
|
49
53
|
* **align** : Column align
|
|
50
|
-
|
|
54
|
+
|
|
55
|
+
* **style** : Column style
|
|
56
|
+
|
|
51
57
|
* **type** : Data type (datetime, date, time, numeric). Show local value
|
|
52
58
|
|
|
53
59
|
* **render** : Render value
|
package/dist/get.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function get(req){return new Promise((resolve,reject)=>{fetch(req).then(res=>res.json()).then(res=>{let r;let c=0;if(res){if(res.hasOwnProperty("value"))r=res.value;else r=res;if(res.hasOwnProperty("@odata
|
|
1
|
+
export default function get(req){return new Promise((resolve,reject)=>{fetch(req).then(res=>res.json()).then(res=>{let r;let c=0;if(res){if(res.hasOwnProperty("value"))r=res.value;else r=res;if(res.hasOwnProperty("@odata.count")){c=parseInt(res["@odata.count"])}else if(res.hasOwnProperty("count"))c=parseInt(res["count"]);else c=0;resolve({rows:r,count:c})}else resolve({rows:null,count:null})}).catch(err=>{console.error(err);reject(err)})})}
|
package/dist/table.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h,onMounted,reactive,ref,watch,isReactive,isRef}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1};const tablevu={props:{settings:{type:Object,default:null},data:{type:[Array,Function]},group:{type:[String,Object]},search:{type:String},filter:{type:[Array,Object]},command:{type:Array,default:[]},rowid:{type:String},onRowClick:{type:Function},onRowDblClick:{type:Function},class:{type:String,default:"table"},style:{type:String,default:null}},emits:["onRowClick","onRowDblClick"],setup(props,{attrs,slots,emit,expose}){let rows=[];let rowg=[];let grps=[];let adapter=null;let timer=null;const spec=reactive({caption:null,group:{value:props.settings&&props.settings.group?props.settings.group.value:props.group?props.group:null,content:props.settings&&props.settings.group?props.settings.group.content:null,expandAll:true,class:"table-light"},page:{count:0,size:props.settings&&props.settings.page?props.settings.page.size:0,current:0,type:null},sort:props.settings&&props.settings.sort?props.settings.sort:[],columns:props.settings&&props.settings.columns?props.settings.columns:[],footer:{button:{class:"btn"}}});if(props.data){if(Array.isArray(props.data)){adapter=adaptarr}else{adapter=props.data}}if(props.filter)spec.filter=props.filter;watch(()=>props.search,(n,o)=>{const x=parseInt(props.settings.searchMinChar)||3;if(timer)clearTimeout(timer);if(o&&o.length>x&&(n==undefined||n==null||n.length<=x)||n&&n.length>x){timer=setTimeout(()=>{if(n&&n.length>x)spec.search=props.search;else spec.search=null;refresh()},444)}});if(props.filter)spec.filter=props.filter;watch(()=>props.filter,()=>{if(props.filter)spec.filter=props.filter;else spec.filter=null;refresh()},{deep:true});watch(()=>props.command,(n,o)=>{if(n&&n.length>0){const c=props.command[n.length-1];if(c&&c.name){if(c.name.toLowerCase()=="refresh")refresh();else if(c.name.toLowerCase()=="first")first();else if(c.name.toLowerCase()=="prior")prior();else if(c.name.toLowerCase()=="next")next();else if(c.name.toLowerCase()=="last")last();else console.log("Unknown command")}props.command.length=0}},{deep:true});function prepareGroup(g,r){grps=[];rowg=[];for(let i=0;i<r.length;i++){let v=null;let c=null;const o=r[i];if(g.value){if(typeof g.value=="function")v=g.value(o);else v=o[g.value]}else if(typeof g=="function")v=g(o);else{if(typeof g=="bigint"||typeof g=="number"){const l=parseInt(g);if(l)v=o[l]}else if(typeof g=="string")v=o[g]}if(g.content){if(typeof g.content=="function")c=g.content(o);else c=o[g.content]}let n=grps.findIndex(f=>f.group==v);if(n==-1){n=grps.push({group:v,content:c,expand:spec.group.expandAll})-1}rowg.push(n)}}function first(){page(1)}function prior(){if(spec.page.current>1){page(spec.page.current-1)}else{page(spec.page.current)}}function next(){page(spec.page.current+1)}function last(){page(spec.page.count)}function refresh(){page(spec.page.current)}function orderby(ind,dir){if(spec.sort&&spec.sort.length>0){let l=spec.sort.findIndex(f=>f.index==ind);if(l<0){let n=spec.columns[ind].name;l=spec.sort.findIndex(f=>f.name==n)}if(l==0){spec.sort[l].dir=dir?dir:spec.sort[0].dir?null:"desc"}else if(l>0){spec.sort.splice(l,1)}if(l!=0){spec.sort.unshift({index:ind,dir:dir?dir:null})}if(spec.sort.length>2){spec.sort.pop()}}else{spec.sort.push({index:ind,dir:dir?dir:null})}page(spec.page.current)}function page(currentPage){let dat=null;if(props.data){if(Array.isArray(props.data))dat=props.data}else return;spec.status=tablevuStatuses.Loading;if(adapter){adapter({pageSize:spec.page.size,currPage:currentPage,sort:spec.sort,cols:spec.columns,filter:spec.filter,search:spec.search},dat).then(ada=>{if(spec.onData)rows=spec.onData(ada.rows);else rows=ada.rows;if(spec.group&&(typeof spec.group=="string"||typeof spec.group=="bigint"||typeof spec.group=="object"&&spec.group.value))prepareGroup(spec.group,rows);spec.page.count=ada.count>0&&spec.page.size>0?ada.count/spec.page.size:0;spec.page.current=currentPage;spec.status=tablevuStatuses.Ready;spec.time=Date.now()})}}function renderValue(col,val){if(val){let v;if(col.type=="datetime"||col.type=="date"||col.type=="time"){let t=new Date(val);if(col.type=="date")v=t.toLocaleDateString();else if(col.type=="time")v=t.toLocaleTimeString();else v=t.toLocaleString()}else{if(col.type=="numeric"){v=parseFloat(val)}else{if(col.type=="integer"){v=parseInt(val)}else v=val}}return v}else return""}function renderCell(col,val){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}if(col.color){o.style["color"]=col.color}if(col.backgroundColor){o.style["background-color"]=col.backgroundColor}const v=renderValue(col,val);return h("td",o,v)}function renderCustomCell(col,row){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}let f=col.render(row);return h("td",o,f)}function renderGroup(grp){const b=h("button",{title:grp.expand,onClick:event=>{grp.expand=grp.expand?false:true;event.currentTarget.value=grp.expand?"▼":"►";spec.time=Date.now();event.preventDefault()},style:{padding:0,margin:"0 6px 0 0",width:"12px",height:"100%",border:"none",outline:0,backgroundColor:"transparent"}},grp.expand?"▼":"►");const v=grp.content||grp.group;return h("tr",{},h("td",{colspan:spec.columns.length,class:spec.group.class},[b,v]))}function renderRow(index,row){const o={};const r=[];o.key=index;o.index=index;if(props.rowid){o.rowid=row[props.rowid]}for(let i=0;i<spec.columns.length;i+=1){let v;const c=spec.columns[i];if(c.render){v=renderCustomCell(c,row);r.push(v)}else{if(c.depth){v=row;for(let j=0;j<c.depth.length;j+=1){if(v)v=v[c.depth[j]]}}else{v=row[c.name]}r.push(renderCell(c,v))}}o.ondblclick=event=>{const r=rows[event.currentTarget.attributes.index.value];emit("onRowDblClick",event,r)};if(props.onRowClick){o.onClick=event=>{const r=rows[event.currentTarget.attributes.index.value];props.onRowClick(event,r)}}return h("tr",o,r)}function renderHeader(){let ar=[];let sp=1;for(let i=0;i<spec.columns.length;i+=1){if(sp>1){sp--;continue}const cl=[];if(spec.columns[i].label){cl.push(h("span",spec.columns[i].label))}else{cl.push(h("span",spec.columns[i].name))}if(spec.sort&&spec.sort.length>0&&spec.sort[0].index==i){if(spec.sort[0].dir=="desc")cl.push(h("span",{style:{float:"right"}},"▼"));else cl.push(h("span",{style:{float:"right"}},"▲"))}let ch={position:"relative"};if(spec.columns[i].width){ch.width=spec.columns[i].width;ch.minWidth=spec.columns[i].width;ch.maxWidth=spec.columns[i].width}let cy={display:"block","font-weight":500,textDecoration:"none",color:"black",textAlign:"center"};if(spec.columns[i].header){if(spec.columns[i].header.colspan)sp=parseInt(spec.columns[i].header.colspan)||1;if(spec.columns[i].header.align)cy.textAlign=spec.columns[i].header.align;if(spec.columns[i].header.backgroundColor)ch.backgroundColor=spec.columns[i].header.backgroundColor;if(spec.columns[i].header.color)cy.color=spec.columns[i].header.color}let a;let f;if(spec.columns[i].popup){const r=ref(null);let c=[h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Ascending"),h("a",{href:"#",onClick(event){orderby(i,"desc");event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Descending")];a=h("a",{href:"#",onClick(event){if(r.value&&r.value.style&&r.value.style.display&&r.value.style.display=="block")r.value.style.display="none";else r.value.style.display="block";event.preventDefault()},style:cy},cl);f=h("div",{ref:r,style:{position:"absolute",display:"none",width:spec.columns[i].width||"12rem",height:"fit-content",border:"1px solid lightgray",backgroundColor:"whitesmoke",zIndex:1,left:0,top:"2rem",bottom:0,right:0,padding:".25rem"}},c)}else a=h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:cy},cl);if(spec.columns[i].filter){}ar.push(h("th",{colspan:sp>1?sp:null,style:ch},[a,f]))}const tr=h("tr",{},ar);return[tr]}function renderBody(){const dr=[];if(rows&&rows.length>0){if(grps&&grps.length>0){let r=[];for(let g=0;g<grps.length;g++)r.push({index:g,childs:[]});for(let i=0;i<rows.length;i++){const x=rowg[i];r[x].childs.push(renderRow(i,rows[i]))}for(let g=0;g<grps.length;g++){dr.push(renderGroup(grps[g]));if(grps[g].expand)dr.push(r[g].childs)}}else{for(let i=0;i<rows.length;i++){dr.push(renderRow(i,rows[i]))}}}return dr}function renderFooter(){const fr=h("button",{class:spec.footer.button.class,style:"margin-right: .5rem",onClick:first,disabled:spec.page.current==1},"◀◀");const ls=h("button",{class:spec.footer.button.class,style:"margin-right: .5rem",onClick:last,disabled:spec.page.count==0},"▶▶");const pg=h("button",{class:spec.footer.button.class,style:"margin-right: .5rem"},spec.page.current);const pr=h("button",{class:spec.footer.button.class,style:"margin-right: .5rem",onClick:prior,disabled:spec.page.current==1},"◀");const nx=h("button",{class:spec.footer.button.class,style:"margin-right: .5rem",onClick:next,disabled:spec.page.count>0&&spec.page.current==spec.page.count},"▶");const td=h("td",{colspan:spec.columns.length,align:"center"},[fr,pr,pg,nx,ls]);const tr=h("tr",{},[td]);return[tr]}function renderCaption(){return null}if(spec.columns.length==0){alert("Columns not defined !")}for(let i=0;i<spec.columns.length;i++)if(spec.columns[i].name&&spec.columns[i].name.indexOf(".")>-1){spec.columns[i].depth=spec.columns[i].name.split(".")}page(1);onMounted(()=>{});return{spec:spec,renderHeader:renderHeader,renderBody:renderBody,renderFooter:renderFooter,renderCaption:renderCaption}},render(props){let prps={class:"tablevu"};if(props.class)prps.class="tablevu "+props.class;if(props.style)prps.style=props.style;let cntn=[];cntn.push(h("thead",{},this.renderHeader()));if(this.spec.status==tablevuStatuses.Ready)cntn.push(h("tbody",{"data-time":this.spec.time},this.renderBody()));if(this.spec.caption)cntn.push(h("caption",{},this.renderCaption()));if(this.spec.page.size>0)cntn.push(h("tfoot",{},this.renderFooter()));return h("table",prps,cntn)}};export default tablevu;
|
|
1
|
+
import{h,onMounted,reactive,ref,watch,isReactive,isRef}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1};const tablevu={props:{settings:{type:Object,default:null},data:{type:[Array,Function]},group:{type:[String,Object]},search:{type:String},filter:{type:[Array,Object]},command:{type:Array,default:[]},rowid:{type:String},onRowClick:{type:Function},onRowDblClick:{type:Function},class:{type:String,default:"table"},style:{type:String,default:null}},emits:["onRowClick","onRowDblClick"],setup(props,{attrs,slots,emit,expose}){let rows=[];let rowg=[];let grps=[];let adapter=null;let timer=null;const spec=reactive({caption:null,group:{value:props.settings&&props.settings.group?props.settings.group.value:props.group?props.group:null,content:props.settings&&props.settings.group?props.settings.group.content:null,expandAll:true,class:"table-light"},page:{count:0,size:props.settings&&props.settings.page?props.settings.page.size:0,current:0,type:null},sort:props.settings&&props.settings.sort?props.settings.sort:[],columns:props.settings&&props.settings.columns?props.settings.columns:[],footer:{button:{class:"btn"}}});if(props.data){if(Array.isArray(props.data)){adapter=adaptarr}else{adapter=props.data}}if(props.filter)spec.filter=props.filter;watch(()=>props.search,(n,o)=>{const x=parseInt(props.settings.searchMinChar)||3;if(timer)clearTimeout(timer);if(o&&o.length>x&&(n==undefined||n==null||n.length<=x)||n&&n.length>x){timer=setTimeout(()=>{if(n&&n.length>x)spec.search=props.search;else spec.search=null;refresh()},444)}});if(props.filter)spec.filter=props.filter;watch(()=>props.filter,()=>{if(props.filter)spec.filter=props.filter;else spec.filter=null;refresh()},{deep:true});watch(()=>props.command,(n,o)=>{if(n&&n.length>0){const c=props.command[n.length-1];if(c&&c.name){if(c.name.toLowerCase()=="refresh")refresh();else if(c.name.toLowerCase()=="first")first();else if(c.name.toLowerCase()=="prior")prior();else if(c.name.toLowerCase()=="next")next();else if(c.name.toLowerCase()=="last")last();else console.log("Unknown command")}props.command.length=0}},{deep:true});function prepareGroup(g,r){grps=[];rowg=[];for(let i=0;i<r.length;i++){let v=null;let c=null;const o=r[i];if(g.value){if(typeof g.value=="function")v=g.value(o);else v=o[g.value]}else if(typeof g=="function")v=g(o);else{if(typeof g=="bigint"||typeof g=="number"){const l=parseInt(g);if(l)v=o[l]}else if(typeof g=="string")v=o[g]}if(g.content){if(typeof g.content=="function")c=g.content(o);else c=o[g.content]}let n=grps.findIndex(f=>f.group==v);if(n==-1){n=grps.push({group:v,content:c,expand:spec.group.expandAll})-1}rowg.push(n)}}function first(){page(1)}function prior(){if(spec.page.current>1){page(spec.page.current-1)}else{page(spec.page.current)}}function next(){page(spec.page.current+1)}function last(){page(spec.page.count)}function refresh(){page(spec.page.current)}function orderby(ind,dir){if(spec.sort&&spec.sort.length>0){let l=spec.sort.findIndex(f=>f.index==ind);if(l<0){let n=spec.columns[ind].name;l=spec.sort.findIndex(f=>f.name==n)}if(l==0){spec.sort[l].dir=dir?dir:spec.sort[0].dir?null:"desc"}else if(l>0){spec.sort.splice(l,1)}if(l!=0){spec.sort.unshift({index:ind,dir:dir?dir:null})}if(spec.sort.length>2){spec.sort.pop()}}else{spec.sort.push({index:ind,dir:dir?dir:null})}page(spec.page.current)}function page(currentPage){let dat=null;if(props.data){if(Array.isArray(props.data))dat=props.data}else return;spec.status=tablevuStatuses.Loading;if(adapter){adapter({pageSize:spec.page.size,currPage:currentPage,sort:spec.sort,cols:spec.columns,filter:spec.filter,search:spec.search},dat).then(ada=>{if(spec.onData)rows=spec.onData(ada.rows);else rows=ada.rows;if(spec.group&&(typeof spec.group=="string"||typeof spec.group=="bigint"||typeof spec.group=="object"&&spec.group.value))prepareGroup(spec.group,rows);spec.page.count=ada.count>0&&spec.page.size>0?ada.count/spec.page.size:0;spec.page.current=currentPage;spec.status=tablevuStatuses.Ready;spec.time=Date.now()})}}function renderValue(col,val){if(val){let v;if(col.type=="datetime"||col.type=="date"||col.type=="time"){let t=new Date(val);if(col.type=="date")v=t.toLocaleDateString();else if(col.type=="time")v=t.toLocaleTimeString();else v=t.toLocaleString()}else{if(col.type=="numeric"){v=parseFloat(val)}else{if(col.type=="integer"){v=parseInt(val)}else v=val}}return v}else return""}function renderCell(col,val){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}const v=renderValue(col,val);return h("td",o,v)}function renderCustomCell(col,row){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}let f=col.render(row);return h("td",o,f)}function renderGroup(grp){const b=h("button",{title:grp.expand,onClick:event=>{grp.expand=grp.expand?false:true;event.currentTarget.value=grp.expand?"▼":"►";spec.time=Date.now();event.preventDefault()},style:{padding:0,margin:"0 6px 0 0",width:"12px",height:"100%",border:"none",outline:0,backgroundColor:"transparent"}},grp.expand?"▼":"►");const v=grp.content||grp.group;return h("tr",{},h("td",{colspan:spec.columns.length,class:spec.group.class},[b,v]))}function renderRow(index,row){const o={};const r=[];o.key=index;o.index=index;if(props.rowid){o.rowid=row[props.rowid]}for(let i=0;i<spec.columns.length;i+=1){let v;const c=spec.columns[i];if(c.render){v=renderCustomCell(c,row);r.push(v)}else{if(c.depth){v=row;for(let j=0;j<c.depth.length;j+=1){if(v)v=v[c.depth[j]]}}else{v=row[c.name]}r.push(renderCell(c,v))}}o.ondblclick=event=>{const r=rows[event.currentTarget.attributes.index.value];emit("onRowDblClick",event,r)};if(props.onRowClick){o.onClick=event=>{const r=rows[event.currentTarget.attributes.index.value];props.onRowClick(event,r)}}return h("tr",o,r)}function renderHeader(){let ar=[];let sp=1;for(let i=0;i<spec.columns.length;i+=1){if(sp>1){sp--;continue}const cl=[];if(spec.columns[i].label){cl.push(h("span",spec.columns[i].label))}else{cl.push(h("span",spec.columns[i].name))}if(spec.sort&&spec.sort.length>0&&spec.sort[0].index==i){if(spec.sort[0].dir=="desc")cl.push(h("span",{style:{float:"right"}},"▼"));else cl.push(h("span",{style:{float:"right"}},"▲"))}let ch={position:"relative"};if(spec.columns[i].width){ch.width=spec.columns[i].width;ch.minWidth=spec.columns[i].width;ch.maxWidth=spec.columns[i].width}let cy={display:"block","font-weight":500,textDecoration:"none",textAlign:"center"};if(spec.columns[i].header){if(spec.columns[i].header.colspan)sp=parseInt(spec.columns[i].header.colspan)||1;if(spec.columns[i].header.style)ch.style=spec.columns[i].header.style;if(spec.columns[i].header.align)ch.textAlign=spec.columns[i].header.align}let a;let f;if(spec.columns[i].popup){const r=ref(null);let c=[h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Ascending"),h("a",{href:"#",onClick(event){orderby(i,"desc");event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Descending")];a=h("a",{href:"#",onClick(event){if(r.value&&r.value.style&&r.value.style.display&&r.value.style.display=="block")r.value.style.display="none";else r.value.style.display="block";event.preventDefault()},style:cy},cl);f=h("div",{ref:r,style:{position:"absolute",display:"none",width:spec.columns[i].width||"12rem",height:"fit-content",border:"1px solid lightgray",backgroundColor:"whitesmoke",zIndex:1,left:0,top:"2rem",bottom:0,right:0,padding:".25rem"}},c)}else a=h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:cy},cl);if(spec.columns[i].filter){}ar.push(h("th",{colspan:sp>1?sp:null,style:ch},[a,f]))}const tr=h("tr",{},ar);return[tr]}function renderBody(){const dr=[];if(rows&&rows.length>0){if(grps&&grps.length>0){let r=[];for(let g=0;g<grps.length;g++)r.push({index:g,childs:[]});for(let i=0;i<rows.length;i++){const x=rowg[i];r[x].childs.push(renderRow(i,rows[i]))}for(let g=0;g<grps.length;g++){dr.push(renderGroup(grps[g]));if(grps[g].expand)dr.push(r[g].childs)}}else{for(let i=0;i<rows.length;i++){dr.push(renderRow(i,rows[i]))}}}return dr}function renderFooter(){const fr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:first,disabled:spec.page.current==1},"◀◀");const ls=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:last,disabled:spec.page.count==0},"▶▶");const pg=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem"},spec.page.current);const pr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:prior,disabled:spec.page.current==1},"◀");const nx=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:next,disabled:spec.page.count>0&&spec.page.current==spec.page.count},"▶");const td=h("td",{colspan:spec.columns.length,align:"center"},[fr,pr,pg,nx,ls]);const tr=h("tr",{},[td]);return[tr]}function renderCaption(){return null}if(spec.columns.length==0){alert("Columns not defined !")}for(let i=0;i<spec.columns.length;i++)if(spec.columns[i].name&&spec.columns[i].name.indexOf(".")>-1){spec.columns[i].depth=spec.columns[i].name.split(".")}page(1);onMounted(()=>{});return{spec:spec,renderHeader:renderHeader,renderBody:renderBody,renderFooter:renderFooter,renderCaption:renderCaption}},render(props){let prps={class:"tablevu"};if(props.class)prps.class="tablevu "+props.class;if(props.style)prps.style=props.style;let cntn=[];cntn.push(h("thead",{},this.renderHeader()));if(this.spec.status==tablevuStatuses.Ready)cntn.push(h("tbody",{"data-time":this.spec.time},this.renderBody()));if(this.spec.caption)cntn.push(h("caption",{},this.renderCaption()));if(this.spec.page.size>0)cntn.push(h("tfoot",{},this.renderFooter()));return h("table",prps,cntn)}};export default tablevu;
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tablevu",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "vue 3 data table",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
7
7
|
"dist": "dist"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
+
"build": "babel src -d lib",
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
12
|
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
},
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
16
15
|
"url": "git+https://github.com/endb/tablevu.git"
|
|
@@ -30,6 +29,8 @@
|
|
|
30
29
|
},
|
|
31
30
|
"homepage": "https://github.com/endb/tablevu#readme",
|
|
32
31
|
"devDependencies": {
|
|
32
|
+
"@babel/cli": "^7.21.0",
|
|
33
|
+
"@babel/core": "^7.21.4",
|
|
33
34
|
"vue": ">=3.0.0"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/src/get.js
CHANGED
|
@@ -10,11 +10,8 @@ export default function get(req) {
|
|
|
10
10
|
else
|
|
11
11
|
r = res;
|
|
12
12
|
|
|
13
|
-
if (res.hasOwnProperty('@odata')) {
|
|
14
|
-
|
|
15
|
-
c = parseInt(res['@odata'].count);
|
|
16
|
-
else
|
|
17
|
-
c = 0;
|
|
13
|
+
if (res.hasOwnProperty('@odata.count')) {
|
|
14
|
+
c = parseInt(res['@odata.count']);
|
|
18
15
|
} else if (res.hasOwnProperty('count'))
|
|
19
16
|
c = parseInt(res['count']);
|
|
20
17
|
else
|
package/src/table.js
CHANGED
|
@@ -289,6 +289,10 @@ const tablevu = {
|
|
|
289
289
|
o.colspan = col.colspan;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
if (col.style) {
|
|
293
|
+
o.style = col.style;
|
|
294
|
+
}
|
|
295
|
+
|
|
292
296
|
if (col.align) {
|
|
293
297
|
o.style['text-align'] = col.align;
|
|
294
298
|
}
|
|
@@ -297,14 +301,6 @@ const tablevu = {
|
|
|
297
301
|
o.style['max-width'] = col.width;
|
|
298
302
|
}
|
|
299
303
|
|
|
300
|
-
if (col.color) {
|
|
301
|
-
o.style['color'] = col.color;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (col.backgroundColor) {
|
|
305
|
-
o.style['background-color'] = col.backgroundColor;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
304
|
const v = renderValue(col, val);
|
|
309
305
|
|
|
310
306
|
return h('td', o, v);
|
|
@@ -317,6 +313,10 @@ const tablevu = {
|
|
|
317
313
|
o.colspan = col.colspan;
|
|
318
314
|
}
|
|
319
315
|
|
|
316
|
+
if (col.style) {
|
|
317
|
+
o.style = col.style;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
320
|
if (col.align) {
|
|
321
321
|
o.style['text-align'] = col.align;
|
|
322
322
|
}
|
|
@@ -421,20 +421,17 @@ const tablevu = {
|
|
|
421
421
|
ch.maxWidth = spec.columns[i].width;
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
let cy = { display: 'block', 'font-weight': 500, textDecoration: 'none',
|
|
424
|
+
let cy = { display: 'block', 'font-weight': 500, textDecoration: 'none', textAlign: 'center' };
|
|
425
425
|
|
|
426
426
|
if (spec.columns[i].header) {
|
|
427
427
|
if (spec.columns[i].header.colspan)
|
|
428
428
|
sp = parseInt(spec.columns[i].header.colspan) || 1;
|
|
429
429
|
|
|
430
|
-
if (spec.columns[i].header.
|
|
431
|
-
|
|
430
|
+
if (spec.columns[i].header.style)
|
|
431
|
+
ch.style = spec.columns[i].header.style;
|
|
432
432
|
|
|
433
|
-
if (spec.columns[i].header.
|
|
434
|
-
ch.
|
|
435
|
-
|
|
436
|
-
if (spec.columns[i].header.color)
|
|
437
|
-
cy.color = spec.columns[i].header.color;
|
|
433
|
+
if (spec.columns[i].header.align)
|
|
434
|
+
ch.textAlign = spec.columns[i].header.align;
|
|
438
435
|
}
|
|
439
436
|
|
|
440
437
|
let a;
|
|
@@ -497,11 +494,11 @@ const tablevu = {
|
|
|
497
494
|
}
|
|
498
495
|
|
|
499
496
|
function renderFooter() {
|
|
500
|
-
const fr = h('button', { class: spec.footer.button.class, style: 'margin-right: .5rem', onClick: first, disabled: spec.page.current == 1 }, '◀◀');
|
|
501
|
-
const ls = h('button', { class: spec.footer.button.class, style: 'margin-right: .5rem', onClick: last, disabled: spec.page.count == 0 }, '▶▶');
|
|
502
|
-
const pg = h('button', { class: spec.footer.button.class, style: 'margin-right: .5rem' }, spec.page.current);
|
|
503
|
-
const pr = h('button', { class: spec.footer.button.class, style: 'margin-right: .5rem', onClick: prior, disabled: spec.page.current == 1 }, '◀');
|
|
504
|
-
const nx = h('button', { class: spec.footer.button.class, style: 'margin-right: .5rem', onClick: next, disabled: spec.page.count > 0 && spec.page.current == spec.page.count }, '▶');
|
|
497
|
+
const fr = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: first, disabled: spec.page.current == 1 }, '◀◀');
|
|
498
|
+
const ls = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: last, disabled: spec.page.count == 0 }, '▶▶');
|
|
499
|
+
const pg = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem' }, spec.page.current);
|
|
500
|
+
const pr = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: prior, disabled: spec.page.current == 1 }, '◀');
|
|
501
|
+
const nx = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: next, disabled: spec.page.count > 0 && spec.page.current == spec.page.count }, '▶');
|
|
505
502
|
const td = h('td', { colspan: spec.columns.length, align: 'center' }, [fr, pr, pg, nx, ls]);
|
|
506
503
|
const tr = h('tr', {}, [td]);
|
|
507
504
|
|