You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/SoftMng/Content/bootstraptable-1.12.1-dist/extensions/group-by/bootstrap-table-group-by.mi...

7 lines
3.3 KiB
JavaScript

3 years ago
/*
* bootstrap-table - v1.12.1 - 2018-03-12
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2018 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b,c="data-tt-id",d="data-tt-parent-id",e={},f=void 0,g=function(b,c){for(var d=b.$body.find("tr").not("[data-tt-parent-id]"),e=0;e<d.length;e++)if(e===c)return a(d[e]).attr("data-tt-id");return void 0},h=function(b,c){var d={};return a.each(c,function(a,c){if(!c.IsParent)for(var e in c)isNaN(parseFloat(c[e]))||b.columns[b.fieldsColumnsIndex[e]].groupBySumGroup&&(void 0===d[e]&&(d[e]=0),d[e]+=+c[e])}),d},i=function(a,g){return b.apply([a,g]),e[c.toString()]=g,a.IsParent?(f=g,delete e[d.toString()]):e[d.toString()]=void 0===f?g:f,e},j=function(a,b){for(var c=[],d=0;d<a.options.groupByField.length;d++)c.push(b[a.options.groupByField[d]]);return c},k=function(a,b,c){for(var d={},e=0;e<a.options.groupByField.length;e++)d[a.options.groupByField[e].toString()]=b[c][0][a.options.groupByField[e]];return d.IsParent=!0,d},l=function(b,c){var d={};return a.each(b,function(a,b){var e=JSON.stringify(c(b));d[e]=d[e]||[],d[e].push(b)}),Object.keys(d).map(function(a){return d[a]})},m=function(b,c){for(var d=[],e={},f=l(c,function(a){return j(b,a)}),g=0;g<f.length;g++)f[g].unshift(k(b,f,g)),b.options.groupBySumGroup&&(e=h(b,f[g]),a.isEmptyObject(e)||f[g].push(e));return d=d.concat.apply(d,f),!b.options.loaded&&d.length>0&&(b.options.loaded=!0,b.options.originalData=b.options.data,b.options.data=d),d};a.extend(a.fn.bootstrapTable.defaults,{groupBy:!1,groupByField:[],groupBySumGroup:!1,groupByInitExpanded:void 0,loaded:!1,originalData:void 0}),a.fn.bootstrapTable.methods.push("collapseAll","expandAll","refreshGroupByField"),a.extend(a.fn.bootstrapTable.COLUMN_DEFAULTS,{groupBySumGroup:!1});var n=a.fn.bootstrapTable.Constructor,o=n.prototype.init,p=n.prototype.initData;n.prototype.init=function(){if(!this.options.sortName&&this.options.groupBy&&this.options.groupByField.length>0){var c=this;Object.keys||a.fn.bootstrapTable.utils.objectKeys(),this.options.loaded=!1,this.options.originalData=void 0,b=this.options.rowAttributes,this.options.rowAttributes=i,this.$el.off("post-body.bs.table").on("post-body.bs.table",function(){c.$el.treetable({expandable:!0,onNodeExpand:function(){c.options.height&&c.resetHeader()},onNodeCollapse:function(){c.options.height&&c.resetHeader()}},!0),void 0!==c.options.groupByInitExpanded&&("number"==typeof c.options.groupByInitExpanded?c.expandNode(c.options.groupByInitExpanded):"all"===c.options.groupByInitExpanded.toLowerCase()&&c.expandAll())})}o.apply(this,Array.prototype.slice.apply(arguments))},n.prototype.initData=function(a,b){this.options.sortName||this.options.groupBy&&this.options.groupByField.length>0&&(this.options.groupByField="string"==typeof this.options.groupByField?this.options.groupByField.replace("[","").replace("]","").replace(/ /g,"").toLowerCase().split(","):this.options.groupByField,a=m(this,a?a:this.options.data)),p.apply(this,[a,b])},n.prototype.expandAll=function(){this.$el.treetable("expandAll")},n.prototype.collapseAll=function(){this.$el.treetable("collapseAll")},n.prototype.expandNode=function(a){a=g(this,a),void 0!==a&&this.$el.treetable("expandNode",a)},n.prototype.refreshGroupByField=function(b){a.fn.bootstrapTable.utils.compareObjects(this.options.groupByField,b)||(this.options.groupByField=b,this.load(this.options.originalData))}}(jQuery);