bootstrap-table-export.min.js 2.5 KB

1
  1. !function(t){"use strict";var o=t.fn.bootstrapTable.utils.sprintf,e={json:"JSON",xml:"XML",png:"PNG",csv:"CSV",txt:"TXT",sql:"SQL",doc:"MS-Word",excel:"MS-Excel",xlsx:"MS-Excel (OpenXML)",powerpoint:"MS-Powerpoint",pdf:"PDF"};t.extend(t.fn.bootstrapTable.defaults,{showExport:!1,exportDataType:"basic",exportTypes:["json","xml","csv","txt","sql","excel"],exportOptions:{}}),t.extend(t.fn.bootstrapTable.defaults.icons,{export:"glyphicon-export icon-share"}),t.extend(t.fn.bootstrapTable.locales,{formatExport:function(){return"Export data"}}),t.extend(t.fn.bootstrapTable.defaults,t.fn.bootstrapTable.locales);var s=t.fn.bootstrapTable.Constructor,i=s.prototype.initToolbar;s.prototype.initToolbar=function(){if(this.showToolbar=this.options.showExport,i.apply(this,Array.prototype.slice.apply(arguments)),this.options.showExport){var s=this,n=this.$toolbar.find(">.btn-group"),a=n.find("div.export");if(!a.length){var p=(a=t(['<div class="export btn-group">','<button class="btn'+o(" btn-%s",this.options.buttonsClass)+o(" btn-%s",this.options.iconSize)+' dropdown-toggle" aria-label="export type" title="'+this.options.formatExport()+'" data-toggle="dropdown" type="button">',o('<i class="%s %s"></i> ',this.options.iconsPrefix,this.options.icons.export),'<span class="caret"></span>',"</button>",'<ul class="dropdown-menu" role="menu">',"</ul>","</div>"].join("")).appendTo(n)).find(".dropdown-menu"),l=this.options.exportTypes;if("string"==typeof this.options.exportTypes){var r=this.options.exportTypes.slice(1,-1).replace(/ /g,"").split(",");l=[],t.each(r,function(t,o){l.push(o.slice(1,-1))})}t.each(l,function(t,o){e.hasOwnProperty(o)&&p.append(['<li role="menuitem" data-type="'+o+'">','<a href="javascript:void(0)">',e[o],"</a>","</li>"].join(""))}),p.find("li").click(function(){var o=t(this).data("type"),e=function(){s.$el.tableExport(t.extend({},s.options.exportOptions,{type:o,escape:!1}))};if("all"===s.options.exportDataType&&s.options.pagination)s.$el.one("server"===s.options.sidePagination?"post-body.bs.table":"page-change.bs.table",function(){e(),s.togglePagination()}),s.togglePagination();else if("selected"===s.options.exportDataType){var i=s.getData(),n=s.getAllSelections();if("server"===s.options.sidePagination){(i={total:s.options.totalRows})[s.options.dataField]=s.getData();var a="function"==typeof require?require("table"):null;(n={total:s.options.totalRows})[s.options.dataField]=a&&s.options.maintainSelected?a.api.selecteddata(s.$el):s.getAllSelections()}s.load(n),e(),s.load(i)}else e()})}}}}(jQuery);