Browse Source

create jumpto extension

Jay 8 years ago
parent
commit
bba8f7522d

+ 7 - 0
src/extensions/page-jumpto/bootstrap-table-jumpto.css

@@ -0,0 +1,7 @@
+.jumpto input {
+    height: 31px;
+    width: 50px;
+    margin-left: 5px;
+    text-align: center;
+    display: inline-block;
+}

+ 52 - 0
src/extensions/page-jumpto/bootstrap-table-jumpto.js

@@ -0,0 +1,52 @@
+/**
+ * @author Jay <jwang@dizsoft.com>
+ */
+
+(function ($) {
+    'use strict';
+    var sprintf = $.fn.bootstrapTable.utils.sprintf;
+
+    $.extend($.fn.bootstrapTable.defaults, {
+        showJumpto: false,
+        exportOptions: {}
+    });
+
+    $.extend($.fn.bootstrapTable.locales, {
+        formatJumpto: function () {
+            return 'GO';
+        }
+    });
+    $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
+
+    var BootstrapTable = $.fn.bootstrapTable.Constructor,
+        _initPagination = BootstrapTable.prototype.initPagination;
+
+    BootstrapTable.prototype.initPagination = function () {
+        this.showToolbar = this.options.showExport;
+
+        _initPagination.apply(this, Array.prototype.slice.apply(arguments));
+
+        if (this.options.showJumpto) {
+            var that = this,
+                $pageGroup = this.$pagination.find('ul.pagination'),
+                $jumpto = $pageGroup.find('div.jumpto');
+
+            if (!$jumpto.length) {
+                $jumpto = $([
+                    '<li class="jumpto">',
+                        '<input type="text" class="form-control">',
+                        '<button class="m-l-5 btn' +
+                            sprintf(' btn-%s', this.options.buttonsClass) +
+                            sprintf(' btn-%s', this.options.iconSize) +
+                            '" title="' + this.options.formatJumpto() + '" ' +
+                            ' type="button">'+this.options.formatJumpto(),
+                        '</button>',
+                    '</li>'].join('')).appendTo($pageGroup);
+
+                $jumpto.find('button').click(function () {
+                    that.selectPage(parseInt($jumpto.find('input').val()));
+                });
+            }
+        }
+    };
+})(jQuery);