浏览代码

Update select2-filter extension

zhixin 8 年之前
父节点
当前提交
7733c32a52

+ 2 - 2
src/extensions/select2-filter/bootstrap-table-select2-filter.js

@@ -256,10 +256,10 @@
     if (that.options.sidePagination === 'client') {
       this.data = $.grep(this.data, function (row, idx) {
         for (var field in filterValues) {
-          var column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, field)],
+          var column = that.columns[that.fieldsColumnsIndex[field]],
             filterValue = filterValues[field].toLowerCase(),
             rowValue = row[field];
-          
+
           rowValue = $.fn.bootstrapTable.utils.calculateObjectValue(
             that.header,
             that.header.formatters[$.inArray(field, that.header.fields)], [rowValue, row, idx], rowValue);

+ 0 - 128
src/extensions/select2-filter/data.json

@@ -1,128 +0,0 @@
-[
-  {
-    "id": 0,
-    "name": "Item 0",
-    "price": "$0",
-    "amount": 3
-  },
-  {
-    "id": 1,
-    "name": "Item 1",
-    "price": "$1",
-    "amount": 4
-  },
-  {
-    "id": 2,
-    "name": "Item 2",
-    "price": "$2",
-    "amount": 8
-  },
-  {
-    "id": 3,
-    "name": "Item 3",
-    "price": "$3",
-    "amount": 2
-  },
-  {
-    "id": 4,
-    "name": "Item 4",
-    "price": "$4",
-    "amount": 90
-  },
-  {
-    "id": 5,
-    "name": "Item 5",
-    "price": "$5",
-    "amount": 2
-  },
-  {
-    "id": 6,
-    "name": "Item 6",
-    "price": "$6",
-    "amount": 3
-  },
-  {
-    "id": 7,
-    "name": "Item 7",
-    "price": "$7",
-    "amount": 7
-  },
-  {
-    "id": 8,
-    "name": "Item 8",
-    "price": "$8",
-    "amount": 39
-  },
-  {
-    "id": 9,
-    "name": "Item 9",
-    "price": "$9",
-    "amount": 78
-  },
-  {
-    "id": 10,
-    "name": "Item 10",
-    "price": "$10",
-    "amount": 30
-  },
-  {
-    "id": 11,
-    "name": "Item 11",
-    "price": "$11",
-    "amount": 32
-  },
-  {
-    "id": 12,
-    "name": "Item 12",
-    "price": "$12",
-    "amount": 12
-  },
-  {
-    "id": 13,
-    "name": "Item 13",
-    "price": "$13",
-    "amount": 76
-  },
-  {
-    "id": 14,
-    "name": "Item 14",
-    "price": "$14",
-    "amount": 10
-  },
-  {
-    "id": 15,
-    "name": "Item 15",
-    "price": "$15",
-    "amount": 9
-  },
-  {
-    "id": 16,
-    "name": "Item 16",
-    "price": "$16",
-    "amount": 8
-  },
-  {
-    "id": 17,
-    "name": "Item 17",
-    "price": "$17",
-    "amount": 1
-  },
-  {
-    "id": 18,
-    "name": "Item 18",
-    "price": "$18",
-    "amount": 99
-  },
-  {
-    "id": 19,
-    "name": "Item 19",
-    "price": "$19",
-    "amount": 100
-  },
-  {
-    "id": 20,
-    "name": "Item 20",
-    "price": "$20",
-    "amount": 109
-  }
-]

+ 0 - 119
src/extensions/select2-filter/select2-filter.html

@@ -1,119 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <title>Select2 Filter</title>
-  <meta charset="utf-8">
-  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css"/>
-  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"/>
-  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css"/>
-
-  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
-  <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>
-  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.js"></script>
-  <script src="bootstrap-table-select2-filter.js"></script>
-  <script>
-    $(function () {
-      function getNumberFilterTemplate(fieldId) {
-        var numberFilterClass = 'numberFilter-' + fieldId,
-                template = function (bootstrapTable, col, isVisible) {
-                  var search = function (event, value) {
-                    bootstrapTable.searchText = undefined;
-                    clearTimeout(bootstrapTable.timeoutId);
-                    bootstrapTable.timeoutId = setTimeout(function () {
-                      bootstrapTable.onColumnSearch(event, fieldId, value);
-                    }, bootstrapTable.options.searchTimeOut);
-                  };
-
-                  var $el = $('<div class="input-group input-group-sm ' + numberFilterClass + '" style="width: 100%; visibility:' + isVisible + '">' +
-                                  '<span class="input-group-addon">&gt;</span>' +
-                                  '<input type="number" class="form-control">' +
-                                  '</div>'),
-                          $input = $el.find('input');
-
-                  $input.off('keyup').on('keyup', function (event) {
-                    search(event, $(this).val());
-                  });
-
-                  $input.off('mouseup').on('mouseup', function (event) {
-                    var $input = $(this),
-                            oldValue = $input.val();
-
-                    if (oldValue === "") {
-                      return;
-                    }
-
-                    setTimeout(function () {
-                      var newValue = $input.val();
-                      if (newValue === "") {
-                        search(event, newValue);
-                      }
-                    }, 1);
-                  });
-
-                  return $el;
-                };
-
-        return template;
-      }
-
-      var options = {
-        filterValues: {price: "$2"},
-        url: "data.json",
-        columns: [
-          {
-            field: "id",
-            title: "ID",
-            filter: {
-              type: "input"
-            }
-          },
-          {
-            field: "name",
-            title: "Item Name",
-            filter: {
-              type: "select",
-              data: []
-            }
-          },
-          {
-            field: "price",
-            title: "Item Price",
-            filter: {
-              type: "select",
-              data: ["$1", "$2", "$3"]
-            }
-          },
-          {
-            field: "amount",
-            title: "Amount",
-            width: 200,
-            filter: {
-              template: getNumberFilterTemplate("amount"),
-              setFilterValue: function ($filter, field, value) {
-                if (value) {
-                  $filter.find('input').val(value.value);
-                }
-              }
-            }
-          }
-        ],
-        filter: true,
-        filterTemplate: {
-          input: function (bootstrapTable, column, isVisible) {
-            return '<input type="text" class="form-control input-sm" data-filter-field="' + column.field + '" style="width: 100%; visibility:' + isVisible + '">';
-          }
-        }
-      };
-
-      var $table = $("#table").bootstrapTable(options);
-      $table.bootstrapTable("setSelect2Data", "name", ["item 1", "item 2", "item 3"]);
-    });
-  </script>
-</head>
-<body>
-<div class="container">
-  <h1>Select2 Filter</h1>
-  <table id="table"></table>
-</div>
-</body>
-</html>