From cbb1eeab90a1f28c399f6598e2dc50e9bf5adb7c Mon Sep 17 00:00:00 2001 From: Mobius1 Date: Wed, 12 Apr 2017 18:20:58 +0100 Subject: [PATCH] v1.1.7 --- bower.json | 2 +- package.json | 2 +- vanilla-dataTables.js | 110 ++++++++++++++++++++++++++++++++++---- vanilla-dataTables.min.js | 4 +- 4 files changed, 105 insertions(+), 13 deletions(-) diff --git a/bower.json b/bower.json index 9369ecf..179035f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "vanilla-datatables", - "version": "1.1.6", + "version": "1.1.7", "ignore": [ ".gitattributes", "README.md" diff --git a/package.json b/package.json index d07553f..cbb49cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vanilla-datatables", - "version": "1.1.6", + "version": "1.1.7", "description": "A lightweight, dependency-free javascript HTML table plugin.", "main": "vanilla-dataTables.min.js", "scripts": { diff --git a/vanilla-dataTables.js b/vanilla-dataTables.js index f799cba..82ce23f 100644 --- a/vanilla-dataTables.js +++ b/vanilla-dataTables.js @@ -4,7 +4,7 @@ * Copyright (c) 2015-2017 Karl Saunders (http://mobiuswebdesign.co.uk) * Licensed under MIT (http://www.opensource.org/licenses/mit-license.php) * - * Version: 1.1.6 + * Version: 1.1.7 * */ (function(root, factory) { @@ -780,6 +780,8 @@ }, }; + _.initialized = false; + // user options _.options = util.extend(defaults, options); @@ -834,19 +836,74 @@ _.table = table; + this.init(); + } + + /** + * Initialize the instance + * @param {object} options + * @return {void} + */ + DataTable.prototype.init = function(options) { + + if ( this.initialized || util.hasClass(this.table, "dataTable-table") ) { + return false; + } + + var _ = this; + + this.options = util.extend(this.options, options || {}); + // IE detection - _.isIE = !!/(msie|trident)/i.test(navigator.userAgent); + this.isIE = !!/(msie|trident)/i.test(navigator.userAgent); - _.currentPage = 1; - _.onFirstPage = true; + this.currentPage = 1; + this.onFirstPage = true; - build.call(_); + build.call(this); setTimeout(function() { _.emit('datatable.init'); + _.initialized = true; }, 10); - } + }; + + /** + * Destroy the instance + * @return {void} + */ + DataTable.prototype.destroy = function() { + var o = this.options; + + // Remove the sorters + if ( o.sortable ) { + util.each(this.tHead.rows[0].cells, function(i, th) { + var html = th.firstElementChild.innerHTML; + th.innerHTML = html; + th.removeAttribute("style"); + }, this); + } + + // Populate the table + var f = util.createFragment(); + util.each(this.rows, function(i, tr) { + f.appendChild(tr); + }, this); + this.clear(f); + // Remove the className + util.removeClass(this.table, "dataTable-table"); + + // Remove the containers + this.wrapper.parentNode.replaceChild(this.table, this.wrapper); + + this.initialized = false; + }; + + /** + * Update the instance + * @return {[type]} [description] + */ DataTable.prototype.update = function() { var _ = this; @@ -866,6 +923,11 @@ _.emit('datatable.update'); }; + /** + * Perform a search of the data set + * @param {string} query + * @return {void} + */ DataTable.prototype.search = function(query) { var _ = this; @@ -905,7 +967,11 @@ _.emit("datatable.search", query, _.searchData); }; - /* Change the page. */ + /** + * Change page + * @param {int} page + * @return {void} + */ DataTable.prototype.page = function(page) { var _ = this; @@ -928,7 +994,12 @@ _.emit('datatable.page', page); }; - /* Perform the sorting */ + /** + * Sort by column + * @param {int} column - The column no. + * @param {string} direction - asc or desc + * @return {void} + */ DataTable.prototype.sortColumn = function(column, direction) { // Check column is present @@ -1005,6 +1076,10 @@ _.emit('datatable.sort', column, dir); }; + /** + * Add new row data + * @param {object} data + */ DataTable.prototype.addRows = function(data) { if (Object.prototype.toString.call(data) !== '[object Object]') { throw new Error("Function addRows: The method requires an object."); @@ -1029,6 +1104,10 @@ this.update(); }; + /** + * Refresh the instance + * @return {void} + */ DataTable.prototype.refresh = function() { if ( this.options.searchable ) { this.input.value = ''; @@ -1041,6 +1120,11 @@ this.emit("datatable.refresh"); }; + /** + * Truncate the table + * @param {mixes} html - HTML string or HTMLElement + * @return {void} + */ DataTable.prototype.clear = function(html) { if (this.tbody) { util.flush(this.tbody, this.isIE); @@ -1052,10 +1136,18 @@ } if (html) { - util.append(parent, html); + if ( typeof html === "string" ) { + parent.innerHTML = html; + } else { + util.append(parent, html); + } } }; + /** + * Show a message in the table + * @param {string} message + */ DataTable.prototype.setMessage = function(message) { var colspan = this.rows[0].cells.length; this.clear(util.createElement('tr', { diff --git a/vanilla-dataTables.min.js b/vanilla-dataTables.min.js index 95f861d..adfb36b 100644 --- a/vanilla-dataTables.min.js +++ b/vanilla-dataTables.min.js @@ -4,7 +4,7 @@ * Copyright (c) 2015-2017 Karl Saunders (http://mobiuswebdesign.co.uk) * Licensed under MIT (http://www.opensource.org/licenses/mit-license.php) * - * Version: 1.1.6 + * Version: 1.1.7 * */ -!function(a,b){var c="DataTable";"function"==typeof define&&define.amd?define([],b(c)):"object"==typeof exports?module.exports=b(c):a[c]=b(c)}(this,function(a){"use strict";function n(a,d){var e=this,f={perPage:10,perPageSelect:[5,10,15,20,25],sortable:!0,searchable:!0,nextPrev:!0,firstLast:!1,prevText:"‹",nextText:"›",firstText:"«",lastText:"»",truncatePager:!0,pagerDelta:2,fixedColumns:!0,fixedHeight:!1,header:!0,footer:!1,labels:{placeholder:"Search...",perPage:"{select} entries per page",noRows:"No entries found",info:"Showing {start} to {end} of {rows} entries"},layout:{top:"{select}{search}",bottom:"{info}{pager}"}};if(e.options=b.extend(f,d),!a)throw new Error("The plugin requires a table as the first parameter");if("string"==typeof a){var g=a;if(a=document.querySelector(a),!a)throw new Error("The element '"+g+"' can not be found.")}if("table"!==a.tagName.toLowerCase())throw new Error("The selected element is not a table.");if(e.options.header||(e.options.sortable=!1),null===a.tHead&&(!e.options.data||e.options.data&&!e.options.data.headings)&&(e.options.sortable=!1),!a.tBodies.length){if(!e.options.data)throw new Error("You don't seem to have a tbody in your table.");if(!e.options.data.rows)throw new Error("You seem to be using the data option, but you've not defined any rows.")}if(a.tBodies.length&&!a.tBodies[0].rows.length){if(!e.options.data)throw new Error("You don't seem to have any rows in your table.");if(!e.options.data.rows)throw new Error("You seem to be using the data option, but you've not defined any rows.")}e.table=a,e.isIE=!!/(msie|trident)/i.test(navigator.userAgent),e.currentPage=1,e.onFirstPage=!0,c.call(e),setTimeout(function(){e.emit("datatable.init")},10)}var b={extend:function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&("[object Object]"===Object.prototype.toString.call(a[d])?b.extend(a[d],c[d]):a[d]=c[d]);return a},each:function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a))for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,d,a[d],a);else for(var e=0,f=a.length;e-1},button:function(a,c,d){return b.createElement("li",{class:a,html:''+d+""})},flush:function(a,c){if(a instanceof NodeList)b.each(a,function(a,d){b.flush(d,c)});else if(c)for(;a.hasChildNodes();)a.removeChild(a.firstChild);else a.innerHTML=""}},c=function(){var a=this,c=a.options,f="";if(m.mixin(a),c.data&&l.call(a),a.tbody=a.table.tBodies[0],a.tHead=a.table.tHead,a.tFoot=a.table.tFoot,!a.tHead){var g=b.createElement("thead"),h=b.createElement("tr");b.each(a.tbody.rows[0].cells,function(a,c){b.append(h,b.createElement("th"))}),b.append(g,h),a.tHead=g}if(c.header||a.tHead&&a.table.removeChild(a.table.tHead),c.footer?a.tHead&&!a.tFoot&&(a.tFoot=b.createElement("tfoot",{html:a.tHead.innerHTML}),a.table.appendChild(a.tFoot)):a.tFoot&&a.table.removeChild(a.table.tFoot),a.wrapper=b.createElement("div",{class:"dataTable-wrapper"}),f+="
",f+=c.layout.top,f+="
",f+="
",f+="
",f+=c.layout.bottom,f+="
",f=f.replace("{info}","
"),c.perPageSelect){var i="
";var k=b.createElement("select",{class:"dataTable-selector"});b.each(c.perPageSelect,function(a,b){var d=b===c.perPage,e=new Option(b,b,d,d);k.add(e)}),i=i.replace("{select}",k.outerHTML),f=f.replace("{select}",i)}else f=f.replace("{select}","");if(c.searchable){var n="";f=f.replace("{search}",n)}else f=f.replace("{search}","");var o=a.tHead.rows[0].cells;b.each(o,function(a,d){if(d.idx=a,c.sortable){var e=b.createElement("a",{href:"#",class:"dataTable-sorter",html:d.innerHTML});d.innerHTML="",b.append(d,e)}}),b.addClass(a.table,"dataTable-table");var p=b.createElement("div",{class:"dataTable-pagination"}),q=b.createElement("ul");if(b.append(p,q),f=f.replace(/\{pager\}/g,p.outerHTML),a.wrapper.innerHTML=f,a.container=a.wrapper.querySelector(".dataTable-container"),a.paginators=a.wrapper.querySelectorAll(".dataTable-pagination"),a.label=a.wrapper.querySelector(".dataTable-info"),a.table.parentNode.replaceChild(a.wrapper,a.table),a.container.appendChild(a.table),a.rect=b.getBoundingRect(a.table),a.rows=Array.prototype.slice.call(a.tbody.rows),a.update(),c.fixedHeight&&j.call(a),c.fixedColumns){var r,s=!1;if(a.table.tHead)r=a.table.tHead.rows[0].cells,b.each(r,function(c,d){var e=b.getBoundingRect(d),f=e.width/a.rect.width*100;d.style.width=f+"%"});else{r=[],s=b.createElement("thead");var t=b.createElement("tr"),u=a.table.tBodies[0].rows[0].cells;b.each(u,function(a,c){var d=b.createElement("th");t.appendChild(d),r.push(d)}),s.appendChild(t),a.table.insertBefore(s,a.table.tBodies[0]);var v=[];b.each(r,function(c,d){var e=b.getBoundingRect(d),f=e.width/a.rect.width*100;v.push(f)}),b.each(this.rows,function(a,c){b.each(c.cells,function(a,b){b.style.width=v[a]+"%"})}),a.table.removeChild(s)}}d.call(a),e.call(a)},d=function(){var a=this.options;a.header||b.addClass(this.wrapper,"no-header"),a.footer||b.addClass(this.wrapper,"no-footer"),a.sortable&&b.addClass(this.wrapper,"sortable"),a.searchable&&b.addClass(this.wrapper,"searchable"),a.fixedHeight&&b.addClass(this.wrapper,"fixed-height"),a.fixedColumns&&b.addClass(this.wrapper,"fixed-columns")},e=function(){var a=this,c=a.options;if(c.perPageSelect){var d=a.wrapper.querySelector(".dataTable-selector");d&&b.listen(d,"change",function(b){c.perPage=parseInt(this.value,10),a.update(),c.fixedHeight&&j.call(a),a.emit("datatable.perpage")})}c.searchable&&(a.input=a.wrapper.querySelector(".dataTable-input"),a.input&&b.listen(a.input,"keyup",function(b){a.search(this.value)})),b.listen(a.wrapper,"click",function(c){var d=c.target;"a"===d.nodeName.toLowerCase()&&d.hasAttribute("data-page")&&(b.preventDefault(c),a.page(d.getAttribute("data-page")))}),c.sortable&&b.listen(a.tHead,"click",function(c){c=c||window.event;var d=c.target;"a"===d.nodeName.toLowerCase()&&b.hasClass(d,"dataTable-sorter")&&(b.preventDefault(c),a.sortColumn(d.parentNode.idx+1))})},f=function(){var a=this,b=a.options.perPage,c=a.searching?a.searchData:a.rows;a.pages=c.map(function(a,d){return d%b===0?c.slice(d,d+b):null}).filter(function(a){return a}),a.totalPages=a.lastPage=a.pages.length},g=function(){var a=this;if(a.totalPages){a.currentPage>a.totalPages&&(a.currentPage=1);var c=a.currentPage-1,d=b.createFragment();switch(b.each(a.pages[c],function(a,c){b.append(d,c)}),a.clear(d),a.onFirstPage=!1,a.onLastPage=!1,a.currentPage){case 1:a.onFirstPage=!0;break;case a.lastPage:a.onLastPage=!0}}var h,e=0,f=0,g=0;if(a.totalPages&&(e=a.currentPage-1,f=e*a.options.perPage,g=f+a.pages[e].length,f+=1,h=a.searching?a.searchData.length:a.rows.length),a.label&&a.options.labels.info.length){var i=a.options.labels.info.replace("{start}",f).replace("{end}",g).replace("{page}",a.currentPage).replace("{pages}",a.totalPages).replace("{rows}",h);a.label.innerHTML=h?i:""}a.options.fixedHeight&&1==a.currentPage&&j.call(a)},h=function(){var a=this;if(b.flush(a.paginators,a.isIE),!(a.totalPages<=1)){var c="pager",d=b.createFragment(),e=a.onFirstPage?1:a.currentPage-1,f=a.onlastPage?a.totalPages:a.currentPage+1;a.options.firstLast&&b.append(d,b.button(c,1,a.options.firstText)),a.options.nextPrev&&b.append(d,b.button(c,e,a.options.prevText));var g=a.links;a.options.truncatePager&&(g=k(a.links,a.currentPage,a.pages.length,a.options.pagerDelta)),b.addClass(a.links[a.currentPage-1],"active"),b.each(g,function(a,c){b.removeClass(c,"active"),b.append(d,c)}),b.addClass(a.links[a.currentPage-1],"active"),a.options.nextPrev&&b.append(d,b.button(c,f,a.options.nextText)),a.options.firstLast&&b.append(d,b.button(c,a.totalPages,a.options.lastText)),b.each(a.paginators,function(a,c){b.append(c,d.cloneNode(!0))})}},i=function(a,b){var c,d;1===b?(c=0,d=a.length):b===-1&&(c=a.length-1,d=-1);for(var e=!0;e;){e=!1;for(var f=c;f!=d;f+=b)if(a[f+b]&&a[f].value>a[f+b].value){var g=a[f],h=a[f+b],i=g;a[f]=h,a[f+b]=i,e=!0}}return a},j=function(){this.container.style.height=null,this.rect=b.getBoundingRect(this.container),this.container.style.height=this.rect.height+"px"},k=function(a,c,d,e){e=e||2;var f,g=2*e,h=c-e,i=c+e,j=[],k=[];c<4-e+g?i=3+g:c>d-(3-e+g)&&(h=d-(2+g));for(var l=1;l<=d;l++)if(1==l||l==d||l>=h&&l<=i){var m=a[l-1];b.removeClass(m,"active"),j.push(m)}return b.each(j,function(c,d){var e=d.children[0].getAttribute("data-page");if(f){var g=f.children[0].getAttribute("data-page");if(e-g==2)k.push(a[g]);else if(e-g!=1){var h=b.createElement("li",{class:"ellipsis",html:''});k.push(h)}}k.push(d),f=d}),k},l=function(){var a=this.options.data,c=!1,d=!1;if(a.headings){c=b.createElement("thead");var e=b.createElement("tr");b.each(a.headings,function(a,c){var d=b.createElement("th",{html:c});e.appendChild(d)}),c.appendChild(e)}a.rows&&(d=b.createElement("tbody"),b.each(a.rows,function(c,e){if(a.headings&&a.headings.length!==e.length)throw new Error("The number of rows do not match the number of headings.");var f=b.createElement("tr");b.each(e,function(a,c){var d=b.createElement("td",{html:c});f.appendChild(d)}),d.appendChild(f)})),c&&(null!==this.table.tHead&&this.table.removeChild(this.table.tHead),b.append(this.table,c)),d&&(this.table.tBodies.length&&this.table.removeChild(this.table.tBodies[0]),b.append(this.table,d))},m=function(){};return m.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)},emit:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bb.pages.length||a<0)&&(g.call(b),h.call(b),void b.emit("datatable.page",a)))},n.prototype.sortColumn=function(a,c){if(a<1||a>this.tHead.rows[0].cells.length)return!1;a-=1;var e,d=this,f=d.searching?d.searchData:d.rows,g=[],h=[],j=0,k=0,l=d.tHead.rows[0].cells[a];b.each(f,function(b,c){var d=c.cells[a],e=d.textContent,f=e.replace(/(\$|\,|\s)/g,"");parseFloat(f)==f?h[k++]={value:Number(f),row:c}:g[j++]={value:e,row:c}});var m,n;b.hasClass(l,"asc")||"asc"==c?(m=i(g,-1),n=i(h,-1),e="descending",b.removeClass(l,"asc"),b.addClass(l,"desc")):(m=i(h,1),n=i(g,1),e="ascending",b.removeClass(l,"desc"),b.addClass(l,"asc")),this.lastTh&&l!=this.lastTh&&(b.removeClass(this.lastTh,"desc"),b.removeClass(this.lastTh,"asc")),this.lastTh=l,f=m.concat(n),d.searching?(d.searchData=[],b.each(f,function(a,b){d.searchData.push(b.row)})):(d.rows=[],b.each(f,function(a,b){d.rows.push(b.row)})),d.update(),d.emit("datatable.sort",a,e)},n.prototype.addRows=function(a){if("[object Object]"!==Object.prototype.toString.call(a))throw new Error("Function addRows: The method requires an object.");if(!a.rows)throw new Error("Function addRows: Your object is missing the 'rows' property.");var c=this;b.each(a.rows,function(a,d){var e=b.createElement("tr");b.each(d,function(a,c){var d=b.createElement("td",{html:c});e.appendChild(d)}),c.rows.push(e)}),this.update()},n.prototype.refresh=function(){this.options.searchable&&(this.input.value="",this.searching=!1),this.currentPage=1,this.onFirstPage=!0,this.update(),this.emit("datatable.refresh")},n.prototype.clear=function(a){this.tbody&&b.flush(this.tbody,this.isIE);var c=this.tbody;this.tbody||(c=this.table),a&&b.append(c,a)},n.prototype.setMessage=function(a){var c=this.rows[0].cells.length;this.clear(b.createElement("tr",{html:''+a+""}))},n}); \ No newline at end of file +!function(a,b){var c="DataTable";"function"==typeof define&&define.amd?define([],b(c)):"object"==typeof exports?module.exports=b(c):a[c]=b(c)}(this,function(a){"use strict";function n(a,c){var d=this,e={perPage:10,perPageSelect:[5,10,15,20,25],sortable:!0,searchable:!0,nextPrev:!0,firstLast:!1,prevText:"‹",nextText:"›",firstText:"«",lastText:"»",truncatePager:!0,pagerDelta:2,fixedColumns:!0,fixedHeight:!1,header:!0,footer:!1,labels:{placeholder:"Search...",perPage:"{select} entries per page",noRows:"No entries found",info:"Showing {start} to {end} of {rows} entries"},layout:{top:"{select}{search}",bottom:"{info}{pager}"}};if(d.initialized=!1,d.options=b.extend(e,c),!a)throw new Error("The plugin requires a table as the first parameter");if("string"==typeof a){var f=a;if(!(a=document.querySelector(a)))throw new Error("The element '"+f+"' can not be found.")}if("table"!==a.tagName.toLowerCase())throw new Error("The selected element is not a table.");if(d.options.header||(d.options.sortable=!1),null===a.tHead&&(!d.options.data||d.options.data&&!d.options.data.headings)&&(d.options.sortable=!1),!a.tBodies.length){if(!d.options.data)throw new Error("You don't seem to have a tbody in your table.");if(!d.options.data.rows)throw new Error("You seem to be using the data option, but you've not defined any rows.")}if(a.tBodies.length&&!a.tBodies[0].rows.length){if(!d.options.data)throw new Error("You don't seem to have any rows in your table.");if(!d.options.data.rows)throw new Error("You seem to be using the data option, but you've not defined any rows.")}d.table=a,this.init()}var b={extend:function(a,c){var d;for(d in c)c.hasOwnProperty(d)&&("[object Object]"===Object.prototype.toString.call(a[d])?b.extend(a[d],c[d]):a[d]=c[d]);return a},each:function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a))for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,d,a[d],a);else for(var e=0,f=a.length;e-1},button:function(a,c,d){return b.createElement("li",{class:a,html:''+d+""})},flush:function(a,c){if(a instanceof NodeList)b.each(a,function(a,d){b.flush(d,c)});else if(c)for(;a.hasChildNodes();)a.removeChild(a.firstChild);else a.innerHTML=""}},c=function(){var a=this,c=a.options,f="";if(m.mixin(a),c.data&&l.call(a),a.tbody=a.table.tBodies[0],a.tHead=a.table.tHead,a.tFoot=a.table.tFoot,!a.tHead){var g=b.createElement("thead"),h=b.createElement("tr");b.each(a.tbody.rows[0].cells,function(a,c){b.append(h,b.createElement("th"))}),b.append(g,h),a.tHead=g}if(c.header||a.tHead&&a.table.removeChild(a.table.tHead),c.footer?a.tHead&&!a.tFoot&&(a.tFoot=b.createElement("tfoot",{html:a.tHead.innerHTML}),a.table.appendChild(a.tFoot)):a.tFoot&&a.table.removeChild(a.table.tFoot),a.wrapper=b.createElement("div",{class:"dataTable-wrapper"}),f+="
",f+=c.layout.top,f+="
",f+="
",f+="
",f+=c.layout.bottom,f+="
",f=f.replace("{info}","
"),c.perPageSelect){var i="
";var k=b.createElement("select",{class:"dataTable-selector"});b.each(c.perPageSelect,function(a,b){var d=b===c.perPage,e=new Option(b,b,d,d);k.add(e)}),i=i.replace("{select}",k.outerHTML),f=f.replace("{select}",i)}else f=f.replace("{select}","");if(c.searchable){var n="";f=f.replace("{search}",n)}else f=f.replace("{search}","");var o=a.tHead.rows[0].cells;b.each(o,function(a,d){if(d.idx=a,c.sortable){var e=b.createElement("a",{href:"#",class:"dataTable-sorter",html:d.innerHTML});d.innerHTML="",b.append(d,e)}}),b.addClass(a.table,"dataTable-table");var p=b.createElement("div",{class:"dataTable-pagination"}),q=b.createElement("ul");if(b.append(p,q),f=f.replace(/\{pager\}/g,p.outerHTML),a.wrapper.innerHTML=f,a.container=a.wrapper.querySelector(".dataTable-container"),a.paginators=a.wrapper.querySelectorAll(".dataTable-pagination"),a.label=a.wrapper.querySelector(".dataTable-info"),a.table.parentNode.replaceChild(a.wrapper,a.table),a.container.appendChild(a.table),a.rect=b.getBoundingRect(a.table),a.rows=Array.prototype.slice.call(a.tbody.rows),a.update(),c.fixedHeight&&j.call(a),c.fixedColumns){var r,s=!1;if(a.table.tHead)r=a.table.tHead.rows[0].cells,b.each(r,function(c,d){var e=b.getBoundingRect(d),f=e.width/a.rect.width*100;d.style.width=f+"%"});else{r=[],s=b.createElement("thead");var t=b.createElement("tr"),u=a.table.tBodies[0].rows[0].cells;b.each(u,function(a,c){var d=b.createElement("th");t.appendChild(d),r.push(d)}),s.appendChild(t),a.table.insertBefore(s,a.table.tBodies[0]);var v=[];b.each(r,function(c,d){var e=b.getBoundingRect(d),f=e.width/a.rect.width*100;v.push(f)}),b.each(this.rows,function(a,c){b.each(c.cells,function(a,b){b.style.width=v[a]+"%"})}),a.table.removeChild(s)}}d.call(a),e.call(a)},d=function(){var a=this.options;a.header||b.addClass(this.wrapper,"no-header"),a.footer||b.addClass(this.wrapper,"no-footer"),a.sortable&&b.addClass(this.wrapper,"sortable"),a.searchable&&b.addClass(this.wrapper,"searchable"),a.fixedHeight&&b.addClass(this.wrapper,"fixed-height"),a.fixedColumns&&b.addClass(this.wrapper,"fixed-columns")},e=function(){var a=this,c=a.options;if(c.perPageSelect){var d=a.wrapper.querySelector(".dataTable-selector");d&&b.listen(d,"change",function(b){c.perPage=parseInt(this.value,10),a.update(),c.fixedHeight&&j.call(a),a.emit("datatable.perpage")})}c.searchable&&(a.input=a.wrapper.querySelector(".dataTable-input"),a.input&&b.listen(a.input,"keyup",function(b){a.search(this.value)})),b.listen(a.wrapper,"click",function(c){var d=c.target;"a"===d.nodeName.toLowerCase()&&d.hasAttribute("data-page")&&(b.preventDefault(c),a.page(d.getAttribute("data-page")))}),c.sortable&&b.listen(a.tHead,"click",function(c){c=c||window.event;var d=c.target;"a"===d.nodeName.toLowerCase()&&b.hasClass(d,"dataTable-sorter")&&(b.preventDefault(c),a.sortColumn(d.parentNode.idx+1))})},f=function(){var a=this,b=a.options.perPage,c=a.searching?a.searchData:a.rows;a.pages=c.map(function(a,d){return d%b==0?c.slice(d,d+b):null}).filter(function(a){return a}),a.totalPages=a.lastPage=a.pages.length},g=function(){var a=this;if(a.totalPages){a.currentPage>a.totalPages&&(a.currentPage=1);var c=a.currentPage-1,d=b.createFragment();switch(b.each(a.pages[c],function(a,c){b.append(d,c)}),a.clear(d),a.onFirstPage=!1,a.onLastPage=!1,a.currentPage){case 1:a.onFirstPage=!0;break;case a.lastPage:a.onLastPage=!0}}var h,e=0,f=0,g=0;if(a.totalPages&&(e=a.currentPage-1,f=e*a.options.perPage,g=f+a.pages[e].length,f+=1,h=a.searching?a.searchData.length:a.rows.length),a.label&&a.options.labels.info.length){var i=a.options.labels.info.replace("{start}",f).replace("{end}",g).replace("{page}",a.currentPage).replace("{pages}",a.totalPages).replace("{rows}",h);a.label.innerHTML=h?i:""}a.options.fixedHeight&&1==a.currentPage&&j.call(a)},h=function(){var a=this;if(b.flush(a.paginators,a.isIE),!(a.totalPages<=1)){var c="pager",d=b.createFragment(),e=a.onFirstPage?1:a.currentPage-1,f=a.onlastPage?a.totalPages:a.currentPage+1;a.options.firstLast&&b.append(d,b.button(c,1,a.options.firstText)),a.options.nextPrev&&b.append(d,b.button(c,e,a.options.prevText));var g=a.links;a.options.truncatePager&&(g=k(a.links,a.currentPage,a.pages.length,a.options.pagerDelta)),b.addClass(a.links[a.currentPage-1],"active"),b.each(g,function(a,c){b.removeClass(c,"active"),b.append(d,c)}),b.addClass(a.links[a.currentPage-1],"active"),a.options.nextPrev&&b.append(d,b.button(c,f,a.options.nextText)),a.options.firstLast&&b.append(d,b.button(c,a.totalPages,a.options.lastText)),b.each(a.paginators,function(a,c){b.append(c,d.cloneNode(!0))})}},i=function(a,b){var c,d;1===b?(c=0,d=a.length):-1===b&&(c=a.length-1,d=-1);for(var e=!0;e;){e=!1;for(var f=c;f!=d;f+=b)if(a[f+b]&&a[f].value>a[f+b].value){var g=a[f],h=a[f+b],i=g;a[f]=h,a[f+b]=i,e=!0}}return a},j=function(){this.container.style.height=null,this.rect=b.getBoundingRect(this.container),this.container.style.height=this.rect.height+"px"},k=function(a,c,d,e){e=e||2;var f,g=2*e,h=c-e,i=c+e,j=[],k=[];c<4-e+g?i=3+g:c>d-(3-e+g)&&(h=d-(2+g));for(var l=1;l<=d;l++)if(1==l||l==d||l>=h&&l<=i){var m=a[l-1];b.removeClass(m,"active"),j.push(m)}return b.each(j,function(c,d){var e=d.children[0].getAttribute("data-page");if(f){var g=f.children[0].getAttribute("data-page");if(e-g==2)k.push(a[g]);else if(e-g!=1){var h=b.createElement("li",{class:"ellipsis",html:''});k.push(h)}}k.push(d),f=d}),k},l=function(){var a=this.options.data,c=!1,d=!1;if(a.headings){c=b.createElement("thead");var e=b.createElement("tr");b.each(a.headings,function(a,c){var d=b.createElement("th",{html:c});e.appendChild(d)}),c.appendChild(e)}a.rows&&(d=b.createElement("tbody"),b.each(a.rows,function(c,e){if(a.headings&&a.headings.length!==e.length)throw new Error("The number of rows do not match the number of headings.");var f=b.createElement("tr");b.each(e,function(a,c){var d=b.createElement("td",{html:c});f.appendChild(d)}),d.appendChild(f)})),c&&(null!==this.table.tHead&&this.table.removeChild(this.table.tHead),b.append(this.table,c)),d&&(this.table.tBodies.length&&this.table.removeChild(this.table.tBodies[0]),b.append(this.table,d))},m=function(){};return m.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)},emit:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;bb.pages.length||a<0)&&(g.call(b),h.call(b),void b.emit("datatable.page",a)))},n.prototype.sortColumn=function(a,c){if(a<1||a>this.tHead.rows[0].cells.length)return!1;a-=1;var e,d=this,f=d.searching?d.searchData:d.rows,g=[],h=[],j=0,k=0,l=d.tHead.rows[0].cells[a];b.each(f,function(b,c){var d=c.cells[a],e=d.textContent,f=e.replace(/(\$|\,|\s)/g,"");parseFloat(f)==f?h[k++]={value:Number(f),row:c}:g[j++]={value:e,row:c}});var m,n;b.hasClass(l,"asc")||"asc"==c?(m=i(g,-1),n=i(h,-1),e="descending",b.removeClass(l,"asc"),b.addClass(l,"desc")):(m=i(h,1),n=i(g,1),e="ascending",b.removeClass(l,"desc"),b.addClass(l,"asc")),this.lastTh&&l!=this.lastTh&&(b.removeClass(this.lastTh,"desc"),b.removeClass(this.lastTh,"asc")),this.lastTh=l,f=m.concat(n),d.searching?(d.searchData=[],b.each(f,function(a,b){d.searchData.push(b.row)})):(d.rows=[],b.each(f,function(a,b){d.rows.push(b.row)})),d.update(),d.emit("datatable.sort",a,e)},n.prototype.addRows=function(a){if("[object Object]"!==Object.prototype.toString.call(a))throw new Error("Function addRows: The method requires an object.");if(!a.rows)throw new Error("Function addRows: Your object is missing the 'rows' property.");var c=this;b.each(a.rows,function(a,d){var e=b.createElement("tr");b.each(d,function(a,c){var d=b.createElement("td",{html:c});e.appendChild(d)}),c.rows.push(e)}),this.update()},n.prototype.refresh=function(){this.options.searchable&&(this.input.value="",this.searching=!1),this.currentPage=1,this.onFirstPage=!0,this.update(),this.emit("datatable.refresh")},n.prototype.clear=function(a){this.tbody&&b.flush(this.tbody,this.isIE);var c=this.tbody;this.tbody||(c=this.table),a&&("string"==typeof a?c.innerHTML=a:b.append(c,a))},n.prototype.setMessage=function(a){var c=this.rows[0].cells.length;this.clear(b.createElement("tr",{html:''+a+""}))},n}); \ No newline at end of file