|
17 | 17 | this.$element = $(element);
|
18 | 18 | this.options = options;
|
19 | 19 | this.create();
|
| 20 | + this.isConstructed = false; |
| 21 | + this.eventQueue = []; |
| 22 | + |
| 23 | + this.triggerOrQueue = function () |
| 24 | + { |
| 25 | + if (this.isConstructed) |
| 26 | + { |
| 27 | + arguments[0].trigger.apply(arguments[0], Array.prototype.slice.call(arguments, 1)); |
| 28 | + } |
| 29 | + else |
| 30 | + { |
| 31 | + this.eventQueue[this.eventQueue.length] = arguments; |
| 32 | + } |
| 33 | + }; |
20 | 34 |
|
21 | 35 | $(this.$element).find("[data-enable-on-selection=true]").addClass("disabled");
|
22 | 36 |
|
23 | 37 | if (this.options.onRefresh)
|
24 | 38 | this.options.onRefresh(this, 0, this.options.count > this.options.pageSize ? this.options.pageSize : this.options.count, this.options.count, null);
|
25 | 39 |
|
26 |
| - this.$element.trigger("init.griddly", |
| 40 | + this.triggerOrQueue(this.$element, "init.griddly", |
27 | 41 | {
|
28 | 42 | start: 0,
|
29 | 43 | pageSize: this.options.count > this.options.pageSize ? this.options.pageSize : this.options.count,
|
|
125 | 139 | }
|
126 | 140 |
|
127 | 141 | }, this);
|
| 142 | + |
| 143 | + this.isConstructed = true; |
128 | 144 | };
|
129 | 145 |
|
130 | 146 | var serializeObject = function ($elements)
|
|
646 | 662 |
|
647 | 663 | $(".griddly-filters-inline input, .griddly-filters-inline select", this.$element).on("change", $.proxy(function (event)
|
648 | 664 | {
|
649 |
| - this.$element.trigger("filterchange.griddly", this.$element, event.target); |
| 665 | + this.triggerOrQueue(this.$element, "filterchange.griddly", this.$element, event.target); |
650 | 666 |
|
651 | 667 | if (this.options.autoRefreshOnFilter)
|
652 | 668 | this.refresh(true);
|
|
792 | 808 | {
|
793 | 809 | if (this.options.allowedFilterModes.indexOf(mode) > -1)
|
794 | 810 | {
|
795 |
| - this.$element.trigger("setfiltermode.griddly", { mode: mode }); |
| 811 | + this.triggerOrQueue(this.$element, "setfiltermode.griddly", { mode: mode }); |
796 | 812 |
|
797 | 813 | var currentFilters = this.getFilterValues();
|
798 | 814 | var request1 = this.buildRequest();
|
|
925 | 941 | this.setFilterValue(e, filters[e.name]);
|
926 | 942 | }, this));
|
927 | 943 |
|
928 |
| - this.$element.trigger("setfilters.griddly", filters); |
| 944 | + this.triggerOrQueue(this.$element, "setfilters.griddly", filters); |
929 | 945 |
|
930 | 946 | this.options.autoRefreshOnFilter = true;
|
931 | 947 |
|
|
942 | 958 |
|
943 | 959 | this.setFilterValues(this.options.filterDefaults);
|
944 | 960 |
|
945 |
| - this.$element.trigger("resetfilters.griddly"); |
| 961 | + this.triggerOrQueue(this.$element, "resetfilters.griddly"); |
946 | 962 |
|
947 | 963 | this.refresh(true);
|
948 | 964 | },
|
|
975 | 991 |
|
976 | 992 | refresh: function(resetPage)
|
977 | 993 | {
|
978 |
| - this.$element.trigger("beforerefresh.griddly"); |
| 994 | + this.triggerOrQueue(this.$element, "beforerefresh.griddly"); |
979 | 995 |
|
980 | 996 | if (!this.options.url)
|
981 | 997 | {
|
|
1066 | 1082 | $(e).prop("checked", true);
|
1067 | 1083 | });
|
1068 | 1084 |
|
1069 |
| - this.$element.trigger("refresh.griddly", |
| 1085 | + this.triggerOrQueue(this.$element, "refresh.griddly", |
1070 | 1086 | {
|
1071 | 1087 | start: startRecord,
|
1072 | 1088 | pageSize: currentPageSize,
|
|
1091 | 1107 | window.location = url;
|
1092 | 1108 | }
|
1093 | 1109 |
|
1094 |
| - this.$element.trigger("error.griddly", { xhr: xhr, status: status, error: errorThrown }); |
| 1110 | + this.triggerOrQueue(this.$element, "error.griddly", { xhr: xhr, status: status, error: errorThrown }); |
1095 | 1111 | }, this));
|
1096 | 1112 | },
|
1097 | 1113 |
|
|
1157 | 1173 | var instanceOptions = $.extend({}, $.fn.griddly.defaults, options);
|
1158 | 1174 |
|
1159 | 1175 | $(this).data('griddly', (data = new Griddly(this, instanceOptions)));
|
| 1176 | + |
| 1177 | + var event = data.eventQueue.pop(); |
| 1178 | + while (event) |
| 1179 | + { |
| 1180 | + event[0].trigger.apply(event[0], Array.prototype.slice.call(event, 1)) |
| 1181 | + event = data.eventQueue.pop(); |
| 1182 | + } |
1160 | 1183 | }
|
1161 | 1184 |
|
1162 | 1185 | // call griddly method
|
|
0 commit comments