|
30 | 30 | count: this.options.count
|
31 | 31 | });
|
32 | 32 |
|
| 33 | + var isLoadingHistory = false; |
| 34 | + |
| 35 | + if (window.history && history.replaceState && history.state && history.state.griddly) |
| 36 | + { |
| 37 | + var state = history.state.griddly[this.options.url]; |
| 38 | + |
| 39 | + if (state && state.filterValues) |
| 40 | + { |
| 41 | + if (this.$element.prev(".griddly-init-flag").val() == "loaded") |
| 42 | + { |
| 43 | + try |
| 44 | + { |
| 45 | + isLoadingHistory = true; |
| 46 | + |
| 47 | + this.options.pageNumber = state.pageNumber; |
| 48 | + this.options.pageSize = state.pageSize; |
| 49 | + this.options.sortFields = state.sortFields; |
| 50 | + this.setFilterMode(state.filterMode, true); |
| 51 | + this.setFilterValues(state.filterValues, false, true); |
| 52 | + |
| 53 | + $("[data-griddly-sortfield], .griddly-filters-inline td", this.$element).removeClass("sorted_a sorted_d"); |
| 54 | + |
| 55 | + if (this.options.sortFields) |
| 56 | + { |
| 57 | + for (var i = 0; i < this.options.sortFields.length; i++) |
| 58 | + { |
| 59 | + var sort = this.options.sortFields[i]; |
| 60 | + |
| 61 | + var header = $("th[data-griddly-sortfield='" + sort.Field + "']", this.$element); |
| 62 | + var inlineFilter = $(".griddly-filters-inline")[0].cells[header[0].cellIndex]; |
| 63 | + |
| 64 | + header.addClass(sort.Direction == "Ascending" ? "sorted_a" : "sorted_d"); |
| 65 | + $(inlineFilter).addClass(sort.Direction == "Ascending" ? "sorted_a" : "sorted_d"); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + this.refresh(); |
| 70 | + } |
| 71 | + catch (e) |
| 72 | + { |
| 73 | + isLoadingHistory = false; |
| 74 | + } |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + // user refreshed page, go back to defaults |
| 79 | + delete history.state.griddly[this.options.url]; |
| 80 | + |
| 81 | + history.replaceState(history.state, document.title); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + if (!isLoadingHistory) |
| 87 | + { |
| 88 | + this.$element.removeClass("griddly-init"); |
| 89 | + this.$element.prev(".griddly-init-flag").val("loaded"); |
| 90 | + } |
| 91 | + |
33 | 92 | $("html").on("click", $.proxy(function (event)
|
34 | 93 | {
|
35 | 94 | if ($(event.target).parents('.popover.in').length == 0 && $(event.target).parents(".filter-trigger").length == 0 && !$(event.target).hasClass("filter-trigger"))
|
|
780 | 839 | value = date.toLocaleDateString();
|
781 | 840 | break;
|
782 | 841 | case "Currency":
|
783 |
| - value = value.toFixed(2); |
| 842 | + value = parseFloat(value).toFixed(2); |
784 | 843 | break;
|
785 | 844 | }
|
786 | 845 | }
|
|
871 | 930 |
|
872 | 931 | var postData = this.buildRequest();
|
873 | 932 |
|
| 933 | + if (window.history && history.replaceState) |
| 934 | + { |
| 935 | + var state = |
| 936 | + { |
| 937 | + pageNumber: this.options.pageNumber, |
| 938 | + pageSize: this.options.pageSize, |
| 939 | + sortFields: this.options.sortFields, |
| 940 | + filterMode: this.getFilterMode(), |
| 941 | + filterValues: this.getFilterValues() |
| 942 | + }; |
| 943 | + |
| 944 | + var globalState = history.state || {}; |
| 945 | + |
| 946 | + if (!globalState.griddly) |
| 947 | + globalState.griddly = {}; |
| 948 | + |
| 949 | + globalState.griddly[this.options.url] = state; |
| 950 | + |
| 951 | + history.replaceState(globalState, document.title); |
| 952 | + } |
| 953 | + |
874 | 954 | // TODO: cancel any outstanding calls
|
875 | 955 |
|
876 | 956 | $.ajax(this.options.url,
|
|
931 | 1011 | pageSize: currentPageSize,
|
932 | 1012 | count: count
|
933 | 1013 | });
|
| 1014 | + |
| 1015 | + this.$element.removeClass("griddly-init"); |
| 1016 | + this.$element.prev(".griddly-init-flag").val("loaded"); |
934 | 1017 | }, this))
|
935 | 1018 | .fail($.proxy(function (xhr, status, errorThrown)
|
936 | 1019 | {
|
|
1218 | 1301 | }
|
1219 | 1302 | };
|
1220 | 1303 |
|
1221 |
| - $(function() |
| 1304 | + $("[data-role=griddly]").griddly(); |
| 1305 | + |
| 1306 | + $(function () |
1222 | 1307 | {
|
1223 | 1308 | $("[data-role=griddly]").griddly();
|
| 1309 | + |
1224 | 1310 | $(document).on("click", "[data-role=griddly-button]", GriddlyButton.handleClick);
|
1225 | 1311 |
|
1226 | 1312 | // patch bootstrap js so it doesn't .empty() our inline filter dropdowns
|
|
0 commit comments