Skip to content

Commit e179583

Browse files
committed
Merge pull request #14 from ithielnor/master
Fixed but in post button type. Added AppendToUrl
2 parents ed3d323 + 23fd92f commit e179583

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

Build/CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
//
1616
// You can specify all the values or you can default the Revision and Build Numbers
1717
// by using the '*' as shown below:
18-
[assembly: AssemblyVersion("1.0.73.0")]
19-
[assembly: AssemblyFileVersion("1.0.73.0")]
18+
[assembly: AssemblyVersion("1.0.73.1")]
19+
[assembly: AssemblyFileVersion("1.0.73.1")]

Griddly.Mvc/GriddlyButton.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public class GriddlyButton
2121
public string ConfirmMessage { get; set; }
2222
public bool AlignRight { get; set; }
2323
public string[] RowIds { get; set; }
24+
/// <summary>
25+
/// Append the selected row ids to the button href as comma separated query strings (only navigate and modal types supported)
26+
/// </summary>
27+
public bool AppendRowIdsToUrl { get; set; }
2428

2529
public GriddlyButtonAction Action { get; set; }
2630

Griddly/Scripts/griddly.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
this.options.onRefresh = window[onRefresh];
117117

118118
// TODO: should we do this later on so we handle dynamically added buttons?
119-
this.$element.find("[data-griddly-toggle=modal][href*='_griddlyIds']").each(function ()
119+
this.$element.find("[data-append-rowids-to-url]").each(function ()
120120
{
121121
$(this).data("griddly-href-template", $(this).attr("href"));
122122
});
@@ -285,22 +285,24 @@
285285

286286
var onRowChange = $.proxy(function (event)
287287
{
288-
var ids = this.getSelected();
289-
290-
if (ids.length)
291-
ids = ids.join(",");
292-
else
293-
ids = "";
288+
this.setSelectedCount();
294289

295-
this.$element.find("[data-griddly-toggle=modal]").each(function ()
290+
this.$element.find("[data-append-rowids-to-url]").each(function ()
296291
{
297292
var template = $(this).data("griddly-href-template");
298293

299294
if (template)
300-
$(this).attr("href", template.replace(/_griddlyIds/g, ids));
301-
});
295+
{
296+
var selection = this.getSelected($(this).data["rowids"]);
297+
var query = [];
298+
for (var k in selection)
299+
{
300+
query[query.length] = k + "=" + selection[k].join(",");
301+
}
302302

303-
this.setSelectedCount();
303+
$(this).attr("href", template + (template.indexOf("?") > -1 ? "&" : "?") + query.join("&"));
304+
}
305+
});
304306
}, this);
305307

306308
var setRowSelect = $.proxy(function ($checkbox)
@@ -820,12 +822,15 @@
820822

821823
getSelected: function(arrayIdNames)
822824
{
825+
if (arrayIdNames === "all")
826+
return this.options.selectedRows;
827+
823828
if (!arrayIdNames)
824829
arrayIdNames = this.options.defaultRowIds;
825830
else if (typeof arrayIdNames === "string")
826831
arrayIdNames = [ arrayIdNames ];
827832

828-
var result = {}
833+
var result = {};
829834
for (var name in arrayIdNames)
830835
result[arrayIdNames[name]] = $.map(this.options.selectedRows, function (x) { return x[arrayIdNames[name]] });
831836

@@ -1009,11 +1014,12 @@
10091014
if (token.length)
10101015
inputs += '<input type="hidden" name="' + token.attr("name") + '" value="' + token.val() + '" />';
10111016

1012-
$.each(selection, function () {
1013-
$.each(this, function () {
1014-
inputs += "<input name=\"ids\" value=\"" + this + "\" />";
1017+
for (var idname in selection)
1018+
{
1019+
$.each(selection[idname], function () {
1020+
inputs += "<input name=\"" + idname + "\" value=\"" + this + "\" />";
10151021
});
1016-
});
1022+
}
10171023

10181024
$("<form action=\"" + url + "\" method=\"post\">" + inputs + "</form>")
10191025
.appendTo("body").submit().remove();

Griddly/Views/Shared/Griddly/BootstrapButton.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ else
7878
@Html.AttributeIf("data-target", button.Action != GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
7979
@Html.AttributeIf("data-enable-on-selection", button.EnableOnSelection, button.EnableOnSelection.ToString().ToLower())
8080
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
81-
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)>
81+
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
82+
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")>
8283

8384
@if (!string.IsNullOrWhiteSpace(Model.Icon) && GriddlySettings.IconTemplate != null)
8485
{

0 commit comments

Comments
 (0)