|
53 | 53 | if (that.options.searchFormTemplate) { |
54 | 54 | return Template(that.options.searchFormTemplate, {columns: pColumns, table: that}); |
55 | 55 | } |
| 56 | + var columnClass = typeof that.options.commonSearchColumnClass === 'undefined' ? 'col-xs-12 col-sm-6 col-md-4 col-lg-3' : that.options.commonSearchColumnClass; |
56 | 57 | var htmlForm = []; |
57 | 58 | htmlForm.push(sprintf('<form class="form-horizontal form-commonsearch" novalidate method="post" action="%s" >', that.options.actionForm)); |
58 | 59 | htmlForm.push('<fieldset>'); |
|
70 | 71 | vObjCol.operate = renderDefault && operate ? operate : (typeof vObjCol.operate === 'undefined' ? '=' : vObjCol.operate); |
71 | 72 | ColumnsForSearch.push(vObjCol); |
72 | 73 |
|
73 | | - htmlForm.push('<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'); |
| 74 | + htmlForm.push(sprintf('<div class="form-group %s %s">', columnClass, (typeof vObjCol.searchVisible === 'undefined' || vObjCol.searchVisible) ? '' : 'hidden')); |
74 | 75 | htmlForm.push(sprintf('<label for="%s" class="control-label col-xs-4">%s</label>', vObjCol.field, vObjCol.title)); |
75 | 76 | htmlForm.push('<div class="col-xs-8">'); |
76 | 77 |
|
|
86 | 87 | if (typeof vObjCol.searchList === 'function') { |
87 | 88 | htmlForm.push(vObjCol.searchList.call(this, vObjCol)); |
88 | 89 | } else { |
89 | | - var optionList = [sprintf('<option value="">%s</option>', that.options.formatCommonChoose())]; |
90 | | - if (typeof vObjCol.searchList === 'object' && typeof vObjCol.searchList.then === 'function') { |
91 | | - (function (vObjCol, that) { |
92 | | - $.when(vObjCol.searchList).done(function (ret) { |
93 | | - var searchList = []; |
94 | | - if (ret.data && ret.data.searchlist && $.isArray(ret.data.searchlist)) { |
95 | | - searchList = ret.data.searchlist; |
96 | | - } else if (ret.constructor === Array || ret.constructor === Object) { |
97 | | - searchList = ret; |
98 | | - } |
99 | | - var optionList = createOptionList(searchList, vObjCol, that); |
100 | | - $("form.form-commonsearch select[name='" + vObjCol.field + "']", that.$container).html(optionList.join('')).trigger("change"); |
101 | | - }); |
102 | | - })(vObjCol, that); |
103 | | - } else { |
104 | | - optionList = createOptionList(vObjCol.searchList, vObjCol, that); |
105 | | - } |
| 90 | + var optionList = createOptionList(vObjCol.searchList, vObjCol, that); |
106 | 91 | htmlForm.push(sprintf('<select class="%s" name="%s" %s %s>%s</select>', addClass, vObjCol.field, style, extend, optionList.join(''))); |
107 | 92 | } |
108 | 93 | } else { |
|
125 | 110 | htmlForm.push('</div>'); |
126 | 111 | } |
127 | 112 | } |
128 | | - htmlForm.push('<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">'); |
| 113 | + htmlForm.push('<div class="form-group ' + columnClass + '">'); |
129 | 114 | htmlForm.push(createFormBtn(that).join('')); |
130 | 115 | htmlForm.push('</div>'); |
131 | 116 | htmlForm.push('</div>'); |
|
147 | 132 | }; |
148 | 133 |
|
149 | 134 | var createOptionList = function (searchList, vObjCol, that) { |
150 | | - var isArray = searchList.constructor === Array; |
151 | 135 | var optionList = []; |
152 | 136 | optionList.push(sprintf('<option value="">%s</option>', that.options.formatCommonChoose())); |
| 137 | + searchList = $.fn.bootstrapTable.utils.combineSearchList(searchList); |
153 | 138 | $.each(searchList, function (key, value) { |
154 | | - if (value.constructor === Object) { |
155 | | - key = value.id; |
156 | | - value = value.name; |
157 | | - } else { |
158 | | - key = isArray ? value : key; |
159 | | - } |
160 | 139 | optionList.push(sprintf("<option value='" + Fast.api.escape(key) + "' %s>" + Fast.api.escape(value) + "</option>", key == vObjCol.defaultValue ? 'selected' : '')); |
161 | 140 | }); |
162 | 141 | return optionList; |
|
306 | 285 | _load = BootstrapTable.prototype.load, |
307 | 286 | _initSearch = BootstrapTable.prototype.initSearch; |
308 | 287 |
|
| 288 | + // 定义通用searchList处理方法 |
| 289 | + $.fn.bootstrapTable.utils.combineSearchList = function (list) { |
| 290 | + var searchList = {}; |
| 291 | + |
| 292 | + if (typeof list !== 'undefined') { |
| 293 | + var isFunction = list.constructor === Function; |
| 294 | + var isAjax = typeof list === 'object' && typeof list.then === 'function'; |
| 295 | + if (isFunction) { |
| 296 | + list = list(); |
| 297 | + } else if (isAjax) { |
| 298 | + $.when(list).done(function (ret) { |
| 299 | + // 兼容旧版本在data中返回searchlist |
| 300 | + if (typeof ret.data.searchlist !== 'undefined') { |
| 301 | + list = ret.data.searchlist; |
| 302 | + } else { |
| 303 | + list = ret; |
| 304 | + } |
| 305 | + }); |
| 306 | + } |
| 307 | + // 兼容旧版本searchList返回字符串直接渲染自定义搜索栏 |
| 308 | + if (typeof list === 'string') { |
| 309 | + return searchList; |
| 310 | + } |
| 311 | + var isArray = list.constructor === Array; |
| 312 | + var i = 0; |
| 313 | + $.each(list, function (key, val) { |
| 314 | + if (typeof val !== 'undefined' && val.constructor === Object) { |
| 315 | + key = val.id; |
| 316 | + val = val.name; |
| 317 | + } else { |
| 318 | + key = isArray ? val : key; |
| 319 | + } |
| 320 | + searchList[key] = val; |
| 321 | + }); |
| 322 | + } |
| 323 | + return searchList; |
| 324 | + }; |
309 | 325 | BootstrapTable.prototype.initHeader = function () { |
310 | 326 | _initHeader.apply(this, Array.prototype.slice.apply(arguments)); |
311 | 327 | this.$header.find('th[data-field]').each(function (i) { |
|
0 commit comments