From 2f688627435b9819f8c216637642b3ddc74dc3eb Mon Sep 17 00:00:00 2001 From: Nick DeVore Date: Thu, 14 Sep 2017 12:13:49 -0700 Subject: [PATCH] #83 Add RowClickTarget --- Griddly.Mvc/GriddlySettings.cs | 10 ++++++++++ Griddly/Scripts/griddly.js | 3 ++- Griddly/Views/Shared/Griddly/Griddly.cshtml | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Griddly.Mvc/GriddlySettings.cs b/Griddly.Mvc/GriddlySettings.cs index e3bc8fd..5daeffe 100644 --- a/Griddly.Mvc/GriddlySettings.cs +++ b/Griddly.Mvc/GriddlySettings.cs @@ -85,6 +85,11 @@ public GriddlySettings() public Func InlineFilterTemplate { get; set; } public Func RowClickUrl { get; set; } + + /// + /// The anchor tag target for the + /// + public string RowClickTarget { get; set; } public string RowClickModal { get; set; } public Func RowClass { get; set; } public Func RowHtmlAttributes { get; set; } @@ -99,6 +104,11 @@ public virtual bool HasRowClickUrl get { return RowClickUrl != null; } } + public virtual bool HasRowClickTarget + { + get { return !string.IsNullOrWhiteSpace(RowClickTarget); } + } + public virtual bool HasRowClass { get { return RowClass != null; } diff --git a/Griddly/Scripts/griddly.js b/Griddly/Scripts/griddly.js index e993352..2dad120 100644 --- a/Griddly/Scripts/griddly.js +++ b/Griddly/Scripts/griddly.js @@ -325,6 +325,7 @@ $(this.$element).on("mouseup", "tbody.data tr td:not(:has(input))", $.proxy(function (e) { var url = $.trim($(e.target).parents("tr").data("griddly-url")); + var target = $.trim($(e.target).parents("tr").data("griddly-urltarget")); if (url && $(e.target).closest("a").length == 0) { @@ -338,7 +339,7 @@ } else { - if (e.which == 2 || e.ctrlKey) + if (e.which == 2 || e.ctrlKey || target == "_blank") window.open(url); else if (e.which != 3) window.location = url; diff --git a/Griddly/Views/Shared/Griddly/Griddly.cshtml b/Griddly/Views/Shared/Griddly/Griddly.cshtml index 05feb09..7778b71 100644 --- a/Griddly/Views/Shared/Griddly/Griddly.cshtml +++ b/Griddly/Views/Shared/Griddly/Griddly.cshtml @@ -90,6 +90,7 @@ @:
().Where(x => settings.AllowedFilterModes.Value.HasFlag(x) && x != FilterMode.Both && x != FilterMode.None).Select(x => x.ToString())) : null) @@ -191,6 +192,7 @@ @foreach (object row in Model.Data) { @settings.RowClickUrl(row) ) + @Html.AttributeIf("data-griddly-urltarget", settings.RowClickTarget != null, @ @settings.RowClickTarget ) @Html.AttributeIf("class", settings.RowClass != null, @ @settings.RowClass(row) ) @Html.AttributeNullable("data-id", TryEval(row, settings.IdProperty)) @foreach (var x in settings.RowIds)