diff --git a/bower.json b/bower.json index 9d60a3a..5cbaa63 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "tc-grid", - "version": "0.8.2", + "version": "0.8.3", "homepage": "https://github.com/ThirdCornerLLC/tc-grid", "authors": [ "Zach Barnes ", diff --git a/dist/tc-grid.js b/dist/tc-grid.js index b72b3b1..a7ad05e 100644 --- a/dist/tc-grid.js +++ b/dist/tc-grid.js @@ -321,7 +321,7 @@ } function initSort() { - if (!vm.options || !vm.options.sorting.sort) { + if (!vm.options || !vm.options.sorting || !vm.options.sorting.sort) { return; }angular.forEach(vm.options.sorting.sort, function (sortItem) { var col = sortItem.split(" ")[0]; diff --git a/dist/tc-grid.min.js b/dist/tc-grid.min.js index dbf700d..24bf181 100644 --- a/dist/tc-grid.min.js +++ b/dist/tc-grid.min.js @@ -1 +1 @@ -"use strict";!function(){function t(t,n,i,e){return{restrict:"E",scope:!0,template:function(t,n){var e=t.find("tc-column"),o="";n.defaultHeaders=[],angular.forEach(e,function(i,e){var a=i.getAttribute("tc-class");i.setAttribute("data-identifier",Math.random()),i.setAttribute("tc-col-index",e+1),i.className+=" "+(a||"tc-style_td"),n.defaultHeaders.push({element:t,options:{tcName:i.getAttribute("tc-name"),tcField:i.getAttribute("tc-field"),identifier:i.getAttribute("data-identifier")}}),o+=i.outerHTML});var a=i.get("tcGrid.html");return a=a.replace(/%GRIDCLASS%/g,n.tcGridClass||"tc-grid"),a=a.replace(/%ROWCLASS%/g,n.tcRowClass?"":"tc-style_tr"),a=a.replace(/%ROWEXPRESSION%/g,n.tcRowClass||""),a=a.replace(/%ROWCLICK%/g,n.tcRowClick?'ng-click="'+n.tcRowClick+'"':""),a=a.replace(/%ROWLINK%/g,n.tcRowLink?' ng-href="'+n.tcRowLink+'"':""),a=a.replace(/%FILTER%/g,n.tcGridFilter?" | filter: "+n.tcGridFilter:""),a=a.replace(/%CHILDREN%/g,o)},controller:["$scope","$element","$attrs",function(i,o,a){function r(){k.options=t(a.tcOptions)(i.$parent),k.data=t(a.tcData)(i.$parent),c(),m(),v(),k.options&&(k.options.onLoad&&"function"==typeof k.options.onLoad?k.options.onLoad():k.options.sorting.onSortChange?O():k.options.paging.onPageChange&&_())}function s(){k.options.paging.currentPage=1,k.options.sorting.sort=[],R(),_(),O()}function c(){for(var t;null!=(t=a.defaultHeaders.shift());)p(t.element,t.options),t.element=null}function p(t,n){if(!l(n)){var i,e,o;n.tcField=n.tcField||"",n.tcName=n.tcName||n.tcField;var r=k.headerTemplates.length;n.tcField?(i=" ng-click=\"tcGrid.sort('"+n.tcField+"')\"",e=' id="'+a.tcOptions+"_"+n.tcField.replace(/\./g,"")+'"'):(i="",e=""),o=" ng-class=\"{'tc-hide-col': !tcGrid.columns['"+r+"'].visible}\"";var s='
"+n.tcName+'
',c=angular.element(s);k.headerTemplates.push(c),k.columnTemplates.push(t.clone()),t=null,c=null,N(n),g()}}function l(t){for(var n=0;n-1?t=i:i.className&&i.className.indexOf("tc-display_tbody")>-1&&(n=i,n.parent=i.parentNode);return e.tbody=n,e.thead=t,n=null,t=null,e}function m(){k.options&&(k.options.reset=s,k.options.prev=P,k.options.next=S,k.options.first=G,k.options.last=b,k.options.sort=I,k.options.paging?C():k.options.paging={},k.options.sorting?h():k.options.sorting={})}function v(){function t(){return F?void(k.options&&k.options.paging&&y()):void(F=!0)}a.tcOptions&&i.$parent.$watch(a.tcOptions,function(n,i){if(k.options=n,n==i&&n.columnDisplay)g(k.options.columnDisplay);else if(n!=i||n.columnDisplay)n.columnDisplay!=i.columnDisplay&&g(k.options.columnDisplay);else{for(var e=[],o=0;o0?Math.ceil(k.options.paging.totalItemCount/k.options.paging.pageSize):0,k.pageCount<1&&(k.pageCount=1),k.options.paging.pageCount=k.pageCount}function G(){k.options.paging.currentPage=1,_()}function P(){k.options.paging.currentPage-=1,k.options.paging.currentPage<1&&(k.options.paging.currentPage=1),_()}function S(){k.options.paging.currentPage+=1,k.options.paging.currentPage>k.pageCount&&(k.options.paging.currentPage=k.pageCount),_()}function b(){k.options.paging.currentPage=k.pageCount,_()}function _(){k.options.paging.onPageChange&&k.options.paging.onPageChange(k.options.paging.currentPage,k.options.paging.pageSize,k.options.sorting.sort)}function O(){k.options.sorting.onSortChange&&(k.options.paging?(k.options.paging.currentPage=1,k.options.sorting.onSortChange(k.options.paging.currentPage,k.options.paging.pageSize,k.options.sorting.sort)):k.options.sorting.onSortChange(null,null,k.options.sorting.sort))}function I(t){if(0!==Object.getOwnPropertyNames(k.columns).length){var n=$(t);if(n){var i="asc";n.hasClass("asc")&&(i="desc"),R(),n.addClass(i),k.options.sorting.sort=[t+" "+i],O(),n=null}}}function R(){angular.forEach(Object.keys(k.columns),function(t){if(k.columns[t].field){var n=$(k.columns[t].field);n&&(n.removeClass("desc"),n.removeClass("asc"),n=null)}})}function $(t){if(t){var n=a.tcOptions+"_"+t.replace(/\./g,""),i=document.getElementById(n);if(i){var e=i.childNodes;for(var o in e)if(e[o].className&&e[o].className.indexOf("tc-display_sort")>-1)return angular.element(e[o])}return null}}function N(t){k.columns.push({field:t.tcField,identifier:t.identifier,visible:!0})}function w(){y(),k.options.paging.currentPage>k.pageCount?k.options.paging.currentPage=k.pageCount:k.options.paging.currentPage<0&&(k.options.paging.currentPage=0),_()}var L,z,F=!1,k=this;k.pageCount=1,k.showFooter=!1,k.columns=[],k.columnTemplates=[],k.headerTemplates=[],k.rowTemplate=a.rowTemplate,a.rowTemplate=null,k.addColumn=N,k.prev=P,k.next=S,k.first=G,k.last=b,k.sort=I,k.updatePageSize=w,k.orderColumns=g,k.registerColumn=p,r(),i.$on("$destroy",function(){L&&e.cancel(L),z&&e.cancel(z)})}],controllerAs:"tcGrid"}}function n(){return{restrict:"E",require:"^?tcGrid",replace:!0,transclude:!0,template:function(t){var n=function(n,i){return t.apply(this,arguments)};return n.toString=function(){return t.toString()},n}(function(t,n){var i="
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n \r\n\r\n
\r\n\r\n
\r\n
\r\n {{(tcGrid.options.paging.currentPage - 1) * tcGrid.options.paging.pageSize + 1}}\r\n -\r\n {{tcGrid.options.paging.currentPage === tcGrid.pageCount ? tcGrid.options.paging.totalItemCount : tcGrid.options.paging.currentPage * tcGrid.options.paging.pageSize}}\r\n of\r\n {{tcGrid.options.paging.totalItemCount}}\r\n
\r\n
\r\n {{tcGrid.options.paging.currentPage}} / {{tcGrid.pageCount}}\r\n \r\n \r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n
\r\n
\r\n\r\n\r\n')}]); \ No newline at end of file +"use strict";!function(){function t(t,n,i,o){return{restrict:"E",scope:!0,template:function(t,n){var o=t.find("tc-column"),e="";n.defaultHeaders=[],angular.forEach(o,function(i,o){var a=i.getAttribute("tc-class");i.setAttribute("data-identifier",Math.random()),i.setAttribute("tc-col-index",o+1),i.className+=" "+(a||"tc-style_td"),n.defaultHeaders.push({element:t,options:{tcName:i.getAttribute("tc-name"),tcField:i.getAttribute("tc-field"),identifier:i.getAttribute("data-identifier")}}),e+=i.outerHTML});var a=i.get("tcGrid.html");return a=a.replace(/%GRIDCLASS%/g,n.tcGridClass||"tc-grid"),a=a.replace(/%ROWCLASS%/g,n.tcRowClass?"":"tc-style_tr"),a=a.replace(/%ROWEXPRESSION%/g,n.tcRowClass||""),a=a.replace(/%ROWCLICK%/g,n.tcRowClick?'ng-click="'+n.tcRowClick+'"':""),a=a.replace(/%ROWLINK%/g,n.tcRowLink?' ng-href="'+n.tcRowLink+'"':""),a=a.replace(/%FILTER%/g,n.tcGridFilter?" | filter: "+n.tcGridFilter:""),a=a.replace(/%CHILDREN%/g,e)},controller:["$scope","$element","$attrs",function(i,e,a){function r(){k.options=t(a.tcOptions)(i.$parent),k.data=t(a.tcData)(i.$parent),c(),m(),v(),k.options&&(k.options.onLoad&&"function"==typeof k.options.onLoad?k.options.onLoad():k.options.sorting.onSortChange?O():k.options.paging.onPageChange&&_())}function s(){k.options.paging.currentPage=1,k.options.sorting.sort=[],R(),_(),O()}function c(){for(var t;null!=(t=a.defaultHeaders.shift());)p(t.element,t.options),t.element=null}function p(t,n){if(!l(n)){var i,o,e;n.tcField=n.tcField||"",n.tcName=n.tcName||n.tcField;var r=k.headerTemplates.length;n.tcField?(i=" ng-click=\"tcGrid.sort('"+n.tcField+"')\"",o=' id="'+a.tcOptions+"_"+n.tcField.replace(/\./g,"")+'"'):(i="",o=""),e=" ng-class=\"{'tc-hide-col': !tcGrid.columns['"+r+"'].visible}\"";var s='
"+n.tcName+'
',c=angular.element(s);k.headerTemplates.push(c),k.columnTemplates.push(t.clone()),t=null,c=null,N(n),g()}}function l(t){for(var n=0;n-1?t=i:i.className&&i.className.indexOf("tc-display_tbody")>-1&&(n=i,n.parent=i.parentNode);return o.tbody=n,o.thead=t,n=null,t=null,o}function m(){k.options&&(k.options.reset=s,k.options.prev=P,k.options.next=S,k.options.first=G,k.options.last=b,k.options.sort=I,k.options.paging?C():k.options.paging={},k.options.sorting?h():k.options.sorting={})}function v(){function t(){return F?void(k.options&&k.options.paging&&y()):void(F=!0)}a.tcOptions&&i.$parent.$watch(a.tcOptions,function(n,i){if(k.options=n,n==i&&n.columnDisplay)g(k.options.columnDisplay);else if(n!=i||n.columnDisplay)n.columnDisplay!=i.columnDisplay&&g(k.options.columnDisplay);else{for(var o=[],e=0;e0?Math.ceil(k.options.paging.totalItemCount/k.options.paging.pageSize):0,k.pageCount<1&&(k.pageCount=1),k.options.paging.pageCount=k.pageCount}function G(){k.options.paging.currentPage=1,_()}function P(){k.options.paging.currentPage-=1,k.options.paging.currentPage<1&&(k.options.paging.currentPage=1),_()}function S(){k.options.paging.currentPage+=1,k.options.paging.currentPage>k.pageCount&&(k.options.paging.currentPage=k.pageCount),_()}function b(){k.options.paging.currentPage=k.pageCount,_()}function _(){k.options.paging.onPageChange&&k.options.paging.onPageChange(k.options.paging.currentPage,k.options.paging.pageSize,k.options.sorting.sort)}function O(){k.options.sorting.onSortChange&&(k.options.paging?(k.options.paging.currentPage=1,k.options.sorting.onSortChange(k.options.paging.currentPage,k.options.paging.pageSize,k.options.sorting.sort)):k.options.sorting.onSortChange(null,null,k.options.sorting.sort))}function I(t){if(0!==Object.getOwnPropertyNames(k.columns).length){var n=$(t);if(n){var i="asc";n.hasClass("asc")&&(i="desc"),R(),n.addClass(i),k.options.sorting.sort=[t+" "+i],O(),n=null}}}function R(){angular.forEach(Object.keys(k.columns),function(t){if(k.columns[t].field){var n=$(k.columns[t].field);n&&(n.removeClass("desc"),n.removeClass("asc"),n=null)}})}function $(t){if(t){var n=a.tcOptions+"_"+t.replace(/\./g,""),i=document.getElementById(n);if(i){var o=i.childNodes;for(var e in o)if(o[e].className&&o[e].className.indexOf("tc-display_sort")>-1)return angular.element(o[e])}return null}}function N(t){k.columns.push({field:t.tcField,identifier:t.identifier,visible:!0})}function w(){y(),k.options.paging.currentPage>k.pageCount?k.options.paging.currentPage=k.pageCount:k.options.paging.currentPage<0&&(k.options.paging.currentPage=0),_()}var L,z,F=!1,k=this;k.pageCount=1,k.showFooter=!1,k.columns=[],k.columnTemplates=[],k.headerTemplates=[],k.rowTemplate=a.rowTemplate,a.rowTemplate=null,k.addColumn=N,k.prev=P,k.next=S,k.first=G,k.last=b,k.sort=I,k.updatePageSize=w,k.orderColumns=g,k.registerColumn=p,r(),i.$on("$destroy",function(){L&&o.cancel(L),z&&o.cancel(z)})}],controllerAs:"tcGrid"}}function n(){return{restrict:"E",require:"^?tcGrid",replace:!0,transclude:!0,template:function(t){var n=function(n,i){return t.apply(this,arguments)};return n.toString=function(){return t.toString()},n}(function(t,n){var i="
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n \r\n\r\n
\r\n\r\n
\r\n
\r\n {{(tcGrid.options.paging.currentPage - 1) * tcGrid.options.paging.pageSize + 1}}\r\n -\r\n {{tcGrid.options.paging.currentPage === tcGrid.pageCount ? tcGrid.options.paging.totalItemCount : tcGrid.options.paging.currentPage * tcGrid.options.paging.pageSize}}\r\n of\r\n {{tcGrid.options.paging.totalItemCount}}\r\n
\r\n
\r\n {{tcGrid.options.paging.currentPage}} / {{tcGrid.pageCount}}\r\n \r\n \r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n
\r\n
\r\n\r\n\r\n')}]); \ No newline at end of file