|
108 | 108 | this.options= $.extend( |
109 | 109 | true, // deep extend |
110 | 110 | { |
111 | | - DEBUG : false, |
112 | | - dataUrl : "", |
113 | | - msgTarget : $('#alerts-page'), |
114 | | - addParams : {}, |
| 111 | + DEBUG : false, |
| 112 | + dataUrl : "", |
| 113 | + msgTarget : $('#alerts-page'), |
| 114 | + addParams : {}, |
| 115 | + filterAllField: '_all', |
115 | 116 | tablesorter : { |
116 | 117 | debug: false, |
117 | 118 | theme : 'bootstrap', |
118 | 119 | widthFixed: true, |
119 | 120 | // Set up pagination of data via an AJAX source |
120 | 121 | // See http://jsfiddle.net/Mottie/uwZc2/ |
121 | 122 | // Also see https://mottie.github.io/tablesorter/docs/example-pager-ajax.html |
122 | | - widgets: ['saveSort','sort2Hash','filter'], |
| 123 | + widgets: ['saveSort','sort2Hash','filter', 'columnSelector', 'reflow2'], |
123 | 124 | widgetOptions : { |
| 125 | + columnSelector_container : this.$T.find('.menu-table-column-selector-options'), |
| 126 | + columnSelector_layout : '<label><input type="checkbox"> <span>{name}</span></label>', |
124 | 127 | filter_cssFilter: 'form-control', |
| 128 | + filter_external : this.$T.find('.table-search input'), |
125 | 129 | filter_saveFilters : true, |
126 | 130 | filter_serversideFiltering : true, |
127 | 131 | filter_selectSource: { |
|
135 | 139 | sort2Hash_tableId : null, |
136 | 140 | // if true, show header cell text instead of a zero-based column index |
137 | 141 | sort2Hash_headerTextAttr : 'data-column-name', |
138 | | - sort2Hash_encodeHash : base._encodeHash, |
139 | | - sort2Hash_decodeHash : base._decodeHash, |
140 | | - sort2Hash_cleanHash : base._cleanHash, |
141 | 142 | // direction text shown in the URL e.g. [ 'asc', 'desc' ] |
142 | 143 | sort2Hash_directionText : [ 'asc', 'desc' ], // default values |
143 | 144 | // if true, override saveSort widget sort, if used & stored sort is available |
|
237 | 238 | var filters = {}; |
238 | 239 | for (i = 0; i < filterList.length; i++) { |
239 | 240 | if (filterList[i]) { |
240 | | - var columnName = $(table.config.headerList[i]).data('column-name'); |
| 241 | + if (table.config.headerList[i]) { |
| 242 | + var columnName = $(table.config.headerList[i]).data('column-name'); |
| 243 | + } else { |
| 244 | + var columnName = base.options.filterAllField; |
| 245 | + } |
| 246 | + |
241 | 247 | filters[columnName] = filterList[i]; |
242 | 248 | } |
243 | 249 | } |
|
271 | 277 | }; |
272 | 278 |
|
273 | 279 | // Callback to display errors |
274 | | - base.options.pager.ajaxError = function ( config, xhr, settings, exception ) { |
| 280 | + base.options.pager.ajaxError = function ( config, xhr, settings, exception ) { |
275 | 281 | return base._ajaxError(base, config, xhr, settings, exception); |
276 | 282 | }; |
277 | 283 |
|
| 284 | + base.options.tablesorter.widgetOptions.sort2Hash_encodeHash = function (config, tableId, component, value, rawValue) { |
| 285 | + return base._encodeHash(base, config, tableId, component, value, rawValue); |
| 286 | + }; |
| 287 | + |
| 288 | + base.options.tablesorter.widgetOptions.sort2Hash_decodeHash = function (config, tableId, component) { |
| 289 | + return base._decodeHash(base, config, tableId, component); |
| 290 | + }; |
| 291 | + |
| 292 | + base.options.tablesorter.widgetOptions.sort2Hash_cleanHash = function (config, tableId, component, hash ) { |
| 293 | + return base._cleanHash(base, config, tableId, component, hash); |
| 294 | + }; |
| 295 | + |
278 | 296 | // Set up tablesorter and pager |
279 | 297 | base.ts = $el.find('.tablesorter').tablesorter(base.options.tablesorter); |
280 | 298 | base.ts.tablesorterPager(base.options.pager); |
|
293 | 311 | window.location = base.options.dataUrl + '?' + $.param( tableState ); |
294 | 312 | }); |
295 | 313 |
|
| 314 | + // Allow clicking on the labels in the table menu without closing the menu |
| 315 | + $(base.options.tablesorter.widgetOptions.columnSelector_container).find('label').on('click', function(e) { |
| 316 | + e.stopPropagation(); |
| 317 | + }); |
| 318 | + |
296 | 319 | base.ts.on('pagerComplete', function () { |
297 | 320 | $el.find('.tablesorter').trigger('update'); |
298 | 321 | $el.trigger('pagerComplete.ufTable'); |
|
395 | 418 | /** |
396 | 419 | * Private method used to encode the current table state variables into a URL hash. |
397 | 420 | */ |
398 | | - Plugin.prototype._encodeHash = function ( config, tableId, component, value, rawValue ) { |
| 421 | + Plugin.prototype._encodeHash = function (base, config, tableId, component, value, rawValue) { |
399 | 422 | var wo = config.widgetOptions; |
400 | 423 | if ( component === 'filter' ) { |
401 | 424 | // rawValue is an array of filter values, numerically indexed |
402 | 425 | var encodedFilters = ""; |
403 | 426 | var len = rawValue.length; |
404 | 427 | for ( index = 0; index < len; index++ ) { |
405 | 428 | if (rawValue[index]) { |
406 | | - var columnName = $(config.$headerIndexed[ index ][0]).attr(wo.sort2Hash_headerTextAttr); |
| 429 | + if (config.$headerIndexed[index]) { |
| 430 | + var columnName = $(config.$headerIndexed[index][0]).attr(wo.sort2Hash_headerTextAttr); |
| 431 | + } else { |
| 432 | + var columnName = base.options.filterAllField; |
| 433 | + } |
407 | 434 | encodedFilters += '&filter[' + tableId + '][' + columnName + ']=' + encodeURIComponent(rawValue[index]); |
408 | 435 | } |
409 | 436 | } |
|
426 | 453 | /** |
427 | 454 | * Private method used to decode the current table state variables from the URL hash. |
428 | 455 | */ |
429 | | - Plugin.prototype._decodeHash = function ( config, tableId, component ) { |
| 456 | + Plugin.prototype._decodeHash = function (base, config, tableId, component ) { |
| 457 | + base = this; |
430 | 458 | var wo = config.widgetOptions; |
431 | 459 | var result; |
432 | 460 | // Convert hash into JSON object |
|
441 | 469 | // Build a numerically indexed array of filter values |
442 | 470 | var len = config.$headerIndexed.length; |
443 | 471 | for ( index = 0; index < len; index++ ) { |
444 | | - var column_name = $(config.$headerIndexed[ index ][0]).attr(wo.sort2Hash_headerTextAttr); |
445 | | - if (filters[column_name]) { |
446 | | - decodedFilters.push(filters[column_name]); |
| 472 | + var columnName = $(config.$headerIndexed[index][0]).attr(wo.sort2Hash_headerTextAttr); |
| 473 | + if (filters[columnName] && filters[columnName] != base.options.filterAllField) { |
| 474 | + decodedFilters.push(filters[columnName]); |
447 | 475 | } else { |
448 | 476 | decodedFilters.push(''); |
449 | 477 | } |
|
462 | 490 | /** |
463 | 491 | * Private method used to clean up URL hash. |
464 | 492 | */ |
465 | | - Plugin.prototype._cleanHash = function ( config, tableId, component, hash ) { |
| 493 | + Plugin.prototype._cleanHash = function (base, config, tableId, component, hash ) { |
466 | 494 | var wo = config.widgetOptions; |
467 | 495 | // Convert hash to JSON object |
468 | 496 | var urlObject = $.String.deparam(hash); |
|
0 commit comments