|
1 | 1 | /*! |
2 | | - * jQuery Bootgrid v1.3.1 - 08/04/2016 |
| 2 | + * jQuery Bootgrid v1.3.2 - 08/09/2016 |
3 | 3 | * Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com) |
4 | 4 | * Licensed under MIT http://www.opensource.org/licenses/MIT |
5 | 5 | */ |
@@ -362,6 +362,7 @@ function renderColumnSelection(actions) { |
362 | 362 | checkbox = $this.find(checkboxSelector); |
363 | 363 | if (!checkbox.prop("disabled")) { |
364 | 364 | column.visible = checkbox.prop("checked"); |
| 365 | + that.element.trigger('toggleColumn', [column.id, column.text, column.visible]); |
365 | 366 | var enable = that.columns.where(isVisible).length > 1; |
366 | 367 | $this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)") |
367 | 368 | ._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable); |
@@ -478,6 +479,7 @@ function renderPaginationItem(list, page, text, markerCss) { |
478 | 479 | }; |
479 | 480 | var command = $this.data("page"); |
480 | 481 | that.current = commandList[command] || command; |
| 482 | + that.element.trigger('changePage', [command.toString(), that.current]); |
481 | 483 | loadData.call(that); |
482 | 484 | } |
483 | 485 | $this.trigger("blur"); |
@@ -518,15 +520,22 @@ function renderRowCountSelection(actions) { |
518 | 520 | var $this = $(this), |
519 | 521 | newRowCount = $this.data("action"); |
520 | 522 | if (newRowCount !== that.rowCount) { |
521 | | - // todo: sophisticated solution needed for calculating which page is selected |
522 | | - that.current = 1; // that.rowCount === -1 ---> All |
| 523 | + if(that.options.resolvePageFromRowCount){ |
| 524 | + var page = that.current > 1 ? that.current : 1; |
| 525 | + var skip = that.current > 1 ? that.rowCount * (that.current-1) + 1 : 0; |
| 526 | + var newPage = skip > 1 ? Math.ceil(skip/newRowCount) : 1; |
| 527 | + that.current = newRowCount > 0 ? newPage : 1; |
| 528 | + }else{ |
| 529 | + that.current = 1; |
| 530 | + } |
523 | 531 | that.rowCount = newRowCount; |
524 | 532 | $this.parents(menuItemsSelector).children().each(function() { |
525 | 533 | var $item = $(this), |
526 | 534 | currentRowCount = $item.find(menuItemSelector).data("action"); |
527 | 535 | $item._bgSelectAria(currentRowCount === newRowCount); |
528 | 536 | }); |
529 | 537 | $this.parents(menuSelector).find(menuTextSelector).text(getText(newRowCount)); |
| 538 | + that.element.trigger('changeRowCount' + namespace, [newRowCount]); |
530 | 539 | loadData.call(that); |
531 | 540 | } |
532 | 541 | }); |
@@ -692,6 +701,7 @@ function executeSearch(phrase) { |
692 | 701 | if (this.searchPhrase !== phrase) { |
693 | 702 | this.current = 1; |
694 | 703 | this.searchPhrase = phrase; |
| 704 | + this.element.trigger("search" + namespace, [this.searchPhrase]); |
695 | 705 | loadData.call(this); |
696 | 706 | } |
697 | 707 | } |
@@ -935,6 +945,17 @@ Grid.defaults = { |
935 | 945 | columnSelection: true, |
936 | 946 | rowCount: [10, 25, 50, -1], // rows per page int or array of int (-1 represents "All") |
937 | 947 |
|
| 948 | + /** |
| 949 | + * Resolves the correct page number after changing the row count so that the top most row will remain in the table |
| 950 | + * |
| 951 | + * @property resolvePageFromRowCount |
| 952 | + * @type Boolean |
| 953 | + * @default true |
| 954 | + * @for defaults |
| 955 | + * @since 1.4.0 |
| 956 | + **/ |
| 957 | + resolvePageFromRowCount: true, |
| 958 | + |
938 | 959 | /** |
939 | 960 | * Enables row selection (to enable multi selection see also `multiSelect`). Default value is `false`. |
940 | 961 | * |
@@ -1609,12 +1630,25 @@ Grid.prototype.sort = function(dictionary) |
1609 | 1630 | * Therefore be sure that only one grid instance is catched by your selector. |
1610 | 1631 | * |
1611 | 1632 | * @method getColumnSettings |
| 1633 | + * @param {Object} filter object to filter return array with |
1612 | 1634 | * @return {Array} Returns a list of the column settings. |
1613 | 1635 | * @since 1.2.0 |
| 1636 | + * @version 1.4.0 |
1614 | 1637 | **/ |
1615 | | -Grid.prototype.getColumnSettings = function() |
| 1638 | +Grid.prototype.getColumnSettings = function(filter) |
1616 | 1639 | { |
1617 | | - return $.merge([], this.columns); |
| 1640 | + var res = this.columns; |
| 1641 | + if(filter && typeof filter === 'object'){ |
| 1642 | + res = this.columns.filter(function(el){ |
| 1643 | + for (var key in filter) { |
| 1644 | + if(el[key] !== filter[key]){ |
| 1645 | + return false; |
| 1646 | + } |
| 1647 | + } |
| 1648 | + return true; |
| 1649 | + }); |
| 1650 | + } |
| 1651 | + return $.merge([], res); |
1618 | 1652 | }; |
1619 | 1653 |
|
1620 | 1654 | /** |
|
0 commit comments