Browse Source

Adding multiple option

djhvscf 7 years ago
parent
commit
e965ec187e

+ 1 - 1
site/docs/extensions/filter-control.md

@@ -87,7 +87,7 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 
 - **Detail:**
 
-   Set `input`: show an input control, `select`: show a select control, `datepicker`: show a datepicker control.
+   Set `input`: show an input control, `select`: show a select control, `multiple`: show a multiple select control.
 
 - **Default:** `undefined`
 

+ 14 - 9
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -165,7 +165,7 @@ const UtilsFilterControl = {
     return String(id).replace(/(:|\.|\[|\]|,)/g, '\\$1')
   },
   isColumnSearchableViaSelect ({ filterControl, searchable }) {
-    return filterControl && filterControl.toLowerCase() === 'select' && searchable
+    return filterControl && (filterControl.toLowerCase() === 'select' || filterControl.toLowerCase() === 'multiple') && searchable
   },
   isFilterDataNotGiven ({ filterData }) {
     return filterData === undefined || filterData.toLowerCase() === 'column'
@@ -225,26 +225,25 @@ const UtilsFilterControl = {
   createControls (that, header) {
     let addedFilterControl = false
     let isVisible
-    let html
+    let controls
 
     that.columns.forEach((column, i) => {
       isVisible = 'hidden'
-      html = []
 
       if (!column.visible) {
         return
       }
 
       if (!column.filterControl) {
-        html.push(createElem('div', ['class', 'no-filter-control']))
+        controls = createElem('div', ['class', 'no-filter-control'])
       } else {
-        html.push(createElem('div', ['class', 'filter-control']))
+        controls = createElem('div', ['class', 'filter-control'])
 
         const nameControl = column.filterControl.toLowerCase()
         if (column.searchable && that.options.filterTemplate[nameControl]) {
           addedFilterControl = true
           isVisible = 'visible'
-          html.push(
+          controls.appendChild(
             that.options.filterTemplate[nameControl](
               that,
               column.field,
@@ -261,9 +260,7 @@ const UtilsFilterControl = {
           const div = find(tr, '.fht-cell')
 
           if (div && div.length > 0) {
-            html.forEach((elem, i) => {
-              div[0].appendChild(elem)
-            })
+            div[0].appendChild(controls)
           }
 
           return false
@@ -459,6 +456,14 @@ Utils.extend($.fn.bootstrapTable.defaults, {
         ['visibility', isVisible],
         ['width', '100%'],
         ['dir', UtilsFilterControl.getDirectionOfSelectOptions(options.alignmentSelectControlOptions)])
+    },
+    multiple ({ options }, field, isVisible) {
+      return createElem('select',
+        ['class', Utils.sprintf('form-control bootstrap-table-filter-control-%s', field)],
+        ['visibility', isVisible],
+        ['width', '100%'],
+        ['multiple', 'multiple'],
+        ['dir', UtilsFilterControl.getDirectionOfSelectOptions(options.alignmentSelectControlOptions)])
     }
   },
   disableControlWhenSearch: false,