Browse Source

Support exporting table footer (#2925)

feat(export extension): add `exportFooter` option
ibraheemhlaiyil 8 years ago
parent
commit
9c9f10c864
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/extensions/export/bootstrap-table-export.js

+ 31 - 0
src/extensions/export/bootstrap-table-export.js

@@ -93,10 +93,41 @@
                 $menu.find('li').click(function () {
                     var type = $(this).data('type'),
                         doExport = function () {
+                            
+                            if (!!that.options.exportFooter) {
+                                var data = that.getData();
+                                var $footerRow = that.$tableFooter.find("tr").first();
+
+                                var footerData = { };
+                                var footerHtml = [];
+
+                                $.each($footerRow.children(), function (index, footerCell) {
+                                    
+                                    var footerCellHtml = $(footerCell).children(".th-inner").first().html();
+                                    footerData[that.columns[index].field] = footerCellHtml == ' ' ? null : footerCellHtml;
+
+                                    // grab footer cell text into cell index-based array
+                                    footerHtml.push(footerCellHtml);
+                                });
+
+                                that.append(footerData);
+
+                                var $lastTableRow = that.$body.children().last();
+
+                                $.each($lastTableRow.children(), function (index, lastTableRowCell) {
+
+                                    $(lastTableRowCell).html(footerHtml[index]);
+                                });
+                            }
+                            
                             that.$el.tableExport($.extend({}, that.options.exportOptions, {
                                 type: type,
                                 escape: false
                             }));
+                            
+                            if (!!that.options.exportFooter) {
+                                that.load(data);
+                            }
                         };
 
                     if (that.options.exportDataType === 'all' && that.options.pagination) {