Skip to content

Commit 762913c

Browse files
committed
Added support for get/set filter values
1 parent 357c903 commit 762913c

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

Griddly/Scripts/griddly.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,34 @@
692692
}
693693
},
694694

695-
buildRequest: function(paging)
695+
getFilterValues: function()
696696
{
697-
var filters = $(".griddly-filters input, .griddly-filters select", this.$element);
697+
var allFilters = $(".griddly-filters input, .griddly-filters select", this.$element).add(this.$inlineFilters);
698+
699+
return serializeObject(allFilters);
700+
},
698701

699-
filters = filters.add(this.$inlineFilters);
702+
setFilterValues: function(filters, isPatch)
703+
{
704+
if (isPatch !== true)
705+
{
706+
var allFilters = $(".griddly-filters input, .griddly-filters select", this.$element).add(this.$inlineFilters);
700707

701-
var postData = serializeObject(filters);
708+
allFilters.each(function ()
709+
{
710+
$(this).val(filters[this.name]).change();
711+
});
712+
}
713+
else
714+
{
715+
for (var key in filters)
716+
$("[name='" + key + "']").val(filters[key]).change();
717+
}
718+
},
719+
720+
buildRequest: function(paging)
721+
{
722+
var postData = this.getFilterValues();
702723

703724
if (this.options.sortFields.length)
704725
{

Griddly/Views/Home/FilterRangeGrid.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
@Html.Griddly(new GriddlySettings<TestGridItem>()
77
{
8-
PageSize = 5
8+
PageSize = 5,
9+
ClassName = "filter-range-grid"
910
}
1011
.Column(x => x.FirstName, "First Name", defaultSort: SortDirection.Ascending)
1112
.Column(x => x.LastName, "Last Name")

Griddly/Views/Home/Index.cshtml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
<div class="jumbotron">
66
<h1>Griddly</h1>
77
@*<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
8-
<p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more &raquo;</a></p>
9-
*@
8+
<p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more &raquo;</a></p>
9+
*@
1010
</div>
1111

1212
<div class="row">
1313
<div class="col-md-12">
1414
@Html.Griddly("FilterBoxGrid", new { test = SortDirection.Ascending })
15+
<br />
16+
<a href="javascript:GetFilterValues()">get filter values</a> | <a href="javascript:SetFilterValues()">set filter values</a>
1517
@Html.Griddly("FilterRangeGrid")
18+
<br />
1619
@Html.Griddly("FilterListGrid")
20+
<br />
1721
@Html.Griddly("TestGrid")
1822
</div>
1923
</div>
@@ -27,7 +31,24 @@
2731
for (var k in result)
2832
str += " " + k + " : [ " + result[k].toString() + " ]\n";
2933
str += "}";
30-
34+
35+
alert(str);
36+
}
37+
38+
function GetFilterValues()
39+
{
40+
var result = $(".filter-range-grid").griddly("getFilterValues");
41+
42+
var str = "{\n";
43+
for (var k in result)
44+
str += " " + k + " : [ " + result[k].toString() + " ]\n";
45+
str += "}";
46+
3147
alert(str);
3248
}
49+
50+
function SetFilterValues()
51+
{
52+
$(".filter-range-grid").griddly("setFilterValues", { companyStart: '53' } );
53+
}
3354
</script>

Griddly/_AppStart.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@using Griddly.Mvc;
22

33
@{
4-
GriddlySettings.DefaultClassName = "table table-bordered table-hover";
4+
//GriddlySettings.DefaultClassName = "table table-bordered table-hover";
55
}
66

0 commit comments

Comments
 (0)