Skip to content

Commit 879d40e

Browse files
committed
Add history support for all griddly settings
1 parent 88d7697 commit 879d40e

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

Griddly/Scripts/griddly.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,38 @@
3030
count: this.options.count
3131
});
3232

33+
if (history.state && history.state.griddly)
34+
{
35+
var state = history.state.griddly[this.options.url];
36+
37+
if (state && state.filterValues)
38+
{
39+
this.options.pageNumber = state.pageNumber;
40+
this.options.pageSize = state.pageSize;
41+
this.options.sortFields = state.sortFields;
42+
this.setFilterMode(state.filterMode, true);
43+
this.setFilterValues(state.filterValues, false, true);
44+
45+
$("[data-griddly-sortfield], .griddly-filters-inline td", this.$element).removeClass("sorted_a sorted_d");
46+
47+
if (this.options.sortFields)
48+
{
49+
for (var i = 0; i < this.options.sortFields.length; i++)
50+
{
51+
var sort = this.options.sortFields[i];
52+
53+
var header = $("th[data-griddly-sortfield='" + sort.Field + "']", this.$element);
54+
var inlineFilter = $(".griddly-filters-inline")[0].cells[header[0].cellIndex];
55+
56+
header.addClass(sort.Direction == "Ascending" ? "sorted_a" : "sorted_d");
57+
$(inlineFilter).addClass(sort.Direction == "Ascending" ? "sorted_a" : "sorted_d");
58+
}
59+
}
60+
61+
this.refresh();
62+
}
63+
}
64+
3365
$("html").on("click", $.proxy(function (event)
3466
{
3567
if ($(event.target).parents('.popover.in').length == 0 && $(event.target).parents(".filter-trigger").length == 0 && !$(event.target).hasClass("filter-trigger"))
@@ -780,7 +812,7 @@
780812
value = date.toLocaleDateString();
781813
break;
782814
case "Currency":
783-
value = value.toFixed(2);
815+
value = parseFloat(value).toFixed(2);
784816
break;
785817
}
786818
}
@@ -871,6 +903,24 @@
871903

872904
var postData = this.buildRequest();
873905

906+
var state =
907+
{
908+
pageNumber: this.options.pageNumber,
909+
pageSize: this.options.pageSize,
910+
sortFields: this.options.sortFields,
911+
filterMode: this.getFilterMode(),
912+
filterValues: this.getFilterValues()
913+
};
914+
915+
var globalState = history.state || {};
916+
917+
if (!globalState.griddly)
918+
globalState.griddly = {};
919+
920+
globalState.griddly[this.options.url] = state;
921+
922+
history.replaceState(globalState);
923+
874924
// TODO: cancel any outstanding calls
875925

876926
$.ajax(this.options.url,

0 commit comments

Comments
 (0)