diff --git a/README.md b/README.md index 3b20e11..e4f7bca 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A lightweight, dependency-free javascript HTML table plugin. Similar to jQuery D * moment.js integration for sorting columns with datetime strings (experimental, v1.2.3 and above) -[Documentation](https://github.com/Mobius1/Vanilla-DataTables/wiki) | [Latest Version](https://github.com/Mobius1/Vanilla-DataTables/releases/tag/1.4.17) +[Documentation](https://github.com/Mobius1/Vanilla-DataTables/wiki) | [Latest Version](https://github.com/Mobius1/Vanilla-DataTables/releases/tag/1.4.18) --- diff --git a/bower.json b/bower.json index 2a26deb..945daad 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "vanilla-datatables", - "version": "1.4.17", + "version": "1.4.18", "main": "src/vanilla-dataTables.js", "ignore": [ ".gitattributes", diff --git a/dist/vanilla-dataTables.min.css b/dist/vanilla-dataTables.min.css index ded8ddd..e692300 100644 --- a/dist/vanilla-dataTables.min.css +++ b/dist/vanilla-dataTables.min.css @@ -4,7 +4,7 @@ * Copyright (c) 2015-2017 Karl Saunders (http://mobius.ovh) * Licensed under MIT (http://www.opensource.org/licenses/mit-license.php) * - * Version: 1.4.17 + * Version: 1.4.18 * */ .dataTable-wrapper.no-header .dataTable-container{border-top:1px solid #d9d9d9}.dataTable-wrapper.no-footer .dataTable-container{border-bottom:1px solid #d9d9d9}.dataTable-top,.dataTable-bottom{padding:8px 10px}.dataTable-top > div:first-child,.dataTable-bottom > div:first-child{float:left}.dataTable-top > div:last-child,.dataTable-bottom > div:last-child{float:right}.dataTable-selector{padding:6px}.dataTable-input{padding:6px 12px}.dataTable-info{margin:7px 0}.dataTable-pagination ul{margin:0;padding-left:0}.dataTable-pagination li{list-style:none;float:left}.dataTable-pagination a{border:1px solid transparent;float:left;margin-left:2px;padding:6px 12px;position:relative;text-decoration:none;color:#333}.dataTable-pagination a:hover{background-color:#d9d9d9}.dataTable-pagination .active a,.dataTable-pagination .active a:focus,.dataTable-pagination .active a:hover{background-color:#d9d9d9;cursor:default}.dataTable-pagination .ellipsis a,.dataTable-pagination .disabled a,.dataTable-pagination .disabled a:focus,.dataTable-pagination .disabled a:hover{cursor:not-allowed}.dataTable-pagination .disabled a,.dataTable-pagination .disabled a:focus,.dataTable-pagination .disabled a:hover{cursor:not-allowed;opacity:.4}.dataTable-pagination .pager a{font-weight:700}.dataTable-table{max-width:100%;width:100%;border-spacing:0}.dataTable-table > tbody > tr > td,.dataTable-table > tbody > tr > th,.dataTable-table > tfoot > tr > td,.dataTable-table > tfoot > tr > th,.dataTable-table > thead > tr > td,.dataTable-table > thead > tr > th{vertical-align:top;padding:8px 10px}.dataTable-table > thead > tr > th{vertical-align:bottom;text-align:left;border-bottom:1px solid #d9d9d9}.dataTable-table > tfoot > tr > th{vertical-align:bottom;text-align:left;border-top:1px solid #d9d9d9}.dataTable-table th{vertical-align:bottom;text-align:left}.dataTable-table th a{text-decoration:none;color:inherit}.dataTable-sorter{display:inline-block;height:100%;position:relative;width:100%}.dataTable-sorter::before,.dataTable-sorter::after{content:"";height:0;width:0;position:absolute;right:4px;border-left:4px solid transparent;border-right:4px solid transparent;opacity:0}.dataTable-sorter::before{border-top:4px solid #000;bottom:8px}.dataTable-sorter::after{border-bottom:4px solid #000;border-top:4px solid transparent;top:8px}.asc .dataTable-sorter::after,.desc .dataTable-sorter::before{opacity:.6}.dataTables-empty{text-align:center}.dataTable-top::after,.dataTable-bottom::after{clear:both;content:" ";display:table} \ No newline at end of file diff --git a/dist/vanilla-dataTables.min.js b/dist/vanilla-dataTables.min.js index 3235b43..70ad32e 100644 --- a/dist/vanilla-dataTables.min.js +++ b/dist/vanilla-dataTables.min.js @@ -4,7 +4,7 @@ * Copyright (c) 2015-2017 Karl Saunders (http://mobius.ovh) * Licensed under MIT (http://www.opensource.org/licenses/mit-license.php) * - * Version: 1.4.17 + * Version: 1.4.18 * */ -!function(e,t){var a="DataTable";"function"==typeof define&&define.amd?define([],t(a)):"object"==typeof exports?module.exports=t(a):e[a]=t(a)}(this,function(e){"use strict";var t=window,a=document,i=a.body,n={perPage:10,perPageSelect:[5,10,15,20,25],sortable:!0,searchable:!0,nextPrev:!0,firstLast:!1,prevText:"‹",nextText:"›",firstText:"«",lastText:"»",ellipsisText:"…",ascText:"▴",descText:"▾",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}"}},s=function(e){return"[object Object]"===Object.prototype.toString.call(e)},r=function(e){return Array.isArray(e)},o=function(e){var t=!1;try{t=JSON.parse(e)}catch(e){return!1}return!(null===t||!r(t)&&!s(t))&&t},l=function(e,t){for(var a in t)if(t.hasOwnProperty(a)){var i=t[a];i&&s(i)?(e[a]=e[a]||{},l(e[a],i)):e[a]=i}return e},d=function(e,t,a){var i;if(s(e))for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.call(a,e[i],i);else for(i=0;i'+a+""})},f={add:function(e,t){e.classList?e.classList.add(t):f.contains(e,t)||(e.className=e.className.trim()+" "+t)},remove:function(e,t){e.classList?e.classList.remove(t):f.contains(e,t)&&(e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},contains:function(e,t){if(e)return e.classList?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},g=function(e,t){var a,i;1===t?(a=0,i=e.length):-1===t&&(a=e.length-1,i=-1);for(var n=!0;n;){n=!1;for(var s=a;s!=i;s+=t)if(e[s+t]&&e[s].value>e[s+t].value){var r=e[s],o=e[s+t],l=r;e[s]=o,e[s+t]=l,n=!0}}return e},b=function(e,t,a,i,n){var s,r=2*(i=i||2),o=t-i,l=t+i,h=[],p=[];t<4-i+r?l=3+r:t>a-(3-i+r)&&(o=a-(2+r));for(var u=1;u<=a;u++)if(1==u||u==a||u>=o&&u<=l){var g=e[u-1];f.remove(g,"active"),h.push(g)}return d(h,function(t){var a=t.children[0].getAttribute("data-page");if(s){var i=s.children[0].getAttribute("data-page");if(a-i==2)p.push(e[i]);else if(a-i!=1){var r=c("li",{class:"ellipsis",html:''+n+""});p.push(r)}}p.push(t),s=t}),p},m=function(e){var t=!1,a=!1;if((e=e||this.options.data).headings){t=c("thead");var i=c("tr");d(e.headings,function(e){var t=c("th",{html:e});i.appendChild(t)}),t.appendChild(i)}e.data&&(a=c("tbody"),d(e.data,function(t){if(e.headings&&e.headings.length!==t.length)throw new Error("The number of rows do not match the number of headings.");var i=c("tr");d(t,function(e){var t=c("td",{html:e});i.appendChild(t)}),a.appendChild(i)})),t&&(null!==this.table.tHead&&this.table.removeChild(this.table.tHead),this.table.appendChild(t)),a&&(this.table.tBodies.length&&this.table.removeChild(this.table.tBodies[0]),this.table.appendChild(a))},v=function(e,t){var a=!1;if(t)switch(t){case"ISO_8601":a=moment(e,moment.ISO_8601).format("YYYYMMDD");break;case"RFC_2822":a=moment(e,"ddd, MM MMM YYYY HH:mm:ss ZZ").format("YYYYMMDD");break;case"MYSQL":a=moment(e,"YYYY-MM-DD hh:mm:ss").format("YYYYMMDD");break;case"UNIX":a=moment(e).unix();break;default:a=moment(e,t).format("YYYYMMDD")}return a},x=function(e){return this.dt=e,this};x.prototype.swap=function(e){if(e.length&&2===e.length){var t=[];d(this.dt.headings,function(e,a){t.push(a)});var a=e[0],i=e[1],n=t[i];t[i]=t[a],t[a]=n,this.order(t)}},x.prototype.order=function(e){var t,a,i,n,s,r,o=[],l=[],h=[],c=[],p=this.dt;d(e,function(e,i){s=p.headings[e],r="false"!==s.getAttribute("data-sortable"),(t=s.cloneNode(!0)).originalCellIndex=i,t.sortable=r,o.push(t),p.hiddenColumns.indexOf(e)<0&&((a=s.cloneNode(!0)).originalCellIndex=i,a.sortable=r,l.push(a))}),d(p.data,function(t,a){i=t.cloneNode(),n=t.cloneNode(),i.dataIndex=a,n.dataIndex=a,null!==t.searchIndex&&void 0!==t.searchIndex&&(i.searchIndex=t.searchIndex,n.searchIndex=t.searchIndex),d(e,function(e,a){i.appendChild(t.cells[a].cloneNode(!0)),p.hiddenColumns.indexOf(a)<0&&n.appendChild(t.cells[a].cloneNode(!0))},this),h.push(i),c.push(n)}),p.headings=o,p.activeHeadings=l,p.data=h,p.activeRows=c,p.update()},x.prototype.hide=function(e){if(e.length){var t=this.dt;d(e,function(e){t.hiddenColumns.indexOf(e)<0&&t.hiddenColumns.push(e)}),this.rebuild()}},x.prototype.show=function(e){if(e.length){var t,a=this.dt;d(e,function(e){(t=a.hiddenColumns.indexOf(e))>-1&&a.hiddenColumns.splice(t,1)}),this.rebuild()}},x.prototype.visible=function(e){var t,a=this.dt;return e=e||a.headings.map(function(e){return e.originalCellIndex}),isNaN(e)?r(e)&&(t=[],d(e,function(e){t.push(a.hiddenColumns.indexOf(e)<0)})):t=a.hiddenColumns.indexOf(e)<0,t},x.prototype.hidden=function(e){var t,a=this.dt;return e=e||this.dt.headings.map(function(e){return e.originalCellIndex}),isNaN(e)?r(e)&&(t=[],d(e,function(e){t.push(a.hiddenColumns.indexOf(e)>-1)})):t=a.hiddenColumns.indexOf(this.columns)>-1,t},x.prototype.add=function(e){var t,a=this,i=document.createElement("th");if(!this.dt.headings.length)return this.dt.insert({headings:[e.heading],data:e.data.map(function(e){return[e]})}),void this.rebuild();this.dt.hiddenHeader?i.innerHTML="":e.heading.nodeName?i.appendChild(e.heading):i.innerHTML=e.heading,this.dt.headings.push(i),d(this.dt.data,function(i,n){e.data[n]&&(t=document.createElement("td"),e.data[n].nodeName?t.appendChild(e.data[n]):t.innerHTML=e.data[n],t.data=t.innerHTML,e.render&&(t.innerHTML=e.render.call(a,t.data,t,i)),i.appendChild(t))}),e.type&&i.setAttribute("data-type",e.type),e.format&&i.setAttribute("data-format",e.format),e.hasOwnProperty("sortable")&&(i.sortable=e.sortable,i.setAttribute("data-sortable",!0===e.sortable?"true":"false")),this.rebuild(),this.dt.renderHeader()},x.prototype.remove=function(e){r(e)?(e.sort(function(e,t){return t-e}),d(e,function(e){this.remove(e)},this)):(this.dt.headings.splice(e,1),d(this.dt.data,function(t){t.removeChild(t.cells[e])})),this.rebuild()},x.prototype.sort=function(e,a,i){var n=this.dt;if(n.hasHeadings&&(e<1||e>n.activeHeadings.length))return!1;n.sorting=!0,e-=1;var s,r=n.data,o=[],l=[],h=0,c=0,p=n.activeHeadings[e];e=p.originalCellIndex,d(r,function(a){var i=a.cells[e].data,n=i.replace(/(\$|\,|\s|%)/g,"");if("date"===p.getAttribute("data-type")&&t.moment){var s=!1;p.hasAttribute("data-format")&&(s=p.getAttribute("data-format")),n=v(i,s)}parseFloat(n)==n?l[c++]={value:Number(n),row:a}:o[h++]={value:i,row:a}});var u,b;f.contains(p,"asc")||"asc"==a?(u=g(o,-1),b=g(l,-1),s="descending",f.remove(p,"asc"),f.add(p,"desc")):(u=g(l,1),b=g(o,1),s="ascending",f.remove(p,"desc"),f.add(p,"asc")),n.lastTh&&p!=n.lastTh&&(f.remove(n.lastTh,"desc"),f.remove(n.lastTh,"asc")),n.lastTh=p,r=u.concat(b),n.data=[];var m=[];d(r,function(e,t){n.data.push(e.row),null!==e.row.searchIndex&&void 0!==e.row.searchIndex&&m.push(t)},n),n.searchData=m,this.rebuild(),n.update(),i||n.emit("datatable.sort",e,s)},x.prototype.rebuild=function(){var e,t,a,i,n=this.dt,s=[];n.activeRows=[],n.activeHeadings=[],d(n.headings,function(e,t){e.originalCellIndex=t,e.sortable="false"!==e.getAttribute("data-sortable"),n.hiddenColumns.indexOf(t)<0&&n.activeHeadings.push(e)},this),d(n.data,function(r,o){e=r.cloneNode(),t=r.cloneNode(),e.dataIndex=o,t.dataIndex=o,null!==r.searchIndex&&void 0!==r.searchIndex&&(e.searchIndex=r.searchIndex,t.searchIndex=r.searchIndex),d(r.cells,function(s){(a=s.cloneNode(!0)).data=s.data,e.appendChild(a),n.hiddenColumns.indexOf(s.cellIndex)<0&&((i=s.cloneNode(!0)).data=s.data,t.appendChild(i))}),s.push(e),n.activeRows.push(t)}),n.data=s,n.update()};var C=function(e,t){return this.dt=e,this.rows=t,this};C.prototype.build=function(e){var t,a=c("tr"),i=this.dt.headings;return i.length||(i=e.map(function(){return""})),d(i,function(i,n){t=c("td"),e[n]||e[n].length||(e[n]=""),t.innerHTML=e[n],t.data=e[n],a.appendChild(t)}),a},C.prototype.render=function(e){return e},C.prototype.add=function(e){if(r(e)){var t=this.dt;r(e[0])?d(e,function(e,a){t.data.push(this.build(e))},this):t.data.push(this.build(e)),this.update(),t.columns().rebuild()}},C.prototype.remove=function(e){var t=this.dt;r(e)?(e.sort(function(e,t){return t-e}),d(e,function(e,a){t.data.splice(e,1)})):t.data.splice(e,1),this.update(),t.columns().rebuild()},C.prototype.update=function(){d(this.dt.data,function(e,t){e.dataIndex=t})};var w=function(e,t){if(this.initialized=!1,this.options=l(n,t),"string"==typeof e){var a=e;if(!(e=document.querySelector(e)))throw new Error("The element '"+a+"' can not be found.")}if("table"!==e.tagName.toLowerCase())throw new Error("The selected element is not a table.");if(this.initialLayout=e.innerHTML,this.initialSortable=this.options.sortable,this.options.header||(this.options.sortable=!1),null===e.tHead&&(!this.options.data||this.options.data&&!this.options.data.headings)&&(this.options.sortable=!1),e.tBodies.length&&!e.tBodies[0].rows.length&&this.options.data&&!this.options.data.data)throw new Error("You seem to be using the data option, but you've not defined any rows.");this.table=e,this.init()},y=w.prototype;return w.extend=function(e,t){"function"==typeof t?w.prototype[e]=t:w[e]=t},y.init=function(e){if(this.initialized||f.contains(this.table,"dataTable-table"))return!1;var t=this;this.options=l(this.options,e||{}),this.isIE=!!/(msie|trident)/i.test(navigator.userAgent),this.currentPage=1,this.onFirstPage=!0,this.hiddenColumns=[],this.columnRenderers=[],this.selectedColumns=[],this.render(),this.options.plugins&&d(this.options.plugins,function(e,t){this[t](e)},this),setTimeout(function(){t.emit("datatable.init"),t.initialized=!0},10)},y.render=function(e){if(e){switch(e){case"page":this.renderPage();break;case"pager":this.renderPager();break;case"header":this.renderHeader()}return!1}var t=this,a=t.options,i="";if(a.data&&m.call(t),a.ajax){var n=a.ajax,s=new XMLHttpRequest;h(s,"progress",function(e){t.emit("datatable.ajax.progress",e,s)}),h(s,"load",function(e){if(4===s.readyState)if(t.emit("datatable.ajax.loaded",e,s),200===s.status){var a={};a.data=n.load?n.load.call(t,s):s.responseText,a.type="json",n.content&&n.content.type&&(a.type=n.content.type,a=l(a,n.content)),t.import(a),t.setColumns(!0),t.emit("datatable.ajax.success",e,s)}else t.emit("datatable.ajax.error",e,s)}),h(s,"error",function(e){t.emit("datatable.ajax.error",e,s)}),h(s,"abort",function(e){t.emit("datatable.ajax.abort",e,s)}),t.emit("datatable.ajax.loading",s),s.open("GET","string"==typeof n?a.ajax:a.ajax.url),s.send()}if(t.body=t.table.tBodies[0],t.head=t.table.tHead,t.foot=t.table.tFoot,t.body||(t.body=c("tbody"),t.table.appendChild(t.body)),t.hasRows=t.body.rows.length>0,!t.head){var r=c("thead"),o=c("tr");t.hasRows&&(d(t.body.rows[0].cells,function(){o.appendChild(c("th"))}),r.appendChild(o)),t.head=r,t.table.insertBefore(t.head,t.body),t.hiddenHeader=!a.ajax}if(t.headings=[],t.hasHeadings=t.head.rows.length>0,t.hasHeadings&&(t.header=t.head.rows[0],t.headings=[].slice.call(t.header.cells)),a.header||t.head&&t.table.removeChild(t.table.tHead),a.footer?t.head&&!t.foot&&(t.foot=c("tfoot",{html:t.head.innerHTML}),t.table.appendChild(t.foot)):t.foot&&t.table.removeChild(t.table.tFoot),t.wrapper=c("div",{class:"dataTable-wrapper dataTable-loading"}),i+="
",i+=a.layout.top,i+="
",i+="
",i+="
",i+=a.layout.bottom,i+="
",i=i.replace("{info}","
"),a.perPageSelect){var p="
";var u=c("select",{class:"dataTable-selector"});d(a.perPageSelect,function(e){var t=e===a.perPage,i=new Option(e,e,t,t);u.add(i)}),p=p.replace("{select}",u.outerHTML),i=i.replace("{select}",p)}else i=i.replace("{select}","");if(a.searchable){var g="";i=i.replace("{search}",g)}else i=i.replace("{search}","");t.hasHeadings&&this.render("header"),f.add(t.table,"dataTable-table");var b=c("div",{class:"dataTable-pagination"}),v=c("ul");b.appendChild(v),i=i.replace(/\{pager\}/g,b.outerHTML),t.wrapper.innerHTML=i,t.container=t.wrapper.querySelector(".dataTable-container"),t.pagers=t.wrapper.querySelectorAll(".dataTable-pagination"),t.label=t.wrapper.querySelector(".dataTable-info"),t.table.parentNode.replaceChild(t.wrapper,t.table),t.container.appendChild(t.table),t.rect=t.table.getBoundingClientRect(),t.data=[].slice.call(t.body.rows),t.activeRows=t.data.slice(),t.activeHeadings=t.headings.slice(),t.update(),a.ajax||t.setColumns(),this.fixHeight(),t.fixColumns(),a.header||f.add(t.wrapper,"no-header"),a.footer||f.add(t.wrapper,"no-footer"),a.sortable&&f.add(t.wrapper,"sortable"),a.searchable&&f.add(t.wrapper,"searchable"),a.fixedHeight&&f.add(t.wrapper,"fixed-height"),a.fixedColumns&&f.add(t.wrapper,"fixed-columns"),t.bindEvents()},y.renderPage=function(){if(this.hasRows&&this.totalPages){this.currentPage>this.totalPages&&(this.currentPage=1);var e=this.currentPage-1,t=a.createDocumentFragment();this.hasHeadings&&(p(this.header,this.isIE),d(this.activeHeadings,function(e){this.header.appendChild(e)},this)),d(this.pages[e],function(e){t.appendChild(this.rows().render(e))},this),this.clear(t),this.onFirstPage=1===this.currentPage,this.onLastPage=this.currentPage===this.lastPage}else this.clear();var i,n=0,s=0,r=0;if(this.totalPages&&(r=(s=(n=this.currentPage-1)*this.options.perPage)+this.pages[n].length,s+=1,i=this.searching?this.searchData.length:this.data.length),this.label&&this.options.labels.info.length){var o=this.options.labels.info.replace("{start}",s).replace("{end}",r).replace("{page}",this.currentPage).replace("{pages}",this.totalPages).replace("{rows}",i);this.label.innerHTML=i?o:""}1==this.currentPage&&this.fixHeight()},y.renderPager=function(){if(p(this.pagers,this.isIE),this.totalPages>1){var e="pager",t=a.createDocumentFragment(),i=this.onFirstPage?1:this.currentPage-1,n=this.onlastPage?this.totalPages:this.currentPage+1;this.options.firstLast&&t.appendChild(u(e,1,this.options.firstText)),this.options.nextPrev&&t.appendChild(u(e,i,this.options.prevText));var s=this.links;this.options.truncatePager&&(s=b(this.links,this.currentPage,this.pages.length,this.options.pagerDelta,this.options.ellipsisText)),f.add(this.links[this.currentPage-1],"active"),d(s,function(e){f.remove(e,"active"),t.appendChild(e)}),f.add(this.links[this.currentPage-1],"active"),this.options.nextPrev&&t.appendChild(u(e,n,this.options.nextText)),this.options.firstLast&&t.appendChild(u(e,this.totalPages,this.options.lastText)),d(this.pagers,function(e){e.appendChild(t.cloneNode(!0))})}},y.renderHeader=function(){var e=this;e.labels=[],e.headings&&e.headings.length&&d(e.headings,function(t,a){if(e.labels[a]=t.textContent,f.contains(t.firstElementChild,"dataTable-sorter")&&(t.innerHTML=t.firstElementChild.innerHTML),t.sortable="false"!==t.getAttribute("data-sortable"),t.originalCellIndex=a,e.options.sortable&&t.sortable){var i=c("a",{href:"#",class:"dataTable-sorter",html:t.innerHTML});t.innerHTML="",t.setAttribute("data-sortable",""),t.appendChild(i)}}),e.fixColumns()},y.bindEvents=function(){var e=this,t=e.options;if(t.perPageSelect){var a=e.wrapper.querySelector(".dataTable-selector");a&&h(a,"change",function(a){t.perPage=parseInt(this.value,10),e.update(),this.fixHeight(),e.emit("datatable.perpage",t.perPage)})}t.searchable&&(e.input=e.wrapper.querySelector(".dataTable-input"),e.input&&h(e.input,"keyup",function(t){e.search(this.value)})),h(e.wrapper,"click",function(a){var i=a.target;"a"===i.nodeName.toLowerCase()&&(i.hasAttribute("data-page")?(e.page(i.getAttribute("data-page")),a.preventDefault()):t.sortable&&f.contains(i,"dataTable-sorter")&&"false"!=i.parentNode.getAttribute("data-sortable")&&(e.columns().sort(e.activeHeadings.indexOf(i.parentNode)+1),a.preventDefault()))})},y.setColumns=function(e){var t=this;e||d(t.data,function(e){d(e.cells,function(e){e.data=e.innerHTML})}),t.options.columns&&t.headings.length&&d(t.options.columns,function(e){r(e.select)||(e.select=[e.select]),e.hasOwnProperty("render")&&"function"==typeof e.render&&(t.selectedColumns=t.selectedColumns.concat(e.select),t.columnRenderers.push({columns:e.select,renderer:e.render})),d(e.select,function(a){var i=t.headings[a];e.type&&i.setAttribute("data-type",e.type),e.format&&i.setAttribute("data-format",e.format),e.hasOwnProperty("sortable")&&i.setAttribute("data-sortable",e.sortable),e.hasOwnProperty("hidden")&&!1!==e.hidden&&t.columns(a).hide(),e.hasOwnProperty("sort")&&1===e.select.length&&t.columns().sort(e.select[0]+1,e.sort,!0)})}),t.hasRows&&(d(t.data,function(e,t){e.dataIndex=t,d(e.cells,function(e){e.data=e.innerHTML})}),t.selectedColumns.length&&d(t.data,function(e){d(e.cells,function(a,i){t.selectedColumns.indexOf(i)>-1&&d(t.columnRenderers,function(n){n.columns.indexOf(i)>-1&&(a.innerHTML=n.renderer.call(t,a.data,a,e))})})}),t.columns().rebuild()),t.render("header")},y.destroy=function(){this.table.innerHTML=this.initialLayout,f.remove(this.table,"dataTable-table"),this.wrapper.parentNode.replaceChild(this.table,this.wrapper),this.initialized=!1},y.update=function(){this.paginate(this),this.render("page"),this.links=[];for(var e=this.pages.length;e--;){var t=e+1;this.links[e]=u(0===e?"active":"",t,t)}this.sorting=!1,this.render("pager"),this.rows().update(),this.emit("datatable.update")},y.paginate=function(){var e=this.options.perPage,t=this.activeRows;return this.searching&&(t=[],d(this.searchData,function(e){t.push(this.activeRows[e])},this)),this.pages=t.map(function(a,i){return i%e==0?t.slice(i,i+e):null}).filter(function(e){return e}),this.totalPages=this.lastPage=this.pages.length,this.totalPages},y.fixColumns=function(){if(this.options.fixedColumns&&this.activeHeadings&&this.activeHeadings.length){var e,t=!1;if(this.columnWidths=[],this.table.tHead)d(this.activeHeadings,function(e){e.style.width=""},this),d(this.activeHeadings,function(e,t){var a=e.offsetWidth,i=a/this.rect.width*100;e.style.width=i+"%",this.columnWidths[t]=a},this);else{e=[],t=c("thead");var a=c("tr"),i=this.table.tBodies[0].rows[0].cells;d(i,function(){var t=c("th");a.appendChild(t),e.push(t)}),t.appendChild(a),this.table.insertBefore(t,this.body);var n=[];d(e,function(e,t){var a=e.offsetWidth,i=a/this.rect.width*100;n.push(i),this.columnWidths[t]=a},this),d(this.data,function(e){d(e.cells,function(e,t){this.columns(e.cellIndex).visible()&&(e.style.width=n[t]+"%")},this)},this),this.table.removeChild(t)}}},y.fixHeight=function(){this.options.fixedHeight&&(this.container.style.height=null,this.rect=this.container.getBoundingClientRect(),this.container.style.height=this.rect.height+"px")},y.search=function(e){if(!this.hasRows)return!1;var t=this;if(e=e.toLowerCase(),this.currentPage=1,this.searching=!0,this.searchData=[],!e.length)return this.searching=!1,this.update(),this.emit("datatable.search",e,this.searchData),f.remove(this.wrapper,"search-results"),!1;this.clear(),d(this.data,function(a,i){var n=this.searchData.indexOf(a)>-1;e.split(" ").reduce(function(e,i){for(var n=!1,s=0;s-1&&t.columns(a.cells[s].cellIndex).visible()){n=!0;break}return e&&n},!0)&&!n?(a.searchIndex=i,this.searchData.push(i)):a.searchIndex=null},this),f.add(this.wrapper,"search-results"),t.searchData.length?t.update():(f.remove(t.wrapper,"search-results"),t.setMessage(t.options.labels.noRows)),this.emit("datatable.search",e,this.searchData)},y.page=function(e){return e!=this.currentPage&&(isNaN(e)||(this.currentPage=parseInt(e,10)),!(e>this.pages.length||e<0)&&(this.render("page"),this.render("pager"),void this.emit("datatable.page",e)))},y.sortColumn=function(e,t){this.columns().sort(e,t)},y.insert=function(e){var t=this,a=[];if(s(e)){if(e.headings&&!t.hasHeadings&&!t.hasRows){var i,n=c("tr");d(e.headings,function(e){i=c("th",{html:e}),n.appendChild(i)}),t.head.appendChild(n),t.header=n,t.headings=[].slice.call(n.cells),t.hasHeadings=!0,t.options.sortable=t.initialSortable,t.render("header")}e.data&&r(e.data)&&(a=e.data)}else r(e)&&d(e,function(e){var i=[];d(e,function(e,a){var n=t.labels.indexOf(a);n>-1&&(i[n]=e)}),a.push(i)});a.length&&(t.rows().add(a),t.hasRows=!0),t.update(),t.fixColumns()},y.refresh=function(){this.options.searchable&&(this.input.value="",this.searching=!1),this.currentPage=1,this.onFirstPage=!0,this.update(),this.emit("datatable.refresh")},y.clear=function(e){this.body&&p(this.body,this.isIE);var t=this.body;this.body||(t=this.table),e&&("string"==typeof e&&(a.createDocumentFragment().innerHTML=e),t.appendChild(e))},y.export=function(e){if(!this.hasHeadings&&!this.hasRows)return!1;var t,a,n,o,d=this.activeHeadings,h=[],c=[],p={download:!0,skipColumn:[],lineDelimiter:"\n",columnDelimiter:",",tableName:"myTable",replacer:null,space:4};if(!s(e))return!1;var u=l(p,e);if(u.type){if("txt"!==u.type&&"csv"!==u.type||(h[0]=this.header),u.selection)if(isNaN(u.selection)){if(r(u.selection))for(t=0;t'+e+""}))},y.columns=function(e){return new x(this,e)},y.rows=function(e){return new C(this,e)},y.on=function(e,t){this.events=this.events||{},this.events[e]=this.events[e]||[],this.events[e].push(t)},y.off=function(e,t){this.events=this.events||{},e in this.events!=!1&&this.events[e].splice(this.events[e].indexOf(t),1)},y.emit=function(e){if(this.events=this.events||{},e in this.events!=!1)for(var t=0;t'+a+""})},f={add:function(e,t){e.classList?e.classList.add(t):f.contains(e,t)||(e.className=e.className.trim()+" "+t)},remove:function(e,t){e.classList?e.classList.remove(t):f.contains(e,t)&&(e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},contains:function(e,t){if(e)return e.classList?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},g=function(e,t){var a,i;1===t?(a=0,i=e.length):-1===t&&(a=e.length-1,i=-1);for(var n=!0;n;){n=!1;for(var s=a;s!=i;s+=t)if(e[s+t]&&e[s].value>e[s+t].value){var r=e[s],o=e[s+t],l=r;e[s]=o,e[s+t]=l,n=!0}}return e},b=function(e,t,a,i,n){var s,r=2*(i=i||2),o=t-i,l=t+i,h=[],p=[];t<4-i+r?l=3+r:t>a-(3-i+r)&&(o=a-(2+r));for(var u=1;u<=a;u++)if(1==u||u==a||u>=o&&u<=l){var g=e[u-1];f.remove(g,"active"),h.push(g)}return d(h,function(t){var a=t.children[0].getAttribute("data-page");if(s){var i=s.children[0].getAttribute("data-page");if(a-i==2)p.push(e[i]);else if(a-i!=1){var r=c("li",{class:"ellipsis",html:''+n+""});p.push(r)}}p.push(t),s=t}),p},m=function(e){var t=!1,a=!1;if((e=e||this.options.data).headings){t=c("thead");var i=c("tr");d(e.headings,function(e){var t=c("th",{html:e});i.appendChild(t)}),t.appendChild(i)}e.data&&(a=c("tbody"),d(e.data,function(t){if(e.headings&&e.headings.length!==t.length)throw new Error("The number of rows do not match the number of headings.");var i=c("tr");d(t,function(e){var t=c("td",{html:e});i.appendChild(t)}),a.appendChild(i)})),t&&(null!==this.table.tHead&&this.table.removeChild(this.table.tHead),this.table.appendChild(t)),a&&(this.table.tBodies.length&&this.table.removeChild(this.table.tBodies[0]),this.table.appendChild(a))},v=function(e,t){var a=!1;if(t)switch(t){case"ISO_8601":a=moment(e,moment.ISO_8601).format("YYYYMMDD");break;case"RFC_2822":a=moment(e,"ddd, MM MMM YYYY HH:mm:ss ZZ").format("YYYYMMDD");break;case"MYSQL":a=moment(e,"YYYY-MM-DD hh:mm:ss").format("YYYYMMDD");break;case"UNIX":a=moment(e).unix();break;default:a=moment(e,t).format("YYYYMMDD")}return a},x=function(e){return this.dt=e,this};x.prototype.swap=function(e){if(e.length&&2===e.length){var t=[];d(this.dt.headings,function(e,a){t.push(a)});var a=e[0],i=e[1],n=t[i];t[i]=t[a],t[a]=n,this.order(t)}},x.prototype.order=function(e){var t,a,i,n,s,r,o=[],l=[],h=[],c=[],p=this.dt;d(e,function(e,i){s=p.headings[e],r="false"!==s.getAttribute("data-sortable"),(t=s.cloneNode(!0)).originalCellIndex=i,t.sortable=r,o.push(t),p.hiddenColumns.indexOf(e)<0&&((a=s.cloneNode(!0)).originalCellIndex=i,a.sortable=r,l.push(a))}),d(p.data,function(t,a){i=t.cloneNode(),n=t.cloneNode(),i.dataIndex=a,n.dataIndex=a,null!==t.searchIndex&&void 0!==t.searchIndex&&(i.searchIndex=t.searchIndex,n.searchIndex=t.searchIndex),d(e,function(e,a){i.appendChild(t.cells[a].cloneNode(!0)),p.hiddenColumns.indexOf(a)<0&&n.appendChild(t.cells[a].cloneNode(!0))},this),h.push(i),c.push(n)}),p.headings=o,p.activeHeadings=l,p.data=h,p.activeRows=c,p.update()},x.prototype.hide=function(e){if(e.length){var t=this.dt;d(e,function(e){t.hiddenColumns.indexOf(e)<0&&t.hiddenColumns.push(e)}),this.rebuild()}},x.prototype.show=function(e){if(e.length){var t,a=this.dt;d(e,function(e){(t=a.hiddenColumns.indexOf(e))>-1&&a.hiddenColumns.splice(t,1)}),this.rebuild()}},x.prototype.visible=function(e){var t,a=this.dt;return e=e||a.headings.map(function(e){return e.originalCellIndex}),isNaN(e)?r(e)&&(t=[],d(e,function(e){t.push(a.hiddenColumns.indexOf(e)<0)})):t=a.hiddenColumns.indexOf(e)<0,t},x.prototype.hidden=function(e){var t,a=this.dt;return e=e||this.dt.headings.map(function(e){return e.originalCellIndex}),isNaN(e)?r(e)&&(t=[],d(e,function(e){t.push(a.hiddenColumns.indexOf(e)>-1)})):t=a.hiddenColumns.indexOf(this.columns)>-1,t},x.prototype.add=function(e){var t,a=this,i=document.createElement("th");if(!this.dt.headings.length)return this.dt.insert({headings:[e.heading],data:e.data.map(function(e){return[e]})}),void this.rebuild();this.dt.hiddenHeader?i.innerHTML="":e.heading.nodeName?i.appendChild(e.heading):i.innerHTML=e.heading,this.dt.headings.push(i),d(this.dt.data,function(i,n){e.data[n]&&(t=document.createElement("td"),e.data[n].nodeName?t.appendChild(e.data[n]):t.innerHTML=e.data[n],t.data=t.innerHTML,e.render&&(t.innerHTML=e.render.call(a,t.data,t,i)),i.appendChild(t))}),e.type&&i.setAttribute("data-type",e.type),e.format&&i.setAttribute("data-format",e.format),e.hasOwnProperty("sortable")&&(i.sortable=e.sortable,i.setAttribute("data-sortable",!0===e.sortable?"true":"false")),this.rebuild(),this.dt.renderHeader()},x.prototype.remove=function(e){r(e)?(e.sort(function(e,t){return t-e}),d(e,function(e){this.remove(e)},this)):(this.dt.headings.splice(e,1),d(this.dt.data,function(t){t.removeChild(t.cells[e])})),this.rebuild()},x.prototype.sort=function(e,a,i){var n=this.dt;if(n.hasHeadings&&(e<1||e>n.activeHeadings.length))return!1;n.sorting=!0,e-=1;var s,r=n.data,o=[],l=[],h=0,c=0,p=n.activeHeadings[e];e=p.originalCellIndex,d(r,function(a){var i=a.cells[e].data,n=i.replace(/(\$|\,|\s|%)/g,"");if("date"===p.getAttribute("data-type")&&t.moment){var s=!1;p.hasAttribute("data-format")&&(s=p.getAttribute("data-format")),n=v(i,s)}parseFloat(n)==n?l[c++]={value:Number(n),row:a}:o[h++]={value:i,row:a}});var u,b;f.contains(p,"asc")||"asc"==a?(u=g(o,-1),b=g(l,-1),s="descending",f.remove(p,"asc"),f.add(p,"desc")):(u=g(l,1),b=g(o,1),s="ascending",f.remove(p,"desc"),f.add(p,"asc")),n.lastTh&&p!=n.lastTh&&(f.remove(n.lastTh,"desc"),f.remove(n.lastTh,"asc")),n.lastTh=p,r=u.concat(b),n.data=[];var m=[];d(r,function(e,t){n.data.push(e.row),null!==e.row.searchIndex&&void 0!==e.row.searchIndex&&m.push(t)},n),n.searchData=m,this.rebuild(),n.update(),i||n.emit("datatable.sort",e,s)},x.prototype.rebuild=function(){var e,t,a,i,n=this.dt,s=[];n.activeRows=[],n.activeHeadings=[],d(n.headings,function(e,t){e.originalCellIndex=t,e.sortable="false"!==e.getAttribute("data-sortable"),n.hiddenColumns.indexOf(t)<0&&n.activeHeadings.push(e)},this),d(n.data,function(r,o){e=r.cloneNode(),t=r.cloneNode(),e.dataIndex=o,t.dataIndex=o,null!==r.searchIndex&&void 0!==r.searchIndex&&(e.searchIndex=r.searchIndex,t.searchIndex=r.searchIndex),d(r.cells,function(s){(a=s.cloneNode(!0)).data=s.data,e.appendChild(a),n.hiddenColumns.indexOf(s.cellIndex)<0&&((i=s.cloneNode(!0)).data=s.data,t.appendChild(i))}),s.push(e),n.activeRows.push(t)}),n.data=s,n.update()};var C=function(e,t){return this.dt=e,this.rows=t,this};C.prototype.build=function(e){var t,a=c("tr"),i=this.dt.headings;return i.length||(i=e.map(function(){return""})),d(i,function(i,n){t=c("td"),e[n]||e[n].length||(e[n]=""),t.innerHTML=e[n],t.data=e[n],a.appendChild(t)}),a},C.prototype.render=function(e){return e},C.prototype.add=function(e){if(r(e)){var t=this.dt;r(e[0])?d(e,function(e,a){t.data.push(this.build(e))},this):t.data.push(this.build(e)),this.update(),t.columns().rebuild()}},C.prototype.remove=function(e){var t=this.dt;r(e)?(e.sort(function(e,t){return t-e}),d(e,function(e,a){t.data.splice(e,1)})):t.data.splice(e,1),this.update(),t.columns().rebuild()},C.prototype.update=function(){d(this.dt.data,function(e,t){e.dataIndex=t})};var w=function(e,t){if(this.initialized=!1,this.options=l(n,t),"string"==typeof e){var a=e;if(!(e=document.querySelector(e)))throw new Error("The element '"+a+"' can not be found.")}if("table"!==e.tagName.toLowerCase())throw new Error("The selected element is not a table.");if(this.initialLayout=e.innerHTML,this.initialSortable=this.options.sortable,this.options.header||(this.options.sortable=!1),null===e.tHead&&(!this.options.data||this.options.data&&!this.options.data.headings)&&(this.options.sortable=!1),e.tBodies.length&&!e.tBodies[0].rows.length&&this.options.data&&!this.options.data.data)throw new Error("You seem to be using the data option, but you've not defined any rows.");this.table=e,this.init()},y=w.prototype;return w.extend=function(e,t){"function"==typeof t?w.prototype[e]=t:w[e]=t},y.init=function(e){if(this.initialized||f.contains(this.table,"dataTable-table"))return!1;var t=this;this.options=l(this.options,e||{}),this.isIE=!!/(msie|trident)/i.test(navigator.userAgent),this.currentPage=1,this.onFirstPage=!0,this.hiddenColumns=[],this.columnRenderers=[],this.selectedColumns=[],this.render(),this.options.plugins&&d(this.options.plugins,function(e,t){this[t](e)},this),setTimeout(function(){t.emit("datatable.init"),t.initialized=!0},10)},y.render=function(e){if(e){switch(e){case"page":this.renderPage();break;case"pager":this.renderPager();break;case"header":this.renderHeader()}return!1}var t=this,a=t.options,i="";if(a.data&&m.call(t),a.ajax){var n=a.ajax,s=new XMLHttpRequest;h(s,"progress",function(e){t.emit("datatable.ajax.progress",e,s)}),h(s,"load",function(e){if(4===s.readyState)if(t.emit("datatable.ajax.loaded",e,s),200===s.status){var a={};a.data=n.load?n.load.call(t,s):s.responseText,a.type="json",n.content&&n.content.type&&(a.type=n.content.type,a=l(a,n.content)),t.import(a),t.setColumns(!0),t.emit("datatable.ajax.success",e,s)}else t.emit("datatable.ajax.error",e,s)}),h(s,"error",function(e){t.emit("datatable.ajax.error",e,s)}),h(s,"abort",function(e){t.emit("datatable.ajax.abort",e,s)}),t.emit("datatable.ajax.loading",s),s.open("GET","string"==typeof n?a.ajax:a.ajax.url),s.send()}if(t.body=t.table.tBodies[0],t.head=t.table.tHead,t.foot=t.table.tFoot,t.body||(t.body=c("tbody"),t.table.appendChild(t.body)),t.hasRows=t.body.rows.length>0,!t.head){var r=c("thead"),o=c("tr");t.hasRows&&(d(t.body.rows[0].cells,function(){o.appendChild(c("th"))}),r.appendChild(o)),t.head=r,t.table.insertBefore(t.head,t.body),t.hiddenHeader=!a.ajax}if(t.headings=[],t.hasHeadings=t.head.rows.length>0,t.hasHeadings&&(t.header=t.head.rows[0],t.headings=[].slice.call(t.header.cells)),a.header||t.head&&t.table.removeChild(t.table.tHead),a.footer?t.head&&!t.foot&&(t.foot=c("tfoot",{html:t.head.innerHTML}),t.table.appendChild(t.foot)):t.foot&&t.table.removeChild(t.table.tFoot),t.wrapper=c("div",{class:"dataTable-wrapper dataTable-loading"}),i+="
",i+=a.layout.top,i+="
",i+="
",i+="
",i+=a.layout.bottom,i+="
",i=i.replace("{info}","
"),a.perPageSelect){var p="
";var u=c("select",{class:"dataTable-selector"});d(a.perPageSelect,function(e){var t=e===a.perPage,i=new Option(e,e,t,t);u.add(i)}),p=p.replace("{select}",u.outerHTML),i=i.replace("{select}",p)}else i=i.replace("{select}","");if(a.searchable){var g="";i=i.replace("{search}",g)}else i=i.replace("{search}","");t.hasHeadings&&this.render("header"),f.add(t.table,"dataTable-table");var b=c("div",{class:"dataTable-pagination"}),v=c("ul");b.appendChild(v),i=i.replace(/\{pager\}/g,b.outerHTML),t.wrapper.innerHTML=i,t.container=t.wrapper.querySelector(".dataTable-container"),t.pagers=t.wrapper.querySelectorAll(".dataTable-pagination"),t.label=t.wrapper.querySelector(".dataTable-info"),t.table.parentNode.replaceChild(t.wrapper,t.table),t.container.appendChild(t.table),t.rect=t.table.getBoundingClientRect(),t.data=[].slice.call(t.body.rows),t.activeRows=t.data.slice(),t.activeHeadings=t.headings.slice(),t.update(),a.ajax||t.setColumns(),this.fixHeight(),t.fixColumns(),a.header||f.add(t.wrapper,"no-header"),a.footer||f.add(t.wrapper,"no-footer"),a.sortable&&f.add(t.wrapper,"sortable"),a.searchable&&f.add(t.wrapper,"searchable"),a.fixedHeight&&f.add(t.wrapper,"fixed-height"),a.fixedColumns&&f.add(t.wrapper,"fixed-columns"),t.bindEvents()},y.renderPage=function(){if(this.hasRows&&this.totalPages){this.currentPage>this.totalPages&&(this.currentPage=1);var e=this.currentPage-1,t=a.createDocumentFragment();this.hasHeadings&&(p(this.header,this.isIE),d(this.activeHeadings,function(e){this.header.appendChild(e)},this)),d(this.pages[e],function(e){t.appendChild(this.rows().render(e))},this),this.clear(t),this.onFirstPage=1===this.currentPage,this.onLastPage=this.currentPage===this.lastPage}else this.clear();var i,n=0,s=0,r=0;if(this.totalPages&&(r=(s=(n=this.currentPage-1)*this.options.perPage)+this.pages[n].length,s+=1,i=this.searching?this.searchData.length:this.data.length),this.label&&this.options.labels.info.length){var o=this.options.labels.info.replace("{start}",s).replace("{end}",r).replace("{page}",this.currentPage).replace("{pages}",this.totalPages).replace("{rows}",i);this.label.innerHTML=i?o:""}1==this.currentPage&&this.fixHeight()},y.renderPager=function(){if(p(this.pagers,this.isIE),this.totalPages>1){var e="pager",t=a.createDocumentFragment(),i=this.onFirstPage?1:this.currentPage-1,n=this.onlastPage?this.totalPages:this.currentPage+1;this.options.firstLast&&t.appendChild(u(e,1,this.options.firstText)),this.options.nextPrev&&t.appendChild(u(e,i,this.options.prevText));var s=this.links;this.options.truncatePager&&(s=b(this.links,this.currentPage,this.pages.length,this.options.pagerDelta,this.options.ellipsisText)),f.add(this.links[this.currentPage-1],"active"),d(s,function(e){f.remove(e,"active"),t.appendChild(e)}),f.add(this.links[this.currentPage-1],"active"),this.options.nextPrev&&t.appendChild(u(e,n,this.options.nextText)),this.options.firstLast&&t.appendChild(u(e,this.totalPages,this.options.lastText)),d(this.pagers,function(e){e.appendChild(t.cloneNode(!0))})}},y.renderHeader=function(){var e=this;e.labels=[],e.headings&&e.headings.length&&d(e.headings,function(t,a){if(e.labels[a]=t.textContent,f.contains(t.firstElementChild,"dataTable-sorter")&&(t.innerHTML=t.firstElementChild.innerHTML),t.sortable="false"!==t.getAttribute("data-sortable"),t.originalCellIndex=a,e.options.sortable&&t.sortable){var i=c("a",{href:"#",class:"dataTable-sorter",html:t.innerHTML});t.innerHTML="",t.setAttribute("data-sortable",""),t.appendChild(i)}}),e.fixColumns()},y.bindEvents=function(){var e=this,t=e.options;if(t.perPageSelect){var a=e.wrapper.querySelector(".dataTable-selector");a&&h(a,"change",function(a){t.perPage=parseInt(this.value,10),e.update(),e.fixHeight(),e.emit("datatable.perpage",t.perPage)})}t.searchable&&(e.input=e.wrapper.querySelector(".dataTable-input"),e.input&&h(e.input,"keyup",function(t){e.search(this.value)})),h(e.wrapper,"click",function(a){var i=a.target;"a"===i.nodeName.toLowerCase()&&(i.hasAttribute("data-page")?(e.page(i.getAttribute("data-page")),a.preventDefault()):t.sortable&&f.contains(i,"dataTable-sorter")&&"false"!=i.parentNode.getAttribute("data-sortable")&&(e.columns().sort(e.activeHeadings.indexOf(i.parentNode)+1),a.preventDefault()))})},y.setColumns=function(e){var t=this;e||d(t.data,function(e){d(e.cells,function(e){e.data=e.innerHTML})}),t.options.columns&&t.headings.length&&d(t.options.columns,function(e){r(e.select)||(e.select=[e.select]),e.hasOwnProperty("render")&&"function"==typeof e.render&&(t.selectedColumns=t.selectedColumns.concat(e.select),t.columnRenderers.push({columns:e.select,renderer:e.render})),d(e.select,function(a){var i=t.headings[a];e.type&&i.setAttribute("data-type",e.type),e.format&&i.setAttribute("data-format",e.format),e.hasOwnProperty("sortable")&&i.setAttribute("data-sortable",e.sortable),e.hasOwnProperty("hidden")&&!1!==e.hidden&&t.columns(a).hide(),e.hasOwnProperty("sort")&&1===e.select.length&&t.columns().sort(e.select[0]+1,e.sort,!0)})}),t.hasRows&&(d(t.data,function(e,t){e.dataIndex=t,d(e.cells,function(e){e.data=e.innerHTML})}),t.selectedColumns.length&&d(t.data,function(e){d(e.cells,function(a,i){t.selectedColumns.indexOf(i)>-1&&d(t.columnRenderers,function(n){n.columns.indexOf(i)>-1&&(a.innerHTML=n.renderer.call(t,a.data,a,e))})})}),t.columns().rebuild()),t.render("header")},y.destroy=function(){this.table.innerHTML=this.initialLayout,f.remove(this.table,"dataTable-table"),this.wrapper.parentNode.replaceChild(this.table,this.wrapper),this.initialized=!1},y.update=function(){this.paginate(this),this.render("page"),this.links=[];for(var e=this.pages.length;e--;){var t=e+1;this.links[e]=u(0===e?"active":"",t,t)}this.sorting=!1,this.render("pager"),this.rows().update(),this.emit("datatable.update")},y.paginate=function(){var e=this.options.perPage,t=this.activeRows;return this.searching&&(t=[],d(this.searchData,function(e){t.push(this.activeRows[e])},this)),this.pages=t.map(function(a,i){return i%e==0?t.slice(i,i+e):null}).filter(function(e){return e}),this.totalPages=this.lastPage=this.pages.length,this.totalPages},y.fixColumns=function(){if(this.options.fixedColumns&&this.activeHeadings&&this.activeHeadings.length){var e,t=!1;if(this.columnWidths=[],this.table.tHead)d(this.activeHeadings,function(e){e.style.width=""},this),d(this.activeHeadings,function(e,t){var a=e.offsetWidth,i=a/this.rect.width*100;e.style.width=i+"%",this.columnWidths[t]=a},this);else{e=[],t=c("thead");var a=c("tr"),i=this.table.tBodies[0].rows[0].cells;d(i,function(){var t=c("th");a.appendChild(t),e.push(t)}),t.appendChild(a),this.table.insertBefore(t,this.body);var n=[];d(e,function(e,t){var a=e.offsetWidth,i=a/this.rect.width*100;n.push(i),this.columnWidths[t]=a},this),d(this.data,function(e){d(e.cells,function(e,t){this.columns(e.cellIndex).visible()&&(e.style.width=n[t]+"%")},this)},this),this.table.removeChild(t)}}},y.fixHeight=function(){this.options.fixedHeight&&(this.container.style.height=null,this.rect=this.container.getBoundingClientRect(),this.container.style.height=this.rect.height+"px")},y.search=function(e){if(!this.hasRows)return!1;var t=this;if(e=e.toLowerCase(),this.currentPage=1,this.searching=!0,this.searchData=[],!e.length)return this.searching=!1,this.update(),this.emit("datatable.search",e,this.searchData),f.remove(this.wrapper,"search-results"),!1;this.clear(),d(this.data,function(a,i){var n=this.searchData.indexOf(a)>-1;e.split(" ").reduce(function(e,i){for(var n=!1,s=0;s-1&&t.columns(a.cells[s].cellIndex).visible()){n=!0;break}return e&&n},!0)&&!n?(a.searchIndex=i,this.searchData.push(i)):a.searchIndex=null},this),f.add(this.wrapper,"search-results"),t.searchData.length?t.update():(f.remove(t.wrapper,"search-results"),t.setMessage(t.options.labels.noRows)),this.emit("datatable.search",e,this.searchData)},y.page=function(e){return e!=this.currentPage&&(isNaN(e)||(this.currentPage=parseInt(e,10)),!(e>this.pages.length||e<0)&&(this.render("page"),this.render("pager"),void this.emit("datatable.page",e)))},y.sortColumn=function(e,t){this.columns().sort(e,t)},y.insert=function(e){var t=this,a=[];if(s(e)){if(e.headings&&!t.hasHeadings&&!t.hasRows){var i,n=c("tr");d(e.headings,function(e){i=c("th",{html:e}),n.appendChild(i)}),t.head.appendChild(n),t.header=n,t.headings=[].slice.call(n.cells),t.hasHeadings=!0,t.options.sortable=t.initialSortable,t.render("header")}e.data&&r(e.data)&&(a=e.data)}else r(e)&&d(e,function(e){var i=[];d(e,function(e,a){var n=t.labels.indexOf(a);n>-1&&(i[n]=e)}),a.push(i)});a.length&&(t.rows().add(a),t.hasRows=!0),t.update(),t.fixColumns()},y.refresh=function(){this.options.searchable&&(this.input.value="",this.searching=!1),this.currentPage=1,this.onFirstPage=!0,this.update(),this.emit("datatable.refresh")},y.clear=function(e){this.body&&p(this.body,this.isIE);var t=this.body;this.body||(t=this.table),e&&("string"==typeof e&&(a.createDocumentFragment().innerHTML=e),t.appendChild(e))},y.export=function(e){if(!this.hasHeadings&&!this.hasRows)return!1;var t,a,n,o,d=this.activeHeadings,h=[],c=[],p={download:!0,skipColumn:[],lineDelimiter:"\n",columnDelimiter:",",tableName:"myTable",replacer:null,space:4};if(!s(e))return!1;var u=l(p,e);if(u.type){if("txt"!==u.type&&"csv"!==u.type||(h[0]=this.header),u.selection)if(isNaN(u.selection)){if(r(u.selection))for(t=0;t'+e+""}))},y.columns=function(e){return new x(this,e)},y.rows=function(e){return new C(this,e)},y.on=function(e,t){this.events=this.events||{},this.events[e]=this.events[e]||[],this.events[e].push(t)},y.off=function(e,t){this.events=this.events||{},e in this.events!=!1&&this.events[e].splice(this.events[e].indexOf(t),1)},y.emit=function(e){if(this.events=this.events||{},e in this.events!=!1)for(var t=0;t