mgsdatatable 1.0.5 → 1.0.6
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 +42 -23
- package/dist/mgsdatatable.min.js +2 -2
- package/package.json +1 -1
- package/src/index.js +3 -2
package/README.md
CHANGED
|
@@ -30,34 +30,14 @@ Two way to use it.
|
|
|
30
30
|
<!DOCTYPE html>
|
|
31
31
|
<html>
|
|
32
32
|
<head>
|
|
33
|
-
<title>mgsDataTable
|
|
33
|
+
<title>mgsDataTable</title>
|
|
34
34
|
<script src="https://cdn.jsdelivr.net/npm/mgsdatatable@1.0.4/dist/mgsdatatable.min.js"></script>
|
|
35
35
|
</head>
|
|
36
36
|
<body>
|
|
37
37
|
<table id="myTable"></table>
|
|
38
38
|
<script>
|
|
39
39
|
mgsDataTable({
|
|
40
|
-
target:
|
|
41
|
-
url: '/api/data',
|
|
42
|
-
methodType: 'post',
|
|
43
|
-
data: { token: 'your-token' },
|
|
44
|
-
page: 1,
|
|
45
|
-
limit: 10
|
|
46
|
-
});
|
|
47
|
-
</script>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
2 ->
|
|
53
|
-
<div id="tableContainer"></div>
|
|
54
|
-
|
|
55
|
-
<script type="module">
|
|
56
|
-
import mgsDataTable from 'mgsdatatable';
|
|
57
|
-
|
|
58
|
-
// Call the function to render table
|
|
59
|
-
mgsDataTable({
|
|
60
|
-
target:"#tableContainer",
|
|
40
|
+
target:"#myTable",
|
|
61
41
|
url:'http://localhost/mgs/users',
|
|
62
42
|
data: {},
|
|
63
43
|
methodType:'post', // Optional, default is post
|
|
@@ -75,7 +55,46 @@ Two way to use it.
|
|
|
75
55
|
isPagination:true, // Optional, default true
|
|
76
56
|
isSorting:true // Optional, default true
|
|
77
57
|
});
|
|
78
|
-
</script>
|
|
58
|
+
</script>
|
|
59
|
+
</body>
|
|
60
|
+
</html>
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
2 ->
|
|
64
|
+
<!DOCTYPE html>
|
|
65
|
+
<html>
|
|
66
|
+
<head>
|
|
67
|
+
<title>mgsDataTable</title>
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
<div id="tableContainer"></div>
|
|
71
|
+
|
|
72
|
+
<script type="module">
|
|
73
|
+
import mgsDataTable from 'mgsdatatable';
|
|
74
|
+
|
|
75
|
+
// Call the function to render table
|
|
76
|
+
mgsDataTable({
|
|
77
|
+
target:"#tableContainer",
|
|
78
|
+
url:'http://localhost/mgs/users',
|
|
79
|
+
data: {},
|
|
80
|
+
methodType:'post', // Optional, default is post
|
|
81
|
+
pageLimits : [10,20,30,50,100], // Optional
|
|
82
|
+
page : 1, // Optional, default is 1
|
|
83
|
+
limit:10, // Optional, default is 10
|
|
84
|
+
column : '', // Optional, default is ''
|
|
85
|
+
sort : 'asc', // Optional, default is asc
|
|
86
|
+
search: '', // Optional, default is ''
|
|
87
|
+
prevPage: null, // Optional, default is null
|
|
88
|
+
nextPage: null, // Optional, default is null
|
|
89
|
+
isLimit:true, // Optional, default true
|
|
90
|
+
isSearch:true, // Optional, default true
|
|
91
|
+
isResult:true, // Optional, default true
|
|
92
|
+
isPagination:true, // Optional, default true
|
|
93
|
+
isSorting:true // Optional, default true
|
|
94
|
+
});
|
|
95
|
+
</script>
|
|
96
|
+
</body>
|
|
97
|
+
</html>
|
|
79
98
|
```
|
|
80
99
|
|
|
81
100
|
## api 'http://localhost/mgs/users' responsed like this format -
|
package/dist/mgsdatatable.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mgsDataTable={})}(this,function(e){"use strict";function t(e,t,n,o,r,i
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mgsDataTable={})}(this,function(e){"use strict";function t(e,t,n,o,r,a,i){try{var l=e[a](i),c=l.value}catch(e){return void n(e)}l.done?t(c):Promise.resolve(c).then(o,r)}function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function r(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach(function(t){n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function a(e,t){if(null==e)return{};var n,o,r=function(e,t){if(null==e)return{};var n={};for(var o in e)if({}.hasOwnProperty.call(e,o)){if(-1!==t.indexOf(o))continue;n[o]=e[o]}return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)n=a[o],-1===t.indexOf(n)&&{}.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function i(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
-
var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var a=o&&o.prototype instanceof s?o:s,d=Object.create(a.prototype);return l(d,"_invoke",function(n,o,r){var i,a,l,s=0,d=r||[],u=!1,p={p:0,n:0,v:e,a:g,f:g.bind(e,4),d:function(t,n){return i=t,a=0,l=e,p.n=n,c}};function g(n,o){for(a=n,l=o,t=0;!u&&s&&!r&&t<d.length;t++){var r,i=d[t],g=p.p,f=i[2];n>3?(r=f===o)&&(l=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=g&&((r=n<2&&g<i[1])?(a=0,p.v=o,p.n=i[1]):g<f&&(r=n<3||i[0]>o||o>f)&&(i[4]=n,i[5]=o,p.n=f,a=0))}if(r||n>1)return c;throw u=!0,o}return function(r,d,f){if(s>1)throw TypeError("Generator is already running");for(u&&1===d&&g(d,f),a=d,l=f;(t=a<2?e:l)||!u;){i||(a?a<3?(a>1&&(p.n=-1),g(a,l)):p.n=l:p.v=l);try{if(s=2,i){if(a||(r="next"),t=i[r]){if(!(t=t.call(i,l)))throw TypeError("iterator result is not an object");if(!t.done)return t;l=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(l=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(u=p.n<0)?l:n.call(o,p))!==c)break}catch(t){i=e,a=1,l=t}finally{s=1}}return{value:t,done:u}}}(n,r,i),!0),d}var c={};function s(){}function d(){}function u(){}t=Object.getPrototypeOf;var p=[][o]?t(t([][o]())):(l(t={},o,function(){return this}),t),g=u.prototype=s.prototype=Object.create(p);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,l(e,r,"GeneratorFunction")),e.prototype=Object.create(g),e}return d.prototype=u,l(g,"constructor",u),l(u,"constructor",d),d.displayName="GeneratorFunction",l(u,r,"GeneratorFunction"),l(g),l(g,r,"Generator"),l(g,o,function(){return this}),l(g,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:f}})()}function l(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}l=function(e,t,n,o){function i(t,n){l(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},l(e,t,n,o)}var c=["token"],s={target:"",url:"",methodType:"post",data:{},pageLimits:[10,20,30,50,100],page:1,limit:10,column:"",sort:"asc",search:"",prevPage:null,nextPage:null,isSearch:!0,isLimit:!0,isResult:!0,isPagination:!0,isSorting:!0},d=0,u=function(){var e,o=(e=a().m(function e(t){var o,l,u,g,f,m,v,y,h,b,x,P,w,_,L,S,T,j,O,k,E,C,A,I,M,H,D,N,R,q,F,z,G,U,B,J,X,K,Q,V,W,Y,Z,$,ee,te,ne,oe,re,ie,ae,le,ce,se,de,ue,pe,ge,fe,me,ve,ye,he,be,xe,Pe,we,_e,Le,Se,Te,je,Oe,ke,Ee,Ce,Ae,Ie,Me,He,De,Ne,Re,qe,Fe,ze,Ge,Ue,Be,Je,Xe,Ke,Qe,Ve,We,Ye;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(s=r(r({},s),t),null!==(o=s)&&void 0!==o&&o.target){e.n=1;break}return alert("Target is requied."),e.a(2);case 1:if(null!==(l=s)&&void 0!==l&&l.url){e.n=2;break}return alert("URL is requied."),e.a(2);case 2:return z=null===(u=s)||void 0===u?void 0:u.target,G=null!==(g=null===(f=s)||void 0===f?void 0:f.url)&&void 0!==g?g:"/",U=r({},null===(m=s)||void 0===m?void 0:m.data),B=U.token,J=i(U,c),X=null===(v=s)||void 0===v?void 0:v.methodType,K=null!==(y=null===(h=s)||void 0===h?void 0:h.page)&&void 0!==y?y:1,Q=null!==(b=null===(x=s)||void 0===x?void 0:x.limit)&&void 0!==b?b:10,V=null!==(P=null===(w=s)||void 0===w?void 0:w.pageLimits)&&void 0!==P?P:[10,20,30,50,100],W=null===(_=s)||void 0===_?void 0:_.search,Y=null===(L=s)||void 0===L?void 0:L.column,Z=null===(S=s)||void 0===S?void 0:S.sort,$=null!==(T=null===(j=s)||void 0===j?void 0:j.nextPage)&&void 0!==T?T:null,ee=null!==(O=null===(k=s)||void 0===k?void 0:k.prevPage)&&void 0!==O?O:null,te=null===(E=null===(C=s)||void 0===C?void 0:C.isSearch)||void 0===E||E,ne=null===(A=null===(I=s)||void 0===I?void 0:I.isLimit)||void 0===A||A,oe=null===(M=null===(H=s)||void 0===H?void 0:H.isResult)||void 0===M||M,re=null===(D=null===(N=s)||void 0===N?void 0:N.isPagination)||void 0===D||D,ie=null===(R=null===(q=s)||void 0===q?void 0:q.isSorting)||void 0===R||R,J=r(r({},J),{},{page:K,limit:Q}),null!=W&&null!=W&&""!=W.trim()&&(J=r(r({},J),{},{search:W})),null!=Y&&null!=Y&&""!=Y.trim()&&(J=r(r({},J),{},{column:Y,sort:Z})),ae="post"===X.toLowerCase(),(le=new Headers).append("Content-Type","application/json"),ae&&le.append("X-CSRF-Token",B),ce={method:null===(F=s)||void 0===F?void 0:F.methodType,headers:le,body:JSON.stringify(J)},se=document.querySelector(z),(de=se.nextElementSibling)&&de.classList.contains("_mgsPaginateResult")&&de.remove(),(ue=se.querySelector("tbody"))&&ue.remove(),(pe=document.createElement("div")).className="_mgsSpinner",pe.innerHTML='<i class="fa fa-spinner fa-spin"></i> Loading...',pe.style.cssText="\n position: fixed;\n z-index: 1031;\n width: 70%;\n height: 30%;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 20px;\n ",e.p=3,e.n=4,fetch(G,ce);case 4:return ye=e.v,e.n=5,ye.json();case 5:if(he=e.v,be=null!==(ge=null==he?void 0:he.data)&&void 0!==ge?ge:[],xe=null!==(fe=null==he||null===(me=he.data)||void 0===me?void 0:me.data)&&void 0!==fe?fe:[],Pe=null!==(ve=null==he?void 0:he.column)&&void 0!==ve?ve:[],we=null!=(null==be?void 0:be.from)&&null!=(null==be?void 0:be.from)&&""!=(null==be?void 0:be.from)?null==be?void 0:be.from:0,_e=null!=(null==be?void 0:be.to)&&null!=(null==be?void 0:be.to)&&""!=(null==be?void 0:be.to)?null==be?void 0:be.to:0,Le=null!=(null==be?void 0:be.total)&&null!=(null==be?void 0:be.total)&&""!=(null==be?void 0:be.total)?null==be?void 0:be.total:0,Se=Math.ceil(Le/Q),Te=Se+2,$=Se>0&&null==$&&null==ee?2:$,se.insertAdjacentElement("beforebegin",pe),0==d&&(te||ne)&&(je="",ne&&V.forEach(function(e){je+='<option value="'.concat(e,'">').concat(e,"</option>")}),Oe='\n <div class="row _mgsPerPageSearch"> \n '.concat(ne?'<div class="_mgsPerPageStyle"> \n <span>Show</span>\n <select class="_mgsPerPageLimit form-control" name="_mgsPerPageLimit" style="width:100px !important">'.concat(je,"</select>\n </div>"):"","\n ").concat(te?'<div class="_mgsSearchStyle"> \n <span>Search</span> \n <input type="text" class="form-control _mgsSearchAnyField" name="_mgsSearchAnyField" value="'.concat(W,'" placeholder="Search any field...">\n </div> '):"","\n </div>\n "),se.insertAdjacentHTML("beforebegin",Oe),(ke=document.querySelector("._mgsPerPageSearch"))&&(ke.style.display="flex",ke.style.justifyContent="space-between",ke.style.alignItems="center",ke.style.gap="10px",ke.style.paddingLeft="14px",ke.style.paddingRight="14px",ke.style.marginBottom="10px",(Ee=ke.querySelector('input[type="search"]'))&&(Ee.style.flex="1",Ee.style.padding="6px 10px",Ee.style.border="1px solid #ccc",Ee.style.borderRadius="4px"),(Ce=ke.querySelector("select"))&&(Ce.style.padding="6px 10px",Ce.style.border="1px solid #ccc",Ce.style.borderRadius="4px"))),(Ae=document.createElement("table")).style.cssText="\n width: 100%;\n min-width: 100%;\n max-width: 100%;\n padding: 10px 5px;\n vertical-align: top;\n border: 1px solid rgb(222, 226, 230);\n background-color: #fff;\n color: #212529;\n border-collapse: collapse;\n ",Ie=document.createElement("thead"),Me=document.createElement("tr"),Pe.forEach(function(e,t){e=p(e);var n=document.createElement("th");(null==xe?void 0:xe.length)>0&&ie&&n.classList.add("_mgsSort"),ie?(n.setAttribute("data-column",t),Y&&t==Y&&"desc"==Z?(n.setAttribute("data-sort","desc"),n.innerHTML="".concat(e,' <i class="fa fa-arrow-down" style="font-size:10px !important"></i>')):(n.setAttribute("data-sort","asc"),n.innerHTML="".concat(e,' <i class="fa fa-arrow-up" style="font-size:10px !important"></i>'))):n.innerHTML=e,n.style.cssText="\n background-color: #f8f9fa;\n font-weight: bold;\n cursor: ".concat((null==xe?void 0:xe.length)>0?"pointer":"not-allowed",";\n width: 150px;\n min-width: 150px;\n max-width: 150px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n padding: 2px;\n border-top: 1px solid rgb(222, 226, 230);\n "),Me.appendChild(n)}),Ie.appendChild(Me),Ae.appendChild(Ie),He=document.createElement("tbody"),(null==xe?void 0:xe.length)>0?xe.forEach(function(e,t){var n=document.createElement("tr");Pe.forEach(function(t){var o=document.createElement("td");o.style.cssText="\n width: 150px;\n min-width: 150px;\n max-width: 150px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n padding: 2px;\n border-top: 1px solid rgb(222, 226, 230);\n ",o.innerHTML=e[t],o.title=e[t],n.appendChild(o)}),He.appendChild(n)}):(De=document.createElement("tr"),(Ne=document.createElement("td")).innerHTML="Data not Found",Ne.setAttribute("colspan",null==Pe?void 0:Pe.length),Ne.style.cssText="\n width: 100%;\n padding: 2px;\n border-top: 1px solid rgb(222, 226, 230);\n text-align: center;\n color:red;\n ",De.appendChild(Ne),He.appendChild(De)),Ae.appendChild(He),se.innerHTML="",se.appendChild(Ae),setTimeout(function(){pe.remove()},500),d++,Re="",Te>0)for((qe=document.createElement("style")).textContent="\n ._mgsPagination {\n display: flex;\n list-style: none;\n padding: 0;\n gap: 6px;\n }\n ._mgsPageItem {\n display: inline-block;\n }\n ._mgsPageLink {\n display: flex;\n align-items: center;\n justify-content: center;\n min-width: 36px;\n height: 36px;\n padding: 0 10px;\n border: 1px solid #0ec6d5;\n border-radius: 6px;\n font-size: 14px;\n font-weight: 500;\n color: #0ec6d5;\n text-decoration: none;\n transition: all 0.2s ease-in-out;\n }\n ._mgsPageLink:hover {\n background-color: #0ec6d5;\n color: #fff;\n }\n ._mgsPageItem.active ._mgsPageLink {\n background-color: #0ec6d5;\n color: #fff;\n border-color: #0ec6d5;\n }\n ._mgsPageItem.disabled ._mgsPageLink {\n border-color: #ccc;\n color: #ccc;\n pointer-events: none;\n cursor: not-allowed;\n }\n ",document.head.appendChild(qe),Fe=!0,ze=0;ze<Te;ze++)Ge=n({0:"« Previous"},Te-1,"Next »"),Ue=Ge[ze]?Ge[ze]:ze,Be="« Previous"==Ge[ze]?ee:"Next »"==Ge[ze]?$:ze,Je=null==Be?"cursor: not-allowed !important;":"cursor: pointer !important;",Xe=null==Be?"disabled":Be==K?"active":"",Ke=Ue,2==Te&&(Be=null,Xe="disabled"),Se>5&&["« Previous",1,2,3,"Next »"].includes(Ue)&&K<3?(Ke=Ue,Re+='<li class="_mgsPageItem '.concat(Xe,'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="').concat(Be,'">').concat(Ke,"</a>\n </li>")):Se>5&&K>2?(Xe=null==Be?"disabled":Be+1==K?"active":"",Ke=K>=3&&!["« Previous","Next »"].includes(Ue)?Ue+1:Ue,1==ze?Re+='<li class="_mgsPageItem '.concat(Xe,'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="1">1</a>\n </li>'):K-1<=ze&&K>=ze&&ze<=K+1&&ze<Se-2&&!["« Previous","Next »"].includes(Ue)?Re+='<li class="_mgsPageItem '.concat(Xe,'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="').concat(Be+1,'">').concat(Ke,"</a>\n </li>"):Se>5&&ze>3&&ze<Se-1&&!["« Previous","Next »"].includes(Ue)?Fe&&(Fe=!1,Ke="...",Re+='<li class="_mgsPageItem '.concat(Xe,'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="').concat(Be+1,'">').concat(Ke,"</a>\n </li>")):(Ke=Ue,Re+='<li class="_mgsPageItem '.concat(Xe=null==Be?"disabled":Be==K?"active":"",'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="').concat(Be,'">').concat(Ke,"</a>\n </li>"))):Se>5&&ze>3&&ze<Se-1&&!["« Previous","Next »"].includes(Ue)?Fe&&(Fe=!1,Ke="...",Re+='<li class="_mgsPageItem '.concat(Xe,'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="').concat(Be,'">').concat(Ke,"</a>\n </li>")):(Ke=Ue,Re+='<li class="_mgsPageItem '.concat(Xe,'" style="').concat(Je,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Se,'" href="').concat(Be,'">').concat(Ke,"</a>\n </li>"));Qe='\n <div class="row _mgsPaginateResult">\n '.concat(oe?"<div>Showing ".concat(we," to ").concat(_e," of ").concat(Le," results</div>"):"","\n ").concat(re?'<div style="margin-top:10px;"> \n <ul class="mgsPagination" style="margin-left: auto !important"> \n '.concat(Re,"\n </ul> \n </div> "):"","\n </div>"),se.insertAdjacentHTML("afterend",Qe),(Ve=document.querySelector("._mgsPaginateResult"))&&(Ve.style.display="flex",Ve.style.justifyContent="space-between",Ve.style.alignItems="center",Ve.style.gap="10px",Ve.style.paddingLeft="14px",Ve.style.paddingRight="14px"),e.n=7;break;case 6:e.p=6,Ye=e.v,We='\n <div class="row" style="text-align: center; display: block; margin: 10px auto; font-weight: bold; margin-top:50px;"> \n <p>Error Message : <span style=\'color: red; margin-left:10px;\'>'.concat(Ye.message,"</span></p>\n </div>\n "),se.innerHTML="",se.insertAdjacentHTML("beforebegin",We),pe.remove();case 7:return e.a(2)}},e,null,[[3,6]])}),function(){var n=this,o=arguments;return new Promise(function(r,i){var a=e.apply(n,o);function l(e){t(a,r,i,l,c,"next",e)}function c(e){t(a,r,i,l,c,"throw",e)}l(void 0)})});return function(e){return o.apply(this,arguments)}}();function p(e){return e.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})}document.addEventListener("click",function(e){var t=e.target.closest("._mgsPageItem");if(t){e.preventDefault(),t.textContent.trim();var n=t.querySelector("._mgsPageLink"),o=null==n?void 0:n.getAttribute("href"),r=null==n?void 0:n.getAttribute("data-mxpage");if(!o||"null"===o)return n.setAttribute("disabled",!0),void(n.style.cssText="cursor: not-allowed !important;");var i=parseInt(o),a=i>=r?null:i+1,l=i<=1?null:i-1;null==n||n.setAttribute("href",a),n.style.cssText=null==a||null==l?"cursor: not-allowed !important;":"cursor: pointer !important;",u({page:i,prevPage:l,nextPage:a})}}),document.addEventListener("change",function(e){var t=e.target;if(t.classList.contains("_mgsPerPageLimit")){e.preventDefault();var n=parseInt(t.value,10);u({page:1,limit:n,prevPage:null,nextPage:null})}}),document.addEventListener("keyup",function(e){var t=e.target;if(t.classList.contains("_mgsSearchAnyField")&&(e.preventDefault(),"Enter"===e.key)){var n=t.value;document.querySelectorAll("._mgsSort").forEach(function(e){var t=p(e.textContent.trim());e.innerHTML="".concat(t,' <i class="fa fa-arrow-up" style="font-size:10px !important"></i>'),e.setAttribute("data-sort","asc")}),u({page:1,column:"",sort:"",search:n})}}),document.addEventListener("click",function(e){var t=e.target.closest("._mgsSort");if(t){e.preventDefault();var n=t.getAttribute("data-column"),o=t.getAttribute("data-sort");u({page:1,column:n,sort:"asc"===o?"desc":"asc"})}}),window.mgsDataTable=u,window._mgsCapitalizeFirstLetter=p,e._mgsCapitalizeFirstLetter=p,e.mgsDataTable=u,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
3
|
+
var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function a(n,o,r,a){var i=o&&o.prototype instanceof s?o:s,d=Object.create(i.prototype);return l(d,"_invoke",function(n,o,r){var a,i,l,s=0,d=r||[],u=!1,p={p:0,n:0,v:e,a:g,f:g.bind(e,4),d:function(t,n){return a=t,i=0,l=e,p.n=n,c}};function g(n,o){for(i=n,l=o,t=0;!u&&s&&!r&&t<d.length;t++){var r,a=d[t],g=p.p,f=a[2];n>3?(r=f===o)&&(l=a[(i=a[4])?5:(i=3,3)],a[4]=a[5]=e):a[0]<=g&&((r=n<2&&g<a[1])?(i=0,p.v=o,p.n=a[1]):g<f&&(r=n<3||a[0]>o||o>f)&&(a[4]=n,a[5]=o,p.n=f,i=0))}if(r||n>1)return c;throw u=!0,o}return function(r,d,f){if(s>1)throw TypeError("Generator is already running");for(u&&1===d&&g(d,f),i=d,l=f;(t=i<2?e:l)||!u;){a||(i?i<3?(i>1&&(p.n=-1),g(i,l)):p.n=l:p.v=l);try{if(s=2,a){if(i||(r="next"),t=a[r]){if(!(t=t.call(a,l)))throw TypeError("iterator result is not an object");if(!t.done)return t;l=t.value,i<2&&(i=0)}else 1===i&&(t=a.return)&&t.call(a),i<2&&(l=TypeError("The iterator does not provide a '"+r+"' method"),i=1);a=e}else if((t=(u=p.n<0)?l:n.call(o,p))!==c)break}catch(t){a=e,i=1,l=t}finally{s=1}}return{value:t,done:u}}}(n,r,a),!0),d}var c={};function s(){}function d(){}function u(){}t=Object.getPrototypeOf;var p=[][o]?t(t([][o]())):(l(t={},o,function(){return this}),t),g=u.prototype=s.prototype=Object.create(p);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,l(e,r,"GeneratorFunction")),e.prototype=Object.create(g),e}return d.prototype=u,l(g,"constructor",u),l(u,"constructor",d),d.displayName="GeneratorFunction",l(u,r,"GeneratorFunction"),l(g),l(g,r,"Generator"),l(g,o,function(){return this}),l(g,"toString",function(){return"[object Generator]"}),(i=function(){return{w:a,m:f}})()}function l(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}l=function(e,t,n,o){function a(t,n){l(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(a("next",0),a("throw",1),a("return",2))},l(e,t,n,o)}var c=["token","bearer"],s={target:"",url:"",methodType:"post",data:{},pageLimits:[10,20,30,50,100],page:1,limit:10,column:"",sort:"asc",search:"",prevPage:null,nextPage:null,isSearch:!0,isLimit:!0,isResult:!0,isPagination:!0,isSorting:!0},d=0,u=function(){var e,o=(e=i().m(function e(t){var o,l,u,g,f,m,v,y,b,h,x,P,w,_,L,S,T,j,O,k,E,C,A,I,M,H,D,N,R,q,F,z,G,B,U,J,X,K,Q,V,W,Y,Z,$,ee,te,ne,oe,re,ae,ie,le,ce,se,de,ue,pe,ge,fe,me,ve,ye,be,he,xe,Pe,we,_e,Le,Se,Te,je,Oe,ke,Ee,Ce,Ae,Ie,Me,He,De,Ne,Re,qe,Fe,ze,Ge,Be,Ue,Je,Xe,Ke,Qe,Ve,We,Ye,Ze;return i().w(function(e){for(;;)switch(e.p=e.n){case 0:if(s=r(r({},s),t),null!==(o=s)&&void 0!==o&&o.target){e.n=1;break}return alert("Target is requied."),e.a(2);case 1:if(null!==(l=s)&&void 0!==l&&l.url){e.n=2;break}return alert("URL is requied."),e.a(2);case 2:return z=null===(u=s)||void 0===u?void 0:u.target,G=null!==(g=null===(f=s)||void 0===f?void 0:f.url)&&void 0!==g?g:"/",B=r({},null===(m=s)||void 0===m?void 0:m.data),U=B.token,J=B.bearer,X=a(B,c),K=null===(v=s)||void 0===v?void 0:v.methodType,Q=null!==(y=null===(b=s)||void 0===b?void 0:b.page)&&void 0!==y?y:1,V=null!==(h=null===(x=s)||void 0===x?void 0:x.limit)&&void 0!==h?h:10,W=null!==(P=null===(w=s)||void 0===w?void 0:w.pageLimits)&&void 0!==P?P:[10,20,30,50,100],Y=null===(_=s)||void 0===_?void 0:_.search,Z=null===(L=s)||void 0===L?void 0:L.column,$=null===(S=s)||void 0===S?void 0:S.sort,ee=null!==(T=null===(j=s)||void 0===j?void 0:j.nextPage)&&void 0!==T?T:null,te=null!==(O=null===(k=s)||void 0===k?void 0:k.prevPage)&&void 0!==O?O:null,ne=null===(E=null===(C=s)||void 0===C?void 0:C.isSearch)||void 0===E||E,oe=null===(A=null===(I=s)||void 0===I?void 0:I.isLimit)||void 0===A||A,re=null===(M=null===(H=s)||void 0===H?void 0:H.isResult)||void 0===M||M,ae=null===(D=null===(N=s)||void 0===N?void 0:N.isPagination)||void 0===D||D,ie=null===(R=null===(q=s)||void 0===q?void 0:q.isSorting)||void 0===R||R,X=r(r({},X),{},{page:Q,limit:V}),null!=Y&&null!=Y&&""!=Y.trim()&&(X=r(r({},X),{},{search:Y})),null!=Z&&null!=Z&&""!=Z.trim()&&(X=r(r({},X),{},{column:Z,sort:$})),le="post"===K.toLowerCase(),(ce=new Headers).append("Content-Type","application/json"),le&&U&&ce.append("X-CSRF-Token",U),J&&ce.append("Authorization","Bearer ".concat(J)),se={method:null===(F=s)||void 0===F?void 0:F.methodType,headers:ce,body:JSON.stringify(X)},de=document.querySelector(z),(ue=de.nextElementSibling)&&ue.classList.contains("_mgsPaginateResult")&&ue.remove(),(pe=de.querySelector("tbody"))&&pe.remove(),(ge=document.createElement("div")).className="_mgsSpinner",ge.innerHTML='<i class="fa fa-spinner fa-spin"></i> Loading...',ge.style.cssText="\n position: fixed;\n z-index: 1031;\n width: 70%;\n height: 30%;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 20px;\n ",e.p=3,e.n=4,fetch(G,se);case 4:return be=e.v,e.n=5,be.json();case 5:if(he=e.v,xe=null!==(fe=null==he?void 0:he.data)&&void 0!==fe?fe:[],Pe=null!==(me=null==he||null===(ve=he.data)||void 0===ve?void 0:ve.data)&&void 0!==me?me:[],we=null!==(ye=null==he?void 0:he.column)&&void 0!==ye?ye:[],_e=null!=(null==xe?void 0:xe.from)&&null!=(null==xe?void 0:xe.from)&&""!=(null==xe?void 0:xe.from)?null==xe?void 0:xe.from:0,Le=null!=(null==xe?void 0:xe.to)&&null!=(null==xe?void 0:xe.to)&&""!=(null==xe?void 0:xe.to)?null==xe?void 0:xe.to:0,Se=null!=(null==xe?void 0:xe.total)&&null!=(null==xe?void 0:xe.total)&&""!=(null==xe?void 0:xe.total)?null==xe?void 0:xe.total:0,Te=Math.ceil(Se/V),je=Te+2,ee=Te>0&&null==ee&&null==te?2:ee,de.insertAdjacentElement("beforebegin",ge),0==d&&(ne||oe)&&(Oe="",oe&&W.forEach(function(e){Oe+='<option value="'.concat(e,'">').concat(e,"</option>")}),ke='\n <div class="row _mgsPerPageSearch"> \n '.concat(oe?'<div class="_mgsPerPageStyle"> \n <span>Show</span>\n <select class="_mgsPerPageLimit form-control" name="_mgsPerPageLimit" style="width:100px !important">'.concat(Oe,"</select>\n </div>"):"","\n ").concat(ne?'<div class="_mgsSearchStyle"> \n <span>Search</span> \n <input type="text" class="form-control _mgsSearchAnyField" name="_mgsSearchAnyField" value="'.concat(Y,'" placeholder="Search any field...">\n </div> '):"","\n </div>\n "),de.insertAdjacentHTML("beforebegin",ke),(Ee=document.querySelector("._mgsPerPageSearch"))&&(Ee.style.display="flex",Ee.style.justifyContent="space-between",Ee.style.alignItems="center",Ee.style.gap="10px",Ee.style.paddingLeft="14px",Ee.style.paddingRight="14px",Ee.style.marginBottom="10px",(Ce=Ee.querySelector('input[type="search"]'))&&(Ce.style.flex="1",Ce.style.padding="6px 10px",Ce.style.border="1px solid #ccc",Ce.style.borderRadius="4px"),(Ae=Ee.querySelector("select"))&&(Ae.style.padding="6px 10px",Ae.style.border="1px solid #ccc",Ae.style.borderRadius="4px"))),(Ie=document.createElement("table")).style.cssText="\n width: 100%;\n min-width: 100%;\n max-width: 100%;\n padding: 10px 5px;\n vertical-align: top;\n border: 1px solid rgb(222, 226, 230);\n background-color: #fff;\n color: #212529;\n border-collapse: collapse;\n ",Me=document.createElement("thead"),He=document.createElement("tr"),we.forEach(function(e,t){e=p(e);var n=document.createElement("th");(null==Pe?void 0:Pe.length)>0&&ie&&n.classList.add("_mgsSort"),ie?(n.setAttribute("data-column",t),Z&&t==Z&&"desc"==$?(n.setAttribute("data-sort","desc"),n.innerHTML="".concat(e,' <i class="fa fa-arrow-down" style="font-size:10px !important"></i>')):(n.setAttribute("data-sort","asc"),n.innerHTML="".concat(e,' <i class="fa fa-arrow-up" style="font-size:10px !important"></i>'))):n.innerHTML=e,n.style.cssText="\n background-color: #f8f9fa;\n font-weight: bold;\n cursor: ".concat((null==Pe?void 0:Pe.length)>0?"pointer":"not-allowed",";\n width: 150px;\n min-width: 150px;\n max-width: 150px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n padding: 2px;\n border-top: 1px solid rgb(222, 226, 230);\n "),He.appendChild(n)}),Me.appendChild(He),Ie.appendChild(Me),De=document.createElement("tbody"),(null==Pe?void 0:Pe.length)>0?Pe.forEach(function(e,t){var n=document.createElement("tr");we.forEach(function(t){var o=document.createElement("td");o.style.cssText="\n width: 150px;\n min-width: 150px;\n max-width: 150px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n padding: 2px;\n border-top: 1px solid rgb(222, 226, 230);\n ",o.innerHTML=e[t],o.title=e[t],n.appendChild(o)}),De.appendChild(n)}):(Ne=document.createElement("tr"),(Re=document.createElement("td")).innerHTML="Data not Found",Re.setAttribute("colspan",null==we?void 0:we.length),Re.style.cssText="\n width: 100%;\n padding: 2px;\n border-top: 1px solid rgb(222, 226, 230);\n text-align: center;\n color:red;\n ",Ne.appendChild(Re),De.appendChild(Ne)),Ie.appendChild(De),de.innerHTML="",de.appendChild(Ie),setTimeout(function(){ge.remove()},500),d++,qe="",je>0)for((Fe=document.createElement("style")).textContent="\n ._mgsPagination {\n display: flex;\n list-style: none;\n padding: 0;\n gap: 6px;\n }\n ._mgsPageItem {\n display: inline-block;\n }\n ._mgsPageLink {\n display: flex;\n align-items: center;\n justify-content: center;\n min-width: 36px;\n height: 36px;\n padding: 0 10px;\n border: 1px solid #0ec6d5;\n border-radius: 6px;\n font-size: 14px;\n font-weight: 500;\n color: #0ec6d5;\n text-decoration: none;\n transition: all 0.2s ease-in-out;\n }\n ._mgsPageLink:hover {\n background-color: #0ec6d5;\n color: #fff;\n }\n ._mgsPageItem.active ._mgsPageLink {\n background-color: #0ec6d5;\n color: #fff;\n border-color: #0ec6d5;\n }\n ._mgsPageItem.disabled ._mgsPageLink {\n border-color: #ccc;\n color: #ccc;\n pointer-events: none;\n cursor: not-allowed;\n }\n ",document.head.appendChild(Fe),ze=!0,Ge=0;Ge<je;Ge++)Be=n({0:"« Previous"},je-1,"Next »"),Ue=Be[Ge]?Be[Ge]:Ge,Je="« Previous"==Be[Ge]?te:"Next »"==Be[Ge]?ee:Ge,Xe=null==Je?"cursor: not-allowed !important;":"cursor: pointer !important;",Ke=null==Je?"disabled":Je==Q?"active":"",Qe=Ue,2==je&&(Je=null,Ke="disabled"),Te>5&&["« Previous",1,2,3,"Next »"].includes(Ue)&&Q<3?(Qe=Ue,qe+='<li class="_mgsPageItem '.concat(Ke,'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="').concat(Je,'">').concat(Qe,"</a>\n </li>")):Te>5&&Q>2?(Ke=null==Je?"disabled":Je+1==Q?"active":"",Qe=Q>=3&&!["« Previous","Next »"].includes(Ue)?Ue+1:Ue,1==Ge?qe+='<li class="_mgsPageItem '.concat(Ke,'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="1">1</a>\n </li>'):Q-1<=Ge&&Q>=Ge&&Ge<=Q+1&&Ge<Te-2&&!["« Previous","Next »"].includes(Ue)?qe+='<li class="_mgsPageItem '.concat(Ke,'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="').concat(Je+1,'">').concat(Qe,"</a>\n </li>"):Te>5&&Ge>3&&Ge<Te-1&&!["« Previous","Next »"].includes(Ue)?ze&&(ze=!1,Qe="...",qe+='<li class="_mgsPageItem '.concat(Ke,'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="').concat(Je+1,'">').concat(Qe,"</a>\n </li>")):(Qe=Ue,qe+='<li class="_mgsPageItem '.concat(Ke=null==Je?"disabled":Je==Q?"active":"",'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="').concat(Je,'">').concat(Qe,"</a>\n </li>"))):Te>5&&Ge>3&&Ge<Te-1&&!["« Previous","Next »"].includes(Ue)?ze&&(ze=!1,Qe="...",qe+='<li class="_mgsPageItem '.concat(Ke,'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="').concat(Je,'">').concat(Qe,"</a>\n </li>")):(Qe=Ue,qe+='<li class="_mgsPageItem '.concat(Ke,'" style="').concat(Xe,'">\n <a class="_mgsPageLink" data-mxpage="').concat(Te,'" href="').concat(Je,'">').concat(Qe,"</a>\n </li>"));Ve='\n <div class="row _mgsPaginateResult">\n '.concat(re?"<div>Showing ".concat(_e," to ").concat(Le," of ").concat(Se," results</div>"):"","\n ").concat(ae?'<div style="margin-top:10px;"> \n <ul class="mgsPagination" style="margin-left: auto !important"> \n '.concat(qe,"\n </ul> \n </div> "):"","\n </div>"),de.insertAdjacentHTML("afterend",Ve),(We=document.querySelector("._mgsPaginateResult"))&&(We.style.display="flex",We.style.justifyContent="space-between",We.style.alignItems="center",We.style.gap="10px",We.style.paddingLeft="14px",We.style.paddingRight="14px"),e.n=7;break;case 6:e.p=6,Ze=e.v,Ye='\n <div class="row" style="text-align: center; display: block; margin: 10px auto; font-weight: bold; margin-top:50px;"> \n <p>Error Message : <span style=\'color: red; margin-left:10px;\'>'.concat(Ze.message,"</span></p>\n </div>\n "),de.innerHTML="",de.insertAdjacentHTML("beforebegin",Ye),ge.remove();case 7:return e.a(2)}},e,null,[[3,6]])}),function(){var n=this,o=arguments;return new Promise(function(r,a){var i=e.apply(n,o);function l(e){t(i,r,a,l,c,"next",e)}function c(e){t(i,r,a,l,c,"throw",e)}l(void 0)})});return function(e){return o.apply(this,arguments)}}();function p(e){return e.replace(/_/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})}document.addEventListener("click",function(e){var t=e.target.closest("._mgsPageItem");if(t){e.preventDefault(),t.textContent.trim();var n=t.querySelector("._mgsPageLink"),o=null==n?void 0:n.getAttribute("href"),r=null==n?void 0:n.getAttribute("data-mxpage");if(!o||"null"===o)return n.setAttribute("disabled",!0),void(n.style.cssText="cursor: not-allowed !important;");var a=parseInt(o),i=a>=r?null:a+1,l=a<=1?null:a-1;null==n||n.setAttribute("href",i),n.style.cssText=null==i||null==l?"cursor: not-allowed !important;":"cursor: pointer !important;",u({page:a,prevPage:l,nextPage:i})}}),document.addEventListener("change",function(e){var t=e.target;if(t.classList.contains("_mgsPerPageLimit")){e.preventDefault();var n=parseInt(t.value,10);u({page:1,limit:n,prevPage:null,nextPage:null})}}),document.addEventListener("keyup",function(e){var t=e.target;if(t.classList.contains("_mgsSearchAnyField")&&(e.preventDefault(),"Enter"===e.key)){var n=t.value;document.querySelectorAll("._mgsSort").forEach(function(e){var t=p(e.textContent.trim());e.innerHTML="".concat(t,' <i class="fa fa-arrow-up" style="font-size:10px !important"></i>'),e.setAttribute("data-sort","asc")}),u({page:1,column:"",sort:"",search:n})}}),document.addEventListener("click",function(e){var t=e.target.closest("._mgsSort");if(t){e.preventDefault();var n=t.getAttribute("data-column"),o=t.getAttribute("data-sort");u({page:1,column:n,sort:"asc"===o?"desc":"asc"})}}),window.mgsDataTable=u,window._mgsCapitalizeFirstLetter=p,e._mgsCapitalizeFirstLetter=p,e.mgsDataTable=u,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -30,7 +30,7 @@ const mgsDataTable = async (data) => {
|
|
|
30
30
|
}
|
|
31
31
|
let _mgsTarget = _mgsCommonData?.target;
|
|
32
32
|
let _mgsFullUrl = _mgsCommonData?.url ?? '/';
|
|
33
|
-
let { token, ...allData} = {..._mgsCommonData?.data};
|
|
33
|
+
let { token, bearer, ...allData} = {..._mgsCommonData?.data};
|
|
34
34
|
let methodType = _mgsCommonData?.methodType;
|
|
35
35
|
let page = _mgsCommonData?.page ?? 1;
|
|
36
36
|
let limit = _mgsCommonData?.limit ?? 10;
|
|
@@ -58,7 +58,8 @@ const mgsDataTable = async (data) => {
|
|
|
58
58
|
// Prepare headers and body
|
|
59
59
|
const headers = new Headers();
|
|
60
60
|
headers.append("Content-Type", "application/json");
|
|
61
|
-
if (_mgsIsPost) headers.append("X-CSRF-Token", token);
|
|
61
|
+
if (_mgsIsPost && token) headers.append("X-CSRF-Token", token);
|
|
62
|
+
if (bearer) headers.append("Authorization", `Bearer ${bearer}`);
|
|
62
63
|
|
|
63
64
|
const _mgsOptions = {
|
|
64
65
|
method: _mgsCommonData?.methodType,
|