ソースを参照

Fix #1044, fix #460: added exportDataType option.

zhixin 10 年 前
コミット
dafc788fb6

+ 6 - 0
src/extensions/export/README.md

@@ -16,6 +16,12 @@ Use Plugin: [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jqu
 * description: set `true` to show export button.
 * default: `false`
 
+### exportDataType
+
+* type: String
+* description: export data type, support: 'basic', 'all', 'selected'.
+* default: `basic`
+
 ### exportTypes
 
 * type: Array

+ 23 - 4
src/extensions/export/bootstrap-table-export.js

@@ -21,6 +21,7 @@
 
     $.extend($.fn.bootstrapTable.defaults, {
         showExport: false,
+        exportDataType: '', // basic, all, selected
         // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
         exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
         exportOptions: {}
@@ -73,10 +74,28 @@
                 });
 
                 $menu.find('li').click(function () {
-                    that.$el.tableExport($.extend({}, that.options.exportOptions, {
-                        type: $(this).data('type'),
-                        escape: false
-                    }));
+                    var type = $(this).data('type'),
+                        doExport = function () {
+                            that.$el.tableExport($.extend({}, that.options.exportOptions, {
+                                type: type,
+                                escape: false
+                            }));
+                        };
+
+                    if (that.options.exportDataType === 'all' && that.options.pagination) {
+                        that.togglePagination();
+                        doExport();
+                        that.togglePagination();
+                    } else if (that.options.exportDataType === 'selected') {
+                        var data = that.getData(),
+                            selectedData = that.getAllSelections();
+
+                        that.load(selectedData);
+                        doExport();
+                        that.load(data);
+                    } else {
+                        doExport();
+                    }
                 });
             }
         }