Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RowClickTarget #84

Merged
merged 2 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Griddly.Mvc/GriddlySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public GriddlySettings()
public Func<GriddlySettings, object> InlineFilterTemplate { get; set; }

public Func<object, object> RowClickUrl { get; set; }

/// <summary>
/// The anchor tag target for the <seealso cref="RowClickUrl"/>
/// </summary>
public string RowClickTarget { get; set; }
public string RowClickModal { get; set; }
public Func<object, object> RowClass { get; set; }
public Func<object, object> RowHtmlAttributes { get; set; }
Expand All @@ -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; }
Expand Down
3 changes: 2 additions & 1 deletion Griddly/Scripts/griddly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Griddly/Views/Shared/Griddly/Griddly.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<input class="griddly-init-flag" type="hidden" />
@:<div class="griddly griddly-init @settings.ClassName" data-role="griddly"
@: @Html.AttributeNullable("data-griddly-url", !simple ? Url.Current() : null)
@: @Html.AttributeNullable("data-griddly-urltarget", !simple ? settings.RowClickTarget : null)
@: data-griddly-count="@Model.Total"
@: @Html.AttributeNullable("data-griddly-filtermode", settings.InitialFilterMode != FilterMode.None ? settings.InitialFilterMode.ToString() : null)
@: @Html.AttributeNullable("data-griddly-allowedfiltermodes", settings.AllowedFilterModes != FilterMode.None ? Json.Encode(Enum.GetValues(typeof(FilterMode)).Cast<FilterMode>().Where(x => settings.AllowedFilterModes.Value.HasFlag(x) && x != FilterMode.Both && x != FilterMode.None).Select(x => x.ToString())) : null)
Expand Down Expand Up @@ -191,6 +192,7 @@
@foreach (object row in Model.Data)
{
<tr @Html.AttributeIf("data-griddly-url", settings.RowClickUrl != null, @<text> @settings.RowClickUrl(row) </text> )
@Html.AttributeIf("data-griddly-urltarget", settings.RowClickTarget != null, @<text> @settings.RowClickTarget </text>)
@Html.AttributeIf("class", settings.RowClass != null, @<text> @settings.RowClass(row) </text> )
@Html.AttributeNullable("data-id", TryEval(row, settings.IdProperty))
@foreach (var x in settings.RowIds)
Expand Down