|
189 | 189 | function update(rows, total)
|
190 | 190 | {
|
191 | 191 | that.currentRows = rows;
|
192 |
| - that.total = total; |
193 |
| - that.totalPages = Math.ceil(total / that.rowCount); |
| 192 | + setTotals.call(that, total); |
194 | 193 |
|
195 | 194 | if (!that.options.keepSelection)
|
196 | 195 | {
|
|
288 | 287 | appendRow.call(that, row);
|
289 | 288 | });
|
290 | 289 |
|
291 |
| - this.total = this.rows.length; |
292 |
| - this.totalPages = (this.rowCount === -1) ? 1 : |
293 |
| - Math.ceil(this.total / this.rowCount); |
294 |
| - |
| 290 | + setTotals.call(this, this.rows.length); |
295 | 291 | sortRows.call(this);
|
296 | 292 | }
|
297 | 293 | }
|
298 | 294 |
|
| 295 | + function setTotals(total) |
| 296 | + { |
| 297 | + this.total = total; |
| 298 | + this.totalPages = (this.rowCount === -1) ? 1 : |
| 299 | + Math.ceil(this.total / this.rowCount); |
| 300 | + } |
| 301 | + |
299 | 302 | function prepareTable()
|
300 | 303 | {
|
301 | 304 | var tpl = this.options.templates,
|
|
1614 | 1617 | return this;
|
1615 | 1618 | };
|
1616 | 1619 |
|
1617 |
| - |
1618 | 1620 | /**
|
1619 | 1621 | * Sorts the rows by a given sort descriptor dictionary.
|
1620 | 1622 | * The sort filter will be reseted, if no argument is provided.
|
|
1640 | 1642 | return this;
|
1641 | 1643 | };
|
1642 | 1644 |
|
| 1645 | + /** |
| 1646 | + * Gets a list of the column settings. |
| 1647 | + * This method returns only for the first grid instance a value. |
| 1648 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1649 | + * |
| 1650 | + * @method getColumnSettings |
| 1651 | + * @return {Array} Returns a list of the column settings. |
| 1652 | + **/ |
| 1653 | + Grid.prototype.getColumnSettings = function() |
| 1654 | + { |
| 1655 | + return $.merge([], this.columns); |
| 1656 | + }; |
| 1657 | + |
| 1658 | + /** |
| 1659 | + * Gets the current page index. |
| 1660 | + * This method returns only for the first grid instance a value. |
| 1661 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1662 | + * |
| 1663 | + * @method getCurrentPage |
| 1664 | + * @return {Number} Returns the current page index. |
| 1665 | + **/ |
| 1666 | + Grid.prototype.getCurrentPage = function() |
| 1667 | + { |
| 1668 | + return this.current; |
| 1669 | + }; |
| 1670 | + |
| 1671 | + /** |
| 1672 | + * Gets the current rows. |
| 1673 | + * This method returns only for the first grid instance a value. |
| 1674 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1675 | + * |
| 1676 | + * @method getCurrentPage |
| 1677 | + * @return {Array} Returns the current rows. |
| 1678 | + **/ |
| 1679 | + Grid.prototype.getCurrentRows = function() |
| 1680 | + { |
| 1681 | + return $.merge([], this.currentRows); |
| 1682 | + }; |
| 1683 | + |
| 1684 | + /** |
| 1685 | + * Gets a number represents the row count per page. |
| 1686 | + * This method returns only for the first grid instance a value. |
| 1687 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1688 | + * |
| 1689 | + * @method getRowCount |
| 1690 | + * @return {Number} Returns the row count per page. |
| 1691 | + **/ |
| 1692 | + Grid.prototype.getRowCount = function() |
| 1693 | + { |
| 1694 | + return this.rowCount; |
| 1695 | + }; |
| 1696 | + |
| 1697 | + /** |
| 1698 | + * Gets the actual search phrase. |
| 1699 | + * This method returns only for the first grid instance a value. |
| 1700 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1701 | + * |
| 1702 | + * @method getSearchPhrase |
| 1703 | + * @return {String} Returns the actual search phrase. |
| 1704 | + **/ |
| 1705 | + Grid.prototype.getSearchPhrase = function() |
| 1706 | + { |
| 1707 | + return this.searchPhrase; |
| 1708 | + }; |
| 1709 | + |
| 1710 | + /** |
| 1711 | + * Gets the complete list of currently selected rows. |
| 1712 | + * This method returns only for the first grid instance a value. |
| 1713 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1714 | + * |
| 1715 | + * @method getSelectedRows |
| 1716 | + * @return {Array} Returns all selected rows. |
| 1717 | + **/ |
| 1718 | + Grid.prototype.getSelectedRows = function() |
| 1719 | + { |
| 1720 | + return $.merge([], this.selectedRows); |
| 1721 | + }; |
| 1722 | + |
| 1723 | + /** |
| 1724 | + * Gets the sort dictionary which represents the state of column sorting. |
| 1725 | + * This method returns only for the first grid instance a value. |
| 1726 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1727 | + * |
| 1728 | + * @method getSortDictionary |
| 1729 | + * @return {Object} Returns the sort dictionary. |
| 1730 | + **/ |
| 1731 | + Grid.prototype.getSortDictionary = function() |
| 1732 | + { |
| 1733 | + return $.extend({}, this.sortDictionary); |
| 1734 | + }; |
| 1735 | + |
| 1736 | + /** |
| 1737 | + * Gets a number represents the total page count. |
| 1738 | + * This method returns only for the first grid instance a value. |
| 1739 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1740 | + * |
| 1741 | + * @method getTotalPageCount |
| 1742 | + * @return {Number} Returns the total page count. |
| 1743 | + **/ |
| 1744 | + Grid.prototype.getTotalPageCount = function() |
| 1745 | + { |
| 1746 | + return this.totalPages; |
| 1747 | + }; |
| 1748 | + |
| 1749 | + /** |
| 1750 | + * Gets a number represents the total row count. |
| 1751 | + * This method returns only for the first grid instance a value. |
| 1752 | + * Therefore be sure that only one grid instance is catched by your selector. |
| 1753 | + * |
| 1754 | + * @method getTotalRowCount |
| 1755 | + * @return {Number} Returns the total row count. |
| 1756 | + **/ |
| 1757 | + Grid.prototype.getTotalRowCount = function() |
| 1758 | + { |
| 1759 | + return this.total; |
| 1760 | + }; |
| 1761 | + |
1643 | 1762 | // GRID COMMON TYPE EXTENSIONS
|
1644 | 1763 | // ============
|
1645 | 1764 |
|
|
1818 | 1937 |
|
1819 | 1938 | $.fn.bootgrid = function (option)
|
1820 | 1939 | {
|
1821 |
| - var args = Array.prototype.slice.call(arguments, 1); |
1822 |
| - return this.each(function () |
1823 |
| - { |
1824 |
| - var $this = $(this), |
1825 |
| - instance = $this.data(namespace), |
1826 |
| - options = typeof option === "object" && option; |
1827 |
| - |
1828 |
| - if (!instance && option === "destroy") |
1829 |
| - { |
1830 |
| - return; |
1831 |
| - } |
1832 |
| - if (!instance) |
1833 |
| - { |
1834 |
| - $this.data(namespace, (instance = new Grid(this, options))); |
1835 |
| - init.call(instance); |
1836 |
| - } |
1837 |
| - if (typeof option === "string") |
| 1940 | + var args = Array.prototype.slice.call(arguments, 1), |
| 1941 | + returnValue = null, |
| 1942 | + elements = this.each(function (index) |
1838 | 1943 | {
|
1839 |
| - return instance[option].apply(instance, args); |
1840 |
| - } |
1841 |
| - }); |
| 1944 | + var $this = $(this), |
| 1945 | + instance = $this.data(namespace), |
| 1946 | + options = typeof option === "object" && option; |
| 1947 | + |
| 1948 | + if (!instance && option === "destroy") |
| 1949 | + { |
| 1950 | + return; |
| 1951 | + } |
| 1952 | + if (!instance) |
| 1953 | + { |
| 1954 | + $this.data(namespace, (instance = new Grid(this, options))); |
| 1955 | + init.call(instance); |
| 1956 | + } |
| 1957 | + if (typeof option === "string") |
| 1958 | + { |
| 1959 | + if (option.indexOf("get") === 0 && index === 0) |
| 1960 | + { |
| 1961 | + returnValue = instance[option].apply(instance, args); |
| 1962 | + } |
| 1963 | + else if (option.indexOf("get") !== 0) |
| 1964 | + { |
| 1965 | + return instance[option].apply(instance, args); |
| 1966 | + } |
| 1967 | + } |
| 1968 | + }); |
| 1969 | + return (typeof option === "string" && option.indexOf("get") === 0) ? returnValue : elements; |
1842 | 1970 | };
|
1843 | 1971 |
|
1844 | 1972 | $.fn.bootgrid.Constructor = Grid;
|
|
0 commit comments