Skip to content

Commit 6f6697c

Browse files
committed
Buttons now clear selection on action by default
1 parent ca34072 commit 6f6697c

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

Griddly.Mvc/GriddlyButton.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public GriddlyButton(string additionalClassName = null)
1212

1313
Enabled = true;
1414
Action = GriddlyButtonAction.Navigate;
15+
ClearSelectionOnAction = true;
1516

1617
ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
1718
}
@@ -23,6 +24,12 @@ public GriddlyButton(string additionalClassName = null)
2324
public bool EnableOnSelection { get; set; }
2425
public bool IsSeparator { get; set; }
2526
public bool IsSplitDropdown { get; set; }
27+
28+
/// <summary>
29+
/// Clear the current row selections after this button is activated (default: true)
30+
/// </summary>
31+
public bool ClearSelectionOnAction { get; set; }
32+
2633
public string Text { get; set; }
2734
public string Title { get; set; }
2835
public string Icon { get; set; }

Griddly/Scripts/griddly.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,12 @@
356356
{
357357
var last = $("tbody tr", this.$element).index(this.options.lastSelectedRow);
358358
var first = $("tbody tr", this.$element).index($target.parents("tr"));
359+
var newstate = this.options.lastSelectedRow.find("input[name=_rowselect]").prop("checked");
359360

360361
var start = Math.min(first, last);
361362
var end = Math.max(first, last);
362363

363-
$("tbody tr", this.$element).slice(start, end).find("input[name=_rowselect]").prop("checked", true);
364+
$("tbody tr", this.$element).slice(start, end).find("input[name=_rowselect]").each(function () { $(this).prop("checked", newstate); setRowSelect($(this)) });
364365
}
365366

366367
this.options.lastSelectedRow = $target.parents("tr");
@@ -378,12 +379,8 @@
378379

379380
$(this.$element).on("click", "thead tr .griddly-selection-clear", $.proxy(function (event)
380381
{
381-
this.options.selectedRows = {};
382-
383-
$("tbody tr", this.$element).find("input[name=_rowselect]").prop("checked", false);
384-
382+
this.clearSelected();
385383
onRowChange();
386-
this.setSelectedCount();
387384
}, this));
388385

389386
$("a.export-xlsx", this.$element).on("click", $.proxy(function (e) {
@@ -893,6 +890,15 @@
893890
return result;
894891
},
895892

893+
clearSelected: function()
894+
{
895+
this.options.selectedRows = {};
896+
897+
$("tbody tr", this.$element).find("input[name=_rowselect]").prop("checked", false);
898+
899+
this.setSelectedCount();
900+
},
901+
896902
pageNumber: function(pageNumber)
897903
{
898904
if (pageNumber >= 0 && pageNumber < this.options.pageCount)
@@ -970,6 +976,7 @@
970976
var onclick = button.data("onclick");
971977
var confirmMessage = button.data("confirm-message");
972978
var enableOnSelection = button.data("enable-on-selection");
979+
var clearSelectionOnAction = button.data("clear-selection-on-action");
973980
var rowIds = button.data("rowids");
974981

975982
if ((typeof confirmMessage === "undefined" || confirm(confirmMessage)))
@@ -993,6 +1000,11 @@
9931000
}
9941001
}
9951002

1003+
if (clearSelectionOnAction)
1004+
{
1005+
griddly.griddly("clearSelected");
1006+
}
1007+
9961008
switch (toggle)
9971009
{
9981010
case "ajaxbulk":
@@ -1027,7 +1039,14 @@
10271039

10281040
if ($.isFunction(f))
10291041
{
1030-
return f.call(button, rowIds);
1042+
var result = f.call(button, rowIds);
1043+
1044+
if (clearSelectionOnAction)
1045+
{
1046+
griddly.griddly("clearSelected");
1047+
}
1048+
1049+
return result;
10311050
}
10321051

10331052
throw "onclick must be a global function";
@@ -1096,7 +1115,7 @@
10961115
.appendTo("body").submit().remove();
10971116
};
10981117

1099-
GriddlyButton.ajax = function (url, selection, button, griddly)
1118+
GriddlyButton.ajax = function (url, selection, button, griddly, clearSelection)
11001119
{
11011120
for (var i = 0; i < selection[Object.keys(selection)[0]].length; i++)
11021121
{

Griddly/Views/Shared/Griddly/BootstrapButton.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ else
7777
@Html.AttributeIf("data-url", button.Action == GriddlyButtonAction.Ajax || button.Action == GriddlyButtonAction.AjaxBulk || button.Action == GriddlyButtonAction.Post || button.Action == GriddlyButtonAction.PostCriteria, button.Argument)
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())
80+
@Html.AttributeIf("data-clear-selection-on-action", button.ClearSelectionOnAction, button.ClearSelectionOnAction.ToString().ToLower())
8081
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
8182
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
8283
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")

0 commit comments

Comments
 (0)