corrade-nucleus-nucleons – Blame information for rev 24
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | /** |
2 | * @author zhixin wen <wenzhixin2010@gmail.com> |
||
3 | * version: 1.11.1 |
||
4 | * https://github.com/wenzhixin/bootstrap-table/ |
||
5 | */ |
||
6 | |||
7 | (function ($) { |
||
8 | 'use strict'; |
||
9 | |||
10 | // TOOLS DEFINITION |
||
11 | // ====================== |
||
12 | |||
13 | var cachedWidth = null; |
||
14 | |||
15 | // it only does '%s', and return '' when arguments are undefined |
||
16 | var sprintf = function (str) { |
||
17 | var args = arguments, |
||
18 | flag = true, |
||
19 | i = 1; |
||
20 | |||
21 | str = str.replace(/%s/g, function () { |
||
22 | var arg = args[i++]; |
||
23 | |||
24 | if (typeof arg === 'undefined') { |
||
25 | flag = false; |
||
26 | return ''; |
||
27 | } |
||
28 | return arg; |
||
29 | }); |
||
30 | return flag ? str : ''; |
||
31 | }; |
||
32 | |||
33 | var getPropertyFromOther = function (list, from, to, value) { |
||
34 | var result = ''; |
||
35 | $.each(list, function (i, item) { |
||
36 | if (item[from] === value) { |
||
37 | result = item[to]; |
||
38 | return false; |
||
39 | } |
||
40 | return true; |
||
41 | }); |
||
42 | return result; |
||
43 | }; |
||
44 | |||
45 | var getFieldIndex = function (columns, field) { |
||
46 | var index = -1; |
||
47 | |||
48 | $.each(columns, function (i, column) { |
||
49 | if (column.field === field) { |
||
50 | index = i; |
||
51 | return false; |
||
52 | } |
||
53 | return true; |
||
54 | }); |
||
55 | return index; |
||
56 | }; |
||
57 | |||
58 | // http://jsfiddle.net/wenyi/47nz7ez9/3/ |
||
59 | var setFieldIndex = function (columns) { |
||
60 | var i, j, k, |
||
61 | totalCol = 0, |
||
62 | flag = []; |
||
63 | |||
64 | for (i = 0; i < columns[0].length; i++) { |
||
65 | totalCol += columns[0][i].colspan || 1; |
||
66 | } |
||
67 | |||
68 | for (i = 0; i < columns.length; i++) { |
||
69 | flag[i] = []; |
||
70 | for (j = 0; j < totalCol; j++) { |
||
71 | flag[i][j] = false; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | for (i = 0; i < columns.length; i++) { |
||
76 | for (j = 0; j < columns[i].length; j++) { |
||
77 | var r = columns[i][j], |
||
78 | rowspan = r.rowspan || 1, |
||
79 | colspan = r.colspan || 1, |
||
80 | index = $.inArray(false, flag[i]); |
||
81 | |||
82 | if (colspan === 1) { |
||
83 | r.fieldIndex = index; |
||
84 | // when field is undefined, use index instead |
||
85 | if (typeof r.field === 'undefined') { |
||
86 | r.field = index; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | for (k = 0; k < rowspan; k++) { |
||
91 | flag[i + k][index] = true; |
||
92 | } |
||
93 | for (k = 0; k < colspan; k++) { |
||
94 | flag[i][index + k] = true; |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | }; |
||
99 | |||
100 | var getScrollBarWidth = function () { |
||
101 | if (cachedWidth === null) { |
||
102 | var inner = $('<p/>').addClass('fixed-table-scroll-inner'), |
||
103 | outer = $('<div/>').addClass('fixed-table-scroll-outer'), |
||
104 | w1, w2; |
||
105 | |||
106 | outer.append(inner); |
||
107 | $('body').append(outer); |
||
108 | |||
109 | w1 = inner[0].offsetWidth; |
||
110 | outer.css('overflow', 'scroll'); |
||
111 | w2 = inner[0].offsetWidth; |
||
112 | |||
113 | if (w1 === w2) { |
||
114 | w2 = outer[0].clientWidth; |
||
115 | } |
||
116 | |||
117 | outer.remove(); |
||
118 | cachedWidth = w1 - w2; |
||
119 | } |
||
120 | return cachedWidth; |
||
121 | }; |
||
122 | |||
123 | var calculateObjectValue = function (self, name, args, defaultValue) { |
||
124 | var func = name; |
||
125 | |||
126 | if (typeof name === 'string') { |
||
127 | // support obj.func1.func2 |
||
128 | var names = name.split('.'); |
||
129 | |||
130 | if (names.length > 1) { |
||
131 | func = window; |
||
132 | $.each(names, function (i, f) { |
||
133 | func = func[f]; |
||
134 | }); |
||
135 | } else { |
||
136 | func = window[name]; |
||
137 | } |
||
138 | } |
||
139 | if (typeof func === 'object') { |
||
140 | return func; |
||
141 | } |
||
142 | if (typeof func === 'function') { |
||
143 | return func.apply(self, args || []); |
||
144 | } |
||
145 | if (!func && typeof name === 'string' && sprintf.apply(this, [name].concat(args))) { |
||
146 | return sprintf.apply(this, [name].concat(args)); |
||
147 | } |
||
148 | return defaultValue; |
||
149 | }; |
||
150 | |||
151 | var compareObjects = function (objectA, objectB, compareLength) { |
||
152 | // Create arrays of property names |
||
153 | var objectAProperties = Object.getOwnPropertyNames(objectA), |
||
154 | objectBProperties = Object.getOwnPropertyNames(objectB), |
||
155 | propName = ''; |
||
156 | |||
157 | if (compareLength) { |
||
158 | // If number of properties is different, objects are not equivalent |
||
159 | if (objectAProperties.length !== objectBProperties.length) { |
||
160 | return false; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | for (var i = 0; i < objectAProperties.length; i++) { |
||
165 | propName = objectAProperties[i]; |
||
166 | |||
167 | // If the property is not in the object B properties, continue with the next property |
||
168 | if ($.inArray(propName, objectBProperties) > -1) { |
||
169 | // If values of same property are not equal, objects are not equivalent |
||
170 | if (objectA[propName] !== objectB[propName]) { |
||
171 | return false; |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | |||
176 | // If we made it this far, objects are considered equivalent |
||
177 | return true; |
||
178 | }; |
||
179 | |||
180 | var escapeHTML = function (text) { |
||
181 | if (typeof text === 'string') { |
||
182 | return text |
||
183 | .replace(/&/g, '&') |
||
184 | .replace(/g, '<') |
||
185 | .replace(/>/g, '>') |
||
186 | .replace(/"/g, '"') |
||
187 | .replace(/'/g, ''') |
||
188 | .replace(/`/g, '`'); |
||
189 | } |
||
190 | return text; |
||
191 | }; |
||
192 | |||
193 | var getRealDataAttr = function (dataAttr) { |
||
194 | for (var attr in dataAttr) { |
||
195 | var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase(); |
||
196 | if (auxAttr !== attr) { |
||
197 | dataAttr[auxAttr] = dataAttr[attr]; |
||
198 | delete dataAttr[attr]; |
||
199 | } |
||
200 | } |
||
201 | |||
202 | return dataAttr; |
||
203 | }; |
||
204 | |||
205 | var getItemField = function (item, field, escape) { |
||
206 | var value = item; |
||
207 | |||
208 | if (typeof field !== 'string' || item.hasOwnProperty(field)) { |
||
209 | return escape ? escapeHTML(item[field]) : item[field]; |
||
210 | } |
||
211 | var props = field.split('.'); |
||
212 | for (var p in props) { |
||
213 | if (props.hasOwnProperty(p)) { |
||
214 | value = value && value[props[p]]; |
||
215 | } |
||
216 | } |
||
217 | return escape ? escapeHTML(value) : value; |
||
218 | }; |
||
219 | |||
220 | var isIEBrowser = function () { |
||
221 | return !!(navigator.userAgent.indexOf("MSIE ") > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)); |
||
222 | }; |
||
223 | |||
224 | var objectKeys = function () { |
||
225 | // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys |
||
226 | if (!Object.keys) { |
||
227 | Object.keys = (function() { |
||
228 | var hasOwnProperty = Object.prototype.hasOwnProperty, |
||
229 | hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'), |
||
230 | dontEnums = [ |
||
231 | 'toString', |
||
232 | 'toLocaleString', |
||
233 | 'valueOf', |
||
234 | 'hasOwnProperty', |
||
235 | 'isPrototypeOf', |
||
236 | 'propertyIsEnumerable', |
||
237 | 'constructor' |
||
238 | ], |
||
239 | dontEnumsLength = dontEnums.length; |
||
240 | |||
241 | return function(obj) { |
||
242 | if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { |
||
243 | throw new TypeError('Object.keys called on non-object'); |
||
244 | } |
||
245 | |||
246 | var result = [], prop, i; |
||
247 | |||
248 | for (prop in obj) { |
||
249 | if (hasOwnProperty.call(obj, prop)) { |
||
250 | result.push(prop); |
||
251 | } |
||
252 | } |
||
253 | |||
254 | if (hasDontEnumBug) { |
||
255 | for (i = 0; i < dontEnumsLength; i++) { |
||
256 | if (hasOwnProperty.call(obj, dontEnums[i])) { |
||
257 | result.push(dontEnums[i]); |
||
258 | } |
||
259 | } |
||
260 | } |
||
261 | return result; |
||
262 | }; |
||
263 | }()); |
||
264 | } |
||
265 | }; |
||
266 | |||
267 | // BOOTSTRAP TABLE CLASS DEFINITION |
||
268 | // ====================== |
||
269 | |||
270 | var BootstrapTable = function (el, options) { |
||
271 | this.options = options; |
||
272 | this.$el = $(el); |
||
273 | this.$el_ = this.$el.clone(); |
||
274 | this.timeoutId_ = 0; |
||
275 | this.timeoutFooter_ = 0; |
||
276 | |||
277 | this.init(); |
||
278 | }; |
||
279 | |||
280 | BootstrapTable.DEFAULTS = { |
||
281 | classes: 'table table-hover', |
||
282 | sortClass: undefined, |
||
283 | locale: undefined, |
||
284 | height: undefined, |
||
285 | undefinedText: '-', |
||
286 | sortName: undefined, |
||
287 | sortOrder: 'asc', |
||
288 | sortStable: false, |
||
289 | striped: false, |
||
290 | columns: [[]], |
||
291 | data: [], |
||
292 | totalField: 'total', |
||
293 | dataField: 'rows', |
||
294 | method: 'get', |
||
295 | url: undefined, |
||
296 | ajax: undefined, |
||
297 | cache: true, |
||
298 | contentType: 'application/json', |
||
299 | dataType: 'json', |
||
300 | ajaxOptions: {}, |
||
301 | queryParams: function (params) { |
||
302 | return params; |
||
303 | }, |
||
304 | queryParamsType: 'limit', // undefined |
||
305 | responseHandler: function (res) { |
||
306 | return res; |
||
307 | }, |
||
308 | pagination: false, |
||
309 | onlyInfoPagination: false, |
||
310 | paginationLoop: true, |
||
311 | sidePagination: 'client', // client or server |
||
312 | totalRows: 0, // server side need to set |
||
313 | pageNumber: 1, |
||
314 | pageSize: 10, |
||
315 | pageList: [10, 25, 50, 100], |
||
316 | paginationHAlign: 'right', //right, left |
||
317 | paginationVAlign: 'bottom', //bottom, top, both |
||
318 | paginationDetailHAlign: 'left', //right, left |
||
319 | paginationPreText: '‹', |
||
320 | paginationNextText: '›', |
||
321 | search: false, |
||
322 | searchOnEnterKey: false, |
||
323 | strictSearch: false, |
||
324 | searchAlign: 'right', |
||
325 | selectItemName: 'btSelectItem', |
||
326 | showHeader: true, |
||
327 | showFooter: false, |
||
328 | showColumns: false, |
||
329 | showPaginationSwitch: false, |
||
330 | showRefresh: false, |
||
331 | showToggle: false, |
||
332 | buttonsAlign: 'right', |
||
333 | smartDisplay: true, |
||
334 | escape: false, |
||
335 | minimumCountColumns: 1, |
||
336 | idField: undefined, |
||
337 | uniqueId: undefined, |
||
338 | cardView: false, |
||
339 | detailView: false, |
||
340 | detailFormatter: function (index, row) { |
||
341 | return ''; |
||
342 | }, |
||
343 | trimOnSearch: true, |
||
344 | clickToSelect: false, |
||
345 | singleSelect: false, |
||
346 | toolbar: undefined, |
||
347 | toolbarAlign: 'left', |
||
348 | checkboxHeader: true, |
||
349 | sortable: true, |
||
350 | silentSort: true, |
||
351 | maintainSelected: false, |
||
352 | searchTimeOut: 500, |
||
353 | searchText: '', |
||
354 | iconSize: undefined, |
||
355 | buttonsClass: 'default', |
||
356 | iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome) |
||
357 | icons: { |
||
358 | paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down', |
||
359 | paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up', |
||
360 | refresh: 'glyphicon-refresh icon-refresh', |
||
361 | toggle: 'glyphicon-list-alt icon-list-alt', |
||
362 | columns: 'glyphicon-th icon-th', |
||
363 | detailOpen: 'glyphicon-plus icon-plus', |
||
364 | detailClose: 'glyphicon-minus icon-minus' |
||
365 | }, |
||
366 | |||
367 | customSearch: $.noop, |
||
368 | |||
369 | customSort: $.noop, |
||
370 | |||
371 | rowStyle: function (row, index) { |
||
372 | return {}; |
||
373 | }, |
||
374 | |||
375 | rowAttributes: function (row, index) { |
||
376 | return {}; |
||
377 | }, |
||
378 | |||
379 | footerStyle: function (row, index) { |
||
380 | return {}; |
||
381 | }, |
||
382 | |||
383 | onAll: function (name, args) { |
||
384 | return false; |
||
385 | }, |
||
386 | onClickCell: function (field, value, row, $element) { |
||
387 | return false; |
||
388 | }, |
||
389 | onDblClickCell: function (field, value, row, $element) { |
||
390 | return false; |
||
391 | }, |
||
392 | onClickRow: function (item, $element) { |
||
393 | return false; |
||
394 | }, |
||
395 | onDblClickRow: function (item, $element) { |
||
396 | return false; |
||
397 | }, |
||
398 | onSort: function (name, order) { |
||
399 | return false; |
||
400 | }, |
||
401 | onCheck: function (row) { |
||
402 | return false; |
||
403 | }, |
||
404 | onUncheck: function (row) { |
||
405 | return false; |
||
406 | }, |
||
407 | onCheckAll: function (rows) { |
||
408 | return false; |
||
409 | }, |
||
410 | onUncheckAll: function (rows) { |
||
411 | return false; |
||
412 | }, |
||
413 | onCheckSome: function (rows) { |
||
414 | return false; |
||
415 | }, |
||
416 | onUncheckSome: function (rows) { |
||
417 | return false; |
||
418 | }, |
||
419 | onLoadSuccess: function (data) { |
||
420 | return false; |
||
421 | }, |
||
422 | onLoadError: function (status) { |
||
423 | return false; |
||
424 | }, |
||
425 | onColumnSwitch: function (field, checked) { |
||
426 | return false; |
||
427 | }, |
||
428 | onPageChange: function (number, size) { |
||
429 | return false; |
||
430 | }, |
||
431 | onSearch: function (text) { |
||
432 | return false; |
||
433 | }, |
||
434 | onToggle: function (cardView) { |
||
435 | return false; |
||
436 | }, |
||
437 | onPreBody: function (data) { |
||
438 | return false; |
||
439 | }, |
||
440 | onPostBody: function () { |
||
441 | return false; |
||
442 | }, |
||
443 | onPostHeader: function () { |
||
444 | return false; |
||
445 | }, |
||
446 | onExpandRow: function (index, row, $detail) { |
||
447 | return false; |
||
448 | }, |
||
449 | onCollapseRow: function (index, row) { |
||
450 | return false; |
||
451 | }, |
||
452 | onRefreshOptions: function (options) { |
||
453 | return false; |
||
454 | }, |
||
455 | onRefresh: function (params) { |
||
456 | return false; |
||
457 | }, |
||
458 | onResetView: function () { |
||
459 | return false; |
||
460 | } |
||
461 | }; |
||
462 | |||
463 | BootstrapTable.LOCALES = {}; |
||
464 | |||
465 | BootstrapTable.LOCALES['en-US'] = BootstrapTable.LOCALES.en = { |
||
466 | formatLoadingMessage: function () { |
||
467 | return 'Loading, please wait...'; |
||
468 | }, |
||
469 | formatRecordsPerPage: function (pageNumber) { |
||
470 | return sprintf('%s rows per page', pageNumber); |
||
471 | }, |
||
472 | formatShowingRows: function (pageFrom, pageTo, totalRows) { |
||
473 | return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows); |
||
474 | }, |
||
475 | formatDetailPagination: function (totalRows) { |
||
476 | return sprintf('Showing %s rows', totalRows); |
||
477 | }, |
||
478 | formatSearch: function () { |
||
479 | return 'Search'; |
||
480 | }, |
||
481 | formatNoMatches: function () { |
||
482 | return 'No matching records found'; |
||
483 | }, |
||
484 | formatPaginationSwitch: function () { |
||
485 | return 'Hide/Show pagination'; |
||
486 | }, |
||
487 | formatRefresh: function () { |
||
488 | return 'Refresh'; |
||
489 | }, |
||
490 | formatToggle: function () { |
||
491 | return 'Toggle'; |
||
492 | }, |
||
493 | formatColumns: function () { |
||
494 | return 'Columns'; |
||
495 | }, |
||
496 | formatAllRows: function () { |
||
497 | return 'All'; |
||
498 | } |
||
499 | }; |
||
500 | |||
501 | $.extend(BootstrapTable.DEFAULTS, BootstrapTable.LOCALES['en-US']); |
||
502 | |||
503 | BootstrapTable.COLUMN_DEFAULTS = { |
||
504 | radio: false, |
||
505 | checkbox: false, |
||
506 | checkboxEnabled: true, |
||
507 | field: undefined, |
||
508 | title: undefined, |
||
509 | titleTooltip: undefined, |
||
510 | 'class': undefined, |
||
511 | align: undefined, // left, right, center |
||
512 | halign: undefined, // left, right, center |
||
513 | falign: undefined, // left, right, center |
||
514 | valign: undefined, // top, middle, bottom |
||
515 | width: undefined, |
||
516 | sortable: false, |
||
517 | order: 'asc', // asc, desc |
||
518 | visible: true, |
||
519 | switchable: true, |
||
520 | clickToSelect: true, |
||
521 | formatter: undefined, |
||
522 | footerFormatter: undefined, |
||
523 | events: undefined, |
||
524 | sorter: undefined, |
||
525 | sortName: undefined, |
||
526 | cellStyle: undefined, |
||
527 | searchable: true, |
||
528 | searchFormatter: true, |
||
529 | cardVisible: true, |
||
530 | escape : false |
||
531 | }; |
||
532 | |||
533 | BootstrapTable.EVENTS = { |
||
534 | 'all.bs.table': 'onAll', |
||
535 | 'click-cell.bs.table': 'onClickCell', |
||
536 | 'dbl-click-cell.bs.table': 'onDblClickCell', |
||
537 | 'click-row.bs.table': 'onClickRow', |
||
538 | 'dbl-click-row.bs.table': 'onDblClickRow', |
||
539 | 'sort.bs.table': 'onSort', |
||
540 | 'check.bs.table': 'onCheck', |
||
541 | 'uncheck.bs.table': 'onUncheck', |
||
542 | 'check-all.bs.table': 'onCheckAll', |
||
543 | 'uncheck-all.bs.table': 'onUncheckAll', |
||
544 | 'check-some.bs.table': 'onCheckSome', |
||
545 | 'uncheck-some.bs.table': 'onUncheckSome', |
||
546 | 'load-success.bs.table': 'onLoadSuccess', |
||
547 | 'load-error.bs.table': 'onLoadError', |
||
548 | 'column-switch.bs.table': 'onColumnSwitch', |
||
549 | 'page-change.bs.table': 'onPageChange', |
||
550 | 'search.bs.table': 'onSearch', |
||
551 | 'toggle.bs.table': 'onToggle', |
||
552 | 'pre-body.bs.table': 'onPreBody', |
||
553 | 'post-body.bs.table': 'onPostBody', |
||
554 | 'post-header.bs.table': 'onPostHeader', |
||
555 | 'expand-row.bs.table': 'onExpandRow', |
||
556 | 'collapse-row.bs.table': 'onCollapseRow', |
||
557 | 'refresh-options.bs.table': 'onRefreshOptions', |
||
558 | 'reset-view.bs.table': 'onResetView', |
||
559 | 'refresh.bs.table': 'onRefresh' |
||
560 | }; |
||
561 | |||
562 | BootstrapTable.prototype.init = function () { |
||
563 | this.initLocale(); |
||
564 | this.initContainer(); |
||
565 | this.initTable(); |
||
566 | this.initHeader(); |
||
567 | this.initData(); |
||
568 | this.initHiddenRows(); |
||
569 | this.initFooter(); |
||
570 | this.initToolbar(); |
||
571 | this.initPagination(); |
||
572 | this.initBody(); |
||
573 | this.initSearchText(); |
||
574 | this.initServer(); |
||
575 | }; |
||
576 | |||
577 | BootstrapTable.prototype.initLocale = function () { |
||
578 | if (this.options.locale) { |
||
579 | var parts = this.options.locale.split(/-|_/); |
||
580 | parts[0].toLowerCase(); |
||
581 | if (parts[1]) parts[1].toUpperCase(); |
||
582 | if ($.fn.bootstrapTable.locales[this.options.locale]) { |
||
583 | // locale as requested |
||
584 | $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]); |
||
585 | } else if ($.fn.bootstrapTable.locales[parts.join('-')]) { |
||
586 | // locale with sep set to - (in case original was specified with _) |
||
587 | $.extend(this.options, $.fn.bootstrapTable.locales[parts.join('-')]); |
||
588 | } else if ($.fn.bootstrapTable.locales[parts[0]]) { |
||
589 | // short locale language code (i.e. 'en') |
||
590 | $.extend(this.options, $.fn.bootstrapTable.locales[parts[0]]); |
||
591 | } |
||
592 | } |
||
593 | }; |
||
594 | |||
595 | BootstrapTable.prototype.initContainer = function () { |
||
596 | this.$container = $([ |
||
597 | '<div class="bootstrap-table">', |
||
598 | '<div class="fixed-table-toolbar"></div>', |
||
599 | this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ? |
||
600 | '<div class="fixed-table-pagination" style="clear: both;"></div>' : |
||
601 | '', |
||
602 | '<div class="fixed-table-container">', |
||
603 | '<div class="fixed-table-header"><table></table></div>', |
||
604 | '<div class="fixed-table-body">', |
||
605 | '<div class="fixed-table-loading">', |
||
606 | this.options.formatLoadingMessage(), |
||
607 | '</div>', |
||
608 | '</div>', |
||
609 | '<div class="fixed-table-footer"><table><tr></tr></table></div>', |
||
610 | this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ? |
||
611 | '<div class="fixed-table-pagination"></div>' : |
||
612 | '', |
||
613 | '</div>', |
||
614 | '</div>' |
||
615 | ].join('')); |
||
616 | |||
617 | this.$container.insertAfter(this.$el); |
||
618 | this.$tableContainer = this.$container.find('.fixed-table-container'); |
||
619 | this.$tableHeader = this.$container.find('.fixed-table-header'); |
||
620 | this.$tableBody = this.$container.find('.fixed-table-body'); |
||
621 | this.$tableLoading = this.$container.find('.fixed-table-loading'); |
||
622 | this.$tableFooter = this.$container.find('.fixed-table-footer'); |
||
623 | this.$toolbar = this.$container.find('.fixed-table-toolbar'); |
||
624 | this.$pagination = this.$container.find('.fixed-table-pagination'); |
||
625 | |||
626 | this.$tableBody.append(this.$el); |
||
627 | this.$container.after('<div class="clearfix"></div>'); |
||
628 | |||
629 | this.$el.addClass(this.options.classes); |
||
630 | if (this.options.striped) { |
||
631 | this.$el.addClass('table-striped'); |
||
632 | } |
||
633 | if ($.inArray('table-no-bordered', this.options.classes.split(' ')) !== -1) { |
||
634 | this.$tableContainer.addClass('table-no-bordered'); |
||
635 | } |
||
636 | }; |
||
637 | |||
638 | BootstrapTable.prototype.initTable = function () { |
||
639 | var that = this, |
||
640 | columns = [], |
||
641 | data = []; |
||
642 | |||
643 | this.$header = this.$el.find('>thead'); |
||
644 | if (!this.$header.length) { |
||
645 | this.$header = $('<thead></thead>').appendTo(this.$el); |
||
646 | } |
||
647 | this.$header.find('tr').each(function () { |
||
648 | var column = []; |
||
649 | |||
650 | $(this).find('th').each(function () { |
||
651 | // Fix #2014 - getFieldIndex and elsewhere assume this is string, causes issues if not |
||
652 | if (typeof $(this).data('field') !== 'undefined') { |
||
653 | $(this).data('field', $(this).data('field') + ''); |
||
654 | } |
||
655 | column.push($.extend({}, { |
||
656 | title: $(this).html(), |
||
657 | 'class': $(this).attr('class'), |
||
658 | titleTooltip: $(this).attr('title'), |
||
659 | rowspan: $(this).attr('rowspan') ? +$(this).attr('rowspan') : undefined, |
||
660 | colspan: $(this).attr('colspan') ? +$(this).attr('colspan') : undefined |
||
661 | }, $(this).data())); |
||
662 | }); |
||
663 | columns.push(column); |
||
664 | }); |
||
665 | if (!$.isArray(this.options.columns[0])) { |
||
666 | this.options.columns = [this.options.columns]; |
||
667 | } |
||
668 | this.options.columns = $.extend(true, [], columns, this.options.columns); |
||
669 | this.columns = []; |
||
670 | |||
671 | setFieldIndex(this.options.columns); |
||
672 | $.each(this.options.columns, function (i, columns) { |
||
673 | $.each(columns, function (j, column) { |
||
674 | column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, column); |
||
675 | |||
676 | if (typeof column.fieldIndex !== 'undefined') { |
||
677 | that.columns[column.fieldIndex] = column; |
||
678 | } |
||
679 | |||
680 | that.options.columns[i][j] = column; |
||
681 | }); |
||
682 | }); |
||
683 | |||
684 | // if options.data is setting, do not process tbody data |
||
685 | if (this.options.data.length) { |
||
686 | return; |
||
687 | } |
||
688 | |||
689 | var m = []; |
||
690 | this.$el.find('>tbody>tr').each(function (y) { |
||
691 | var row = {}; |
||
692 | |||
693 | // save tr's id, class and data-* attributes |
||
694 | row._id = $(this).attr('id'); |
||
695 | row._class = $(this).attr('class'); |
||
696 | row._data = getRealDataAttr($(this).data()); |
||
697 | |||
698 | $(this).find('>td').each(function (x) { |
||
699 | var $this = $(this), |
||
700 | cspan = +$this.attr('colspan') || 1, |
||
701 | rspan = +$this.attr('rowspan') || 1, |
||
702 | tx, ty; |
||
703 | |||
704 | for (; m[y] && m[y][x]; x++); //skip already occupied cells in current row |
||
705 | |||
706 | for (tx = x; tx < x + cspan; tx++) { //mark matrix elements occupied by current cell with true |
||
707 | for (ty = y; ty < y + rspan; ty++) { |
||
708 | if (!m[ty]) { //fill missing rows |
||
709 | m[ty] = []; |
||
710 | } |
||
711 | m[ty][tx] = true; |
||
712 | } |
||
713 | } |
||
714 | |||
715 | var field = that.columns[x].field; |
||
716 | |||
717 | row[field] = $(this).html(); |
||
718 | // save td's id, class and data-* attributes |
||
719 | row['_' + field + '_id'] = $(this).attr('id'); |
||
720 | row['_' + field + '_class'] = $(this).attr('class'); |
||
721 | row['_' + field + '_rowspan'] = $(this).attr('rowspan'); |
||
722 | row['_' + field + '_colspan'] = $(this).attr('colspan'); |
||
723 | row['_' + field + '_title'] = $(this).attr('title'); |
||
724 | row['_' + field + '_data'] = getRealDataAttr($(this).data()); |
||
725 | }); |
||
726 | data.push(row); |
||
727 | }); |
||
728 | this.options.data = data; |
||
729 | if (data.length) this.fromHtml = true; |
||
730 | }; |
||
731 | |||
732 | BootstrapTable.prototype.initHeader = function () { |
||
733 | var that = this, |
||
734 | visibleColumns = {}, |
||
735 | html = []; |
||
736 | |||
737 | this.header = { |
||
738 | fields: [], |
||
739 | styles: [], |
||
740 | classes: [], |
||
741 | formatters: [], |
||
742 | events: [], |
||
743 | sorters: [], |
||
744 | sortNames: [], |
||
745 | cellStyles: [], |
||
746 | searchables: [] |
||
747 | }; |
||
748 | |||
749 | $.each(this.options.columns, function (i, columns) { |
||
750 | html.push('<tr>'); |
||
751 | |||
752 | if (i === 0 && !that.options.cardView && that.options.detailView) { |
||
753 | html.push(sprintf('<th class="detail" rowspan="%s"><div class="fht-cell"></div></th>', |
||
754 | that.options.columns.length)); |
||
755 | } |
||
756 | |||
757 | $.each(columns, function (j, column) { |
||
758 | var text = '', |
||
759 | halign = '', // header align style |
||
760 | align = '', // body align style |
||
761 | style = '', |
||
762 | class_ = sprintf(' class="%s"', column['class']), |
||
763 | order = that.options.sortOrder || column.order, |
||
764 | unitWidth = 'px', |
||
765 | width = column.width; |
||
766 | |||
767 | if (column.width !== undefined && (!that.options.cardView)) { |
||
768 | if (typeof column.width === 'string') { |
||
769 | if (column.width.indexOf('%') !== -1) { |
||
770 | unitWidth = '%'; |
||
771 | } |
||
772 | } |
||
773 | } |
||
774 | if (column.width && typeof column.width === 'string') { |
||
775 | width = column.width.replace('%', '').replace('px', ''); |
||
776 | } |
||
777 | |||
778 | halign = sprintf('text-align: %s; ', column.halign ? column.halign : column.align); |
||
779 | align = sprintf('text-align: %s; ', column.align); |
||
780 | style = sprintf('vertical-align: %s; ', column.valign); |
||
781 | style += sprintf('width: %s; ', (column.checkbox || column.radio) && !width ? |
||
782 | '36px' : (width ? width + unitWidth : undefined)); |
||
783 | |||
784 | if (typeof column.fieldIndex !== 'undefined') { |
||
785 | that.header.fields[column.fieldIndex] = column.field; |
||
786 | that.header.styles[column.fieldIndex] = align + style; |
||
787 | that.header.classes[column.fieldIndex] = class_; |
||
788 | that.header.formatters[column.fieldIndex] = column.formatter; |
||
789 | that.header.events[column.fieldIndex] = column.events; |
||
790 | that.header.sorters[column.fieldIndex] = column.sorter; |
||
791 | that.header.sortNames[column.fieldIndex] = column.sortName; |
||
792 | that.header.cellStyles[column.fieldIndex] = column.cellStyle; |
||
793 | that.header.searchables[column.fieldIndex] = column.searchable; |
||
794 | |||
795 | if (!column.visible) { |
||
796 | return; |
||
797 | } |
||
798 | |||
799 | if (that.options.cardView && (!column.cardVisible)) { |
||
800 | return; |
||
801 | } |
||
802 | |||
803 | visibleColumns[column.field] = column; |
||
804 | } |
||
805 | |||
806 | html.push('<th' + sprintf(' title="%s"', column.titleTooltip), |
||
807 | column.checkbox || column.radio ? |
||
808 | sprintf(' class="bs-checkbox %s"', column['class'] || '') : |
||
809 | class_, |
||
810 | sprintf(' style="%s"', halign + style), |
||
811 | sprintf(' rowspan="%s"', column.rowspan), |
||
812 | sprintf(' colspan="%s"', column.colspan), |
||
813 | sprintf(' data-field="%s"', column.field), |
||
814 | '>'); |
||
815 | |||
816 | html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ? |
||
817 | 'sortable both' : '')); |
||
818 | |||
819 | text = that.options.escape ? escapeHTML(column.title) : column.title; |
||
820 | |||
821 | if (column.checkbox) { |
||
822 | if (!that.options.singleSelect && that.options.checkboxHeader) { |
||
823 | text = '<input name="btSelectAll" type="checkbox" />'; |
||
824 | } |
||
825 | that.header.stateField = column.field; |
||
826 | } |
||
827 | if (column.radio) { |
||
828 | text = ''; |
||
829 | that.header.stateField = column.field; |
||
830 | that.options.singleSelect = true; |
||
831 | } |
||
832 | |||
833 | html.push(text); |
||
834 | html.push('</div>'); |
||
835 | html.push('<div class="fht-cell"></div>'); |
||
836 | html.push('</div>'); |
||
837 | html.push('</th>'); |
||
838 | }); |
||
839 | html.push('</tr>'); |
||
840 | }); |
||
841 | |||
842 | this.$header.html(html.join('')); |
||
843 | this.$header.find('th[data-field]').each(function (i) { |
||
844 | $(this).data(visibleColumns[$(this).data('field')]); |
||
845 | }); |
||
846 | this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) { |
||
847 | var target = $(this); |
||
848 | |||
849 | if (that.options.detailView) { |
||
850 | if (target.closest('.bootstrap-table')[0] !== that.$container[0]) |
||
851 | return false; |
||
852 | } |
||
853 | |||
854 | if (that.options.sortable && target.parent().data().sortable) { |
||
855 | that.onSort(event); |
||
856 | } |
||
857 | }); |
||
858 | |||
859 | this.$header.children().children().off('keypress').on('keypress', function (event) { |
||
860 | if (that.options.sortable && $(this).data().sortable) { |
||
861 | var code = event.keyCode || event.which; |
||
862 | if (code == 13) { //Enter keycode |
||
863 | that.onSort(event); |
||
864 | } |
||
865 | } |
||
866 | }); |
||
867 | |||
868 | $(window).off('resize.bootstrap-table'); |
||
869 | if (!this.options.showHeader || this.options.cardView) { |
||
870 | this.$header.hide(); |
||
871 | this.$tableHeader.hide(); |
||
872 | this.$tableLoading.css('top', 0); |
||
873 | } else { |
||
874 | this.$header.show(); |
||
875 | this.$tableHeader.show(); |
||
876 | this.$tableLoading.css('top', this.$header.outerHeight() + 1); |
||
877 | // Assign the correct sortable arrow |
||
878 | this.getCaret(); |
||
879 | $(window).on('resize.bootstrap-table', $.proxy(this.resetWidth, this)); |
||
880 | } |
||
881 | |||
882 | this.$selectAll = this.$header.find('[name="btSelectAll"]'); |
||
883 | this.$selectAll.off('click').on('click', function () { |
||
884 | var checked = $(this).prop('checked'); |
||
885 | that[checked ? 'checkAll' : 'uncheckAll'](); |
||
886 | that.updateSelected(); |
||
887 | }); |
||
888 | }; |
||
889 | |||
890 | BootstrapTable.prototype.initFooter = function () { |
||
891 | if (!this.options.showFooter || this.options.cardView) { |
||
892 | this.$tableFooter.hide(); |
||
893 | } else { |
||
894 | this.$tableFooter.show(); |
||
895 | } |
||
896 | }; |
||
897 | |||
898 | /** |
||
899 | * @param data |
||
900 | * @param type: append / prepend |
||
901 | */ |
||
902 | BootstrapTable.prototype.initData = function (data, type) { |
||
903 | if (type === 'append') { |
||
904 | this.data = this.data.concat(data); |
||
905 | } else if (type === 'prepend') { |
||
906 | this.data = [].concat(data).concat(this.data); |
||
907 | } else { |
||
908 | this.data = data || this.options.data; |
||
909 | } |
||
910 | |||
911 | // Fix #839 Records deleted when adding new row on filtered table |
||
912 | if (type === 'append') { |
||
913 | this.options.data = this.options.data.concat(data); |
||
914 | } else if (type === 'prepend') { |
||
915 | this.options.data = [].concat(data).concat(this.options.data); |
||
916 | } else { |
||
917 | this.options.data = this.data; |
||
918 | } |
||
919 | |||
920 | if (this.options.sidePagination === 'server') { |
||
921 | return; |
||
922 | } |
||
923 | this.initSort(); |
||
924 | }; |
||
925 | |||
926 | BootstrapTable.prototype.initSort = function () { |
||
927 | var that = this, |
||
928 | name = this.options.sortName, |
||
929 | order = this.options.sortOrder === 'desc' ? -1 : 1, |
||
930 | index = $.inArray(this.options.sortName, this.header.fields), |
||
931 | timeoutId = 0; |
||
932 | |||
933 | if (this.options.customSort !== $.noop) { |
||
934 | this.options.customSort.apply(this, [this.options.sortName, this.options.sortOrder]); |
||
935 | return; |
||
936 | } |
||
937 | |||
938 | if (index !== -1) { |
||
939 | if (this.options.sortStable) { |
||
940 | $.each(this.data, function (i, row) { |
||
941 | if (!row.hasOwnProperty('_position')) row._position = i; |
||
942 | }); |
||
943 | } |
||
944 | |||
945 | this.data.sort(function (a, b) { |
||
946 | if (that.header.sortNames[index]) { |
||
947 | name = that.header.sortNames[index]; |
||
948 | } |
||
949 | var aa = getItemField(a, name, that.options.escape), |
||
950 | bb = getItemField(b, name, that.options.escape), |
||
951 | value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]); |
||
952 | |||
953 | if (value !== undefined) { |
||
954 | return order * value; |
||
955 | } |
||
956 | |||
957 | // Fix #161: undefined or null string sort bug. |
||
958 | if (aa === undefined || aa === null) { |
||
959 | aa = ''; |
||
960 | } |
||
961 | if (bb === undefined || bb === null) { |
||
962 | bb = ''; |
||
963 | } |
||
964 | |||
965 | if (that.options.sortStable && aa === bb) { |
||
966 | aa = a._position; |
||
967 | bb = b._position; |
||
968 | } |
||
969 | |||
970 | // IF both values are numeric, do a numeric comparison |
||
971 | if ($.isNumeric(aa) && $.isNumeric(bb)) { |
||
972 | // Convert numerical values form string to float. |
||
973 | aa = parseFloat(aa); |
||
974 | bb = parseFloat(bb); |
||
975 | if (aa < bb) { |
||
976 | return order * -1; |
||
977 | } |
||
978 | return order; |
||
979 | } |
||
980 | |||
981 | if (aa === bb) { |
||
982 | return 0; |
||
983 | } |
||
984 | |||
985 | // If value is not a string, convert to string |
||
986 | if (typeof aa !== 'string') { |
||
987 | aa = aa.toString(); |
||
988 | } |
||
989 | |||
990 | if (aa.localeCompare(bb) === -1) { |
||
991 | return order * -1; |
||
992 | } |
||
993 | |||
994 | return order; |
||
995 | }); |
||
996 | |||
997 | if (this.options.sortClass !== undefined) { |
||
998 | clearTimeout(timeoutId); |
||
999 | timeoutId = setTimeout(function () { |
||
1000 | that.$el.removeClass(that.options.sortClass); |
||
1001 | var index = that.$header.find(sprintf('[data-field="%s"]', |
||
1002 | that.options.sortName).index() + 1); |
||
1003 | that.$el.find(sprintf('tr td:nth-child(%s)', index)) |
||
1004 | .addClass(that.options.sortClass); |
||
1005 | }, 250); |
||
1006 | } |
||
1007 | } |
||
1008 | }; |
||
1009 | |||
1010 | BootstrapTable.prototype.onSort = function (event) { |
||
1011 | var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(), |
||
1012 | $this_ = this.$header.find('th').eq($this.index()); |
||
1013 | |||
1014 | this.$header.add(this.$header_).find('span.order').remove(); |
||
1015 | |||
1016 | if (this.options.sortName === $this.data('field')) { |
||
1017 | this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc'; |
||
1018 | } else { |
||
1019 | this.options.sortName = $this.data('field'); |
||
1020 | this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc'; |
||
1021 | } |
||
1022 | this.trigger('sort', this.options.sortName, this.options.sortOrder); |
||
1023 | |||
1024 | $this.add($this_).data('order', this.options.sortOrder); |
||
1025 | |||
1026 | // Assign the correct sortable arrow |
||
1027 | this.getCaret(); |
||
1028 | |||
1029 | if (this.options.sidePagination === 'server') { |
||
1030 | this.initServer(this.options.silentSort); |
||
1031 | return; |
||
1032 | } |
||
1033 | |||
1034 | this.initSort(); |
||
1035 | this.initBody(); |
||
1036 | }; |
||
1037 | |||
1038 | BootstrapTable.prototype.initToolbar = function () { |
||
1039 | var that = this, |
||
1040 | html = [], |
||
1041 | timeoutId = 0, |
||
1042 | $keepOpen, |
||
1043 | $search, |
||
1044 | switchableCount = 0; |
||
1045 | |||
1046 | if (this.$toolbar.find('.bs-bars').children().length) { |
||
1047 | $('body').append($(this.options.toolbar)); |
||
1048 | } |
||
1049 | this.$toolbar.html(''); |
||
1050 | |||
1051 | if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') { |
||
1052 | $(sprintf('<div class="bs-bars pull-%s"></div>', this.options.toolbarAlign)) |
||
1053 | .appendTo(this.$toolbar) |
||
1054 | .append($(this.options.toolbar)); |
||
1055 | } |
||
1056 | |||
1057 | // showColumns, showToggle, showRefresh |
||
1058 | html = [sprintf('<div class="columns columns-%s btn-group pull-%s">', |
||
1059 | this.options.buttonsAlign, this.options.buttonsAlign)]; |
||
1060 | |||
1061 | if (typeof this.options.icons === 'string') { |
||
1062 | this.options.icons = calculateObjectValue(null, this.options.icons); |
||
1063 | } |
||
1064 | |||
1065 | if (this.options.showPaginationSwitch) { |
||
1066 | html.push(sprintf('<button class="btn' + |
||
1067 | sprintf(' btn-%s', this.options.buttonsClass) + |
||
1068 | sprintf(' btn-%s', this.options.iconSize) + |
||
1069 | '" type="button" name="paginationSwitch" aria-label="pagination Switch" title="%s">', |
||
1070 | this.options.formatPaginationSwitch()), |
||
1071 | sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown), |
||
1072 | '</button>'); |
||
1073 | } |
||
1074 | |||
1075 | if (this.options.showRefresh) { |
||
1076 | html.push(sprintf('<button class="btn' + |
||
1077 | sprintf(' btn-%s', this.options.buttonsClass) + |
||
1078 | sprintf(' btn-%s', this.options.iconSize) + |
||
1079 | '" type="button" name="refresh" aria-label="refresh" title="%s">', |
||
1080 | this.options.formatRefresh()), |
||
1081 | sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh), |
||
1082 | '</button>'); |
||
1083 | } |
||
1084 | |||
1085 | if (this.options.showToggle) { |
||
1086 | html.push(sprintf('<button class="btn' + |
||
1087 | sprintf(' btn-%s', this.options.buttonsClass) + |
||
1088 | sprintf(' btn-%s', this.options.iconSize) + |
||
1089 | '" type="button" name="toggle" aria-label="toggle" title="%s">', |
||
1090 | this.options.formatToggle()), |
||
1091 | sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle), |
||
1092 | '</button>'); |
||
1093 | } |
||
1094 | |||
1095 | if (this.options.showColumns) { |
||
1096 | html.push(sprintf('<div class="keep-open btn-group" title="%s">', |
||
1097 | this.options.formatColumns()), |
||
1098 | '<button type="button" aria-label="columns" class="btn' + |
||
1099 | sprintf(' btn-%s', this.options.buttonsClass) + |
||
1100 | sprintf(' btn-%s', this.options.iconSize) + |
||
1101 | ' dropdown-toggle" data-toggle="dropdown">', |
||
1102 | sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns), |
||
1103 | ' <span class="caret"></span>', |
||
1104 | '</button>', |
||
1105 | '<ul class="dropdown-menu" role="menu">'); |
||
1106 | |||
1107 | $.each(this.columns, function (i, column) { |
||
1108 | if (column.radio || column.checkbox) { |
||
1109 | return; |
||
1110 | } |
||
1111 | |||
1112 | if (that.options.cardView && !column.cardVisible) { |
||
1113 | return; |
||
1114 | } |
||
1115 | |||
1116 | var checked = column.visible ? ' checked="checked"' : ''; |
||
1117 | |||
1118 | if (column.switchable) { |
||
1119 | html.push(sprintf('<li role="menuitem">' + |
||
1120 | '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' + |
||
1121 | '</li>', column.field, i, checked, column.title)); |
||
1122 | switchableCount++; |
||
1123 | } |
||
1124 | }); |
||
1125 | html.push('</ul>', |
||
1126 | '</div>'); |
||
1127 | } |
||
1128 | |||
1129 | html.push('</div>'); |
||
1130 | |||
1131 | // Fix #188: this.showToolbar is for extensions |
||
1132 | if (this.showToolbar || html.length > 2) { |
||
1133 | this.$toolbar.append(html.join('')); |
||
1134 | } |
||
1135 | |||
1136 | if (this.options.showPaginationSwitch) { |
||
1137 | this.$toolbar.find('button[name="paginationSwitch"]') |
||
1138 | .off('click').on('click', $.proxy(this.togglePagination, this)); |
||
1139 | } |
||
1140 | |||
1141 | if (this.options.showRefresh) { |
||
1142 | this.$toolbar.find('button[name="refresh"]') |
||
1143 | .off('click').on('click', $.proxy(this.refresh, this)); |
||
1144 | } |
||
1145 | |||
1146 | if (this.options.showToggle) { |
||
1147 | this.$toolbar.find('button[name="toggle"]') |
||
1148 | .off('click').on('click', function () { |
||
1149 | that.toggleView(); |
||
1150 | }); |
||
1151 | } |
||
1152 | |||
1153 | if (this.options.showColumns) { |
||
1154 | $keepOpen = this.$toolbar.find('.keep-open'); |
||
1155 | |||
1156 | if (switchableCount <= this.options.minimumCountColumns) { |
||
1157 | $keepOpen.find('input').prop('disabled', true); |
||
1158 | } |
||
1159 | |||
1160 | $keepOpen.find('li').off('click').on('click', function (event) { |
||
1161 | event.stopImmediatePropagation(); |
||
1162 | }); |
||
1163 | $keepOpen.find('input').off('click').on('click', function () { |
||
1164 | var $this = $(this); |
||
1165 | |||
1166 | that.toggleColumn($(this).val(), $this.prop('checked'), false); |
||
1167 | that.trigger('column-switch', $(this).data('field'), $this.prop('checked')); |
||
1168 | }); |
||
1169 | } |
||
1170 | |||
1171 | if (this.options.search) { |
||
1172 | html = []; |
||
1173 | html.push( |
||
1174 | '<div class="pull-' + this.options.searchAlign + ' search">', |
||
1175 | sprintf('<input class="form-control' + |
||
1176 | sprintf(' input-%s', this.options.iconSize) + |
||
1177 | '" type="text" placeholder="%s">', |
||
1178 | this.options.formatSearch()), |
||
1179 | '</div>'); |
||
1180 | |||
1181 | this.$toolbar.append(html.join('')); |
||
1182 | $search = this.$toolbar.find('.search input'); |
||
1183 | $search.off('keyup drop blur').on('keyup drop blur', function (event) { |
||
1184 | if (that.options.searchOnEnterKey && event.keyCode !== 13) { |
||
1185 | return; |
||
1186 | } |
||
1187 | |||
1188 | if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) { |
||
1189 | return; |
||
1190 | } |
||
1191 | |||
1192 | clearTimeout(timeoutId); // doesn't matter if it's 0 |
||
1193 | timeoutId = setTimeout(function () { |
||
1194 | that.onSearch(event); |
||
1195 | }, that.options.searchTimeOut); |
||
1196 | }); |
||
1197 | |||
1198 | if (isIEBrowser()) { |
||
1199 | $search.off('mouseup').on('mouseup', function (event) { |
||
1200 | clearTimeout(timeoutId); // doesn't matter if it's 0 |
||
1201 | timeoutId = setTimeout(function () { |
||
1202 | that.onSearch(event); |
||
1203 | }, that.options.searchTimeOut); |
||
1204 | }); |
||
1205 | } |
||
1206 | } |
||
1207 | }; |
||
1208 | |||
1209 | BootstrapTable.prototype.onSearch = function (event) { |
||
1210 | var text = $.trim($(event.currentTarget).val()); |
||
1211 | |||
1212 | // trim search input |
||
1213 | if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) { |
||
1214 | $(event.currentTarget).val(text); |
||
1215 | } |
||
1216 | |||
1217 | if (text === this.searchText) { |
||
1218 | return; |
||
1219 | } |
||
1220 | this.searchText = text; |
||
1221 | this.options.searchText = text; |
||
1222 | |||
1223 | this.options.pageNumber = 1; |
||
1224 | this.initSearch(); |
||
1225 | this.updatePagination(); |
||
1226 | this.trigger('search', text); |
||
1227 | }; |
||
1228 | |||
1229 | BootstrapTable.prototype.initSearch = function () { |
||
1230 | var that = this; |
||
1231 | |||
1232 | if (this.options.sidePagination !== 'server') { |
||
1233 | if (this.options.customSearch !== $.noop) { |
||
1234 | this.options.customSearch.apply(this, [this.searchText]); |
||
1235 | return; |
||
1236 | } |
||
1237 | |||
1238 | var s = this.searchText && (this.options.escape ? |
||
1239 | escapeHTML(this.searchText) : this.searchText).toLowerCase(); |
||
1240 | var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns; |
||
1241 | |||
1242 | // Check filter |
||
1243 | this.data = f ? $.grep(this.options.data, function (item, i) { |
||
1244 | for (var key in f) { |
||
1245 | if ($.isArray(f[key]) && $.inArray(item[key], f[key]) === -1 || |
||
1246 | !$.isArray(f[key]) && item[key] !== f[key]) { |
||
1247 | return false; |
||
1248 | } |
||
1249 | } |
||
1250 | return true; |
||
1251 | }) : this.options.data; |
||
1252 | |||
1253 | this.data = s ? $.grep(this.data, function (item, i) { |
||
1254 | for (var j = 0; j < that.header.fields.length; j++) { |
||
1255 | |||
1256 | if (!that.header.searchables[j]) { |
||
1257 | continue; |
||
1258 | } |
||
1259 | |||
1260 | var key = $.isNumeric(that.header.fields[j]) ? parseInt(that.header.fields[j], 10) : that.header.fields[j]; |
||
1261 | var column = that.columns[getFieldIndex(that.columns, key)]; |
||
1262 | var value; |
||
1263 | |||
1264 | if (typeof key === 'string') { |
||
1265 | value = item; |
||
1266 | var props = key.split('.'); |
||
1267 | for (var prop_index = 0; prop_index < props.length; prop_index++) { |
||
1268 | value = value[props[prop_index]]; |
||
1269 | } |
||
1270 | |||
1271 | // Fix #142: respect searchForamtter boolean |
||
1272 | if (column && column.searchFormatter) { |
||
1273 | value = calculateObjectValue(column, |
||
1274 | that.header.formatters[j], [value, item, i], value); |
||
1275 | } |
||
1276 | } else { |
||
1277 | value = item[key]; |
||
1278 | } |
||
1279 | |||
1280 | if (typeof value === 'string' || typeof value === 'number') { |
||
1281 | if (that.options.strictSearch) { |
||
1282 | if ((value + '').toLowerCase() === s) { |
||
1283 | return true; |
||
1284 | } |
||
1285 | } else { |
||
1286 | if ((value + '').toLowerCase().indexOf(s) !== -1) { |
||
1287 | return true; |
||
1288 | } |
||
1289 | } |
||
1290 | } |
||
1291 | } |
||
1292 | return false; |
||
1293 | }) : this.data; |
||
1294 | } |
||
1295 | }; |
||
1296 | |||
1297 | BootstrapTable.prototype.initPagination = function () { |
||
1298 | if (!this.options.pagination) { |
||
1299 | this.$pagination.hide(); |
||
1300 | return; |
||
1301 | } else { |
||
1302 | this.$pagination.show(); |
||
1303 | } |
||
1304 | |||
1305 | var that = this, |
||
1306 | html = [], |
||
1307 | $allSelected = false, |
||
1308 | i, from, to, |
||
1309 | $pageList, |
||
1310 | $first, $pre, |
||
1311 | $next, $last, |
||
1312 | $number, |
||
1313 | data = this.getData(), |
||
1314 | pageList = this.options.pageList; |
||
1315 | |||
1316 | if (this.options.sidePagination !== 'server') { |
||
1317 | this.options.totalRows = data.length; |
||
1318 | } |
||
1319 | |||
1320 | this.totalPages = 0; |
||
1321 | if (this.options.totalRows) { |
||
1322 | if (this.options.pageSize === this.options.formatAllRows()) { |
||
1323 | this.options.pageSize = this.options.totalRows; |
||
1324 | $allSelected = true; |
||
1325 | } else if (this.options.pageSize === this.options.totalRows) { |
||
1326 | // Fix #667 Table with pagination, |
||
1327 | // multiple pages and a search that matches to one page throws exception |
||
1328 | var pageLst = typeof this.options.pageList === 'string' ? |
||
1329 | this.options.pageList.replace('[', '').replace(']', '') |
||
1330 | .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList; |
||
1331 | if ($.inArray(this.options.formatAllRows().toLowerCase(), pageLst) > -1) { |
||
1332 | $allSelected = true; |
||
1333 | } |
||
1334 | } |
||
1335 | |||
1336 | this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1; |
||
1337 | |||
1338 | this.options.totalPages = this.totalPages; |
||
1339 | } |
||
1340 | if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) { |
||
1341 | this.options.pageNumber = this.totalPages; |
||
1342 | } |
||
1343 | |||
1344 | this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1; |
||
1345 | this.pageTo = this.options.pageNumber * this.options.pageSize; |
||
1346 | if (this.pageTo > this.options.totalRows) { |
||
1347 | this.pageTo = this.options.totalRows; |
||
1348 | } |
||
1349 | |||
1350 | html.push( |
||
1351 | ' |
||
1352 |
|
||
1353 |
|
||
1354 |
|
||
1355 |
|
||
1356 | |||
1357 |
|
||
1358 |
|
||
1359 | |||
1360 |
|
||
1361 |
|
||
1362 |
|
||
1363 |
|
||
1364 |
|
||
1365 |
|
||
1366 |
|
||
1367 |
|
||
1368 |
|
||
1369 |
|
||
1370 |
|
||
1371 |
|
||
1372 |
|
||
1373 |
|
||
1374 |
|
||
1375 | |||
1376 |
|
||
1377 |
|
||
1378 |
|
||
1379 | |||
1380 |
|
||
1381 |
|
||
1382 |
|
||
1383 |
|
||
1384 |
|
||
1385 |
|
||
1386 | |||
1387 |
|
||
1388 |
|
||
1389 |
|
||
1390 |
|
||
1391 |
|
||
1392 |
|
||
1393 |
|
||
1394 |
|
||
1395 |
|
||
1396 |
|
||
1397 |
|
||
1398 |
|
||
1399 | |||
1400 |
|
||
1401 |
|
||
1402 | |||
1403 |
|
||
1404 |
|
||
1405 |
|
||
1406 |
|
||
1407 | |||
1408 |
|
||
1409 |
|
||
1410 |
|
||
1411 |
|
||
1412 |
|
||
1413 |
|
||
1414 |
|
||
1415 |
|
||
1416 |
|
||
1417 |
|
||
1418 |
|
||
1419 |
|
||
1420 |
|
||
1421 |
|
||
1422 |
|
||
1423 | |||
1424 |
|
||
1425 |
|
||
1426 |
|
||
1427 |
|
||
1428 |
|
||
1429 | |||
1430 |
|
||
1431 |
|
||
1432 | |||
1433 |
|
||
1434 |
|
||
1435 |
|
||
1436 |
|
||
1437 |
|
||
1438 |
|
||
1439 |
|
||
1440 |
|
||
1441 | |||
1442 |
|
||
1443 |
|
||
1444 |
|
||
1445 | |||
1446 |
|
||
1447 |
|
||
1448 |
|
||
1449 |
|
||
1450 |
|
||
1451 | |||
1452 |
|
||
1453 |
|
||
1454 |
|
||
1455 |
|
||
1456 |
|
||
1457 |
|
||
1458 |
|
||
1459 |
|
||
1460 |
|
||
1461 | |||
1462 |
|
||
1463 |
|
||
1464 |
|
||
1465 |
|
||
1466 |
|
||
1467 | |||
1468 |
|
||
1469 |
|
||
1470 |
|
||
1471 |
|
||
1472 |
|
||
1473 |
|
||
1474 |
|
||
1475 | |||
1476 |
|
||
1477 |
|
||
1478 |
|
||
1479 |
|
||
1480 |
|
||
1481 |
|
||
1482 |
|
||
1483 | |||
1484 |
|
||
1485 |
|
||
1486 |
|
||
1487 |
|
||
1488 |
|
||
1489 |
|
||
1490 | |||
1491 |
|
||
1492 |
|
||
1493 |
|
||
1494 |
|
||
1495 |
|
||
1496 |
|
||
1497 |
|
||
1498 | |||
1499 |
|
||
1500 |
|
||
1501 |
|
||
1502 |
|
||
1503 |
|
||
1504 |
|
||
1505 |
|
||
1506 | |||
1507 |
|
||
1508 |
|
||
1509 |
|
||
1510 | |||
1511 |
|
||
1512 |
|
||
1513 |
|
||
1514 |
|
||
1515 |
|
||
1516 |
|
||
1517 |
|
||
1518 |
|
||
1519 | |||
1520 |
|
||
1521 |
|
||
1522 |
|
||
1523 |
|
||
1524 |
|
||
1525 |
|
||
1526 |
|
||
1527 |
|
||
1528 |
|
||
1529 |
|
||
1530 |
|
||
1531 | |||
1532 |
|
||
1533 |
|
||
1534 |
|
||
1535 |
|
||
1536 |
|
||
1537 | |||
1538 |
|
||
1539 |
|
||
1540 |
|
||
1541 | |||
1542 |
|
||
1543 |
|
||
1544 |
|
||
1545 |
|
||
1546 |
|
||
1547 |
|
||
1548 | |||
1549 |
|
||
1550 |
|
||
1551 | |||
1552 |
|
||
1553 |
|
||
1554 | |||
1555 |
|
||
1556 |
|
||
1557 |
|
||
1558 |
|
||
1559 | |||
1560 |
|
||
1561 |
|
||
1562 |
|
||
1563 | |||
1564 |
|
||
1565 |
|
||
1566 |
|
||
1567 |
|
||
1568 |
|
||
1569 | |||
1570 |
|
||
1571 |
|
||
1572 |
|
||
1573 |
|
||
1574 |
|
||
1575 |
|
||
1576 |
|
||
1577 |
|
||
1578 |
|
||
1579 | |||
1580 |
|
||
1581 |
|
||
1582 |
|
||
1583 |
|
||
1584 |
|
||
1585 |
|
||
1586 |
|
||
1587 |
|
||
1588 |
|
||
1589 | |||
1590 |
|
||
1591 |
|
||
1592 |
|
||
1593 |
|
||
1594 |
|
||
1595 | |||
1596 |
|
||
1597 |
|
||
1598 |
|
||
1599 |
|
||
1600 |
|
||
1601 |
|
||
1602 |
|
||
1603 |
|
||
1604 | |||
1605 |
|
||
1606 |
|
||
1607 |
|
||
1608 |
|
||
1609 |
|
||
1610 |
|
||
1611 |
|
||
1612 |
|
||
1613 |
|
||
1614 | |||
1615 |
|
||
1616 |
|
||
1617 |
|
||
1618 | |||
1619 |
|
||
1620 | |||
1621 |
|
||
1622 |
|
||
1623 |
|
||
1624 |
|
||
1625 |
|
||
1626 | |||
1627 |
|
||
1628 |
|
||
1629 | |||
1630 |
|
||
1631 |
|
||
1632 |
|
||
1633 |
|
||
1634 |
|
||
1635 | |||
1636 |
|
||
1637 |
|
||
1638 |
|
||
1639 |
|
||
1640 |
|
||
1641 |
|
||
1642 |
|
||
1643 |
|
||
1644 |
|
||
1645 | |||
1646 |
|