Skip to content

Commit 7cab284

Browse files
committed
Add InputHtmlAttributesTemplate to SelectColumn
Also fix dropbox folder finding in publish script
1 parent 23f088a commit 7cab284

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

Build/CommonAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
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.5.6")]
19-
[assembly: AssemblyFileVersion("1.5.6")]
18+
[assembly: AssemblyVersion("1.5.7")]
19+
[assembly: AssemblyFileVersion("1.5.7")]
2020
//[assembly: AssemblyInformationalVersion("1.4.5-editlyalpha2")]

Build/publish-nuget.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ Function Get-DropBox() {
1111
}
1212
else
1313
{
14-
$hostFile = Join-Path (Split-Path (Get-ItemProperty HKCU:\Software\Dropbox).InstallPath) "host.db"
15-
$encodedPath = [System.Convert]::FromBase64String((Get-Content $hostFile)[1])
16-
[System.Text.Encoding]::UTF8.GetString($encodedPath)
14+
$hostFile = Get-Content -raw -path "$env:LOCALAPPDATA\Dropbox\info.json" | ConvertFrom-Json
15+
$hostFile.personal.path
1716
}
1817
}
1918

Griddly.Mvc/GriddlySelectColumn.cs

+40-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq.Expressions;
55
using System.Web;
66
using System.Web.Mvc;
7+
using System.Web.Routing;
78

89
namespace Griddly.Mvc
910
{
@@ -13,7 +14,12 @@ public GriddlySelectColumn()
1314
{
1415
ClassName = "griddly-select align-center";
1516
}
16-
17+
18+
public virtual IDictionary<string, object> GenerateInputHtmlAttributes(object row)
19+
{
20+
return null;
21+
}
22+
1723
public override HtmlString RenderCell(object row, GriddlySettings settings, bool encode = true)
1824
{
1925
TagBuilder input = new TagBuilder("input");
@@ -45,6 +51,13 @@ public override HtmlString RenderCell(object row, GriddlySettings settings, bool
4551
input.Attributes["data-rowkey"] = key;
4652
}
4753

54+
var inputAttributes = GenerateInputHtmlAttributes(row);
55+
56+
if (inputAttributes != null)
57+
{
58+
input.MergeAttributes(inputAttributes);
59+
}
60+
4861
return new HtmlString(input.ToString(TagRenderMode.SelfClosing));
4962
}
5063

@@ -58,4 +71,30 @@ public override HtmlString RenderUnderlyingValue(object row)
5871
return null;
5972
}
6073
}
74+
75+
public class GriddlySelectColumn<TRow> : GriddlySelectColumn
76+
{
77+
public Func<TRow, object> InputHtmlAttributesTemplate { get; set; }
78+
79+
public override IDictionary<string, object> GenerateInputHtmlAttributes(object row)
80+
{
81+
if (InputHtmlAttributesTemplate == null)
82+
return null;
83+
84+
RouteValueDictionary attributes = new RouteValueDictionary();
85+
86+
object value = InputHtmlAttributesTemplate((TRow)row);
87+
88+
if (value != null)
89+
{
90+
if (!(value is IDictionary<string, object>))
91+
value = HtmlHelper.AnonymousObjectToHtmlAttributes(value);
92+
93+
foreach (KeyValuePair<string, object> entry in (IDictionary<string, object>)value)
94+
attributes.Add(entry.Key, entry.Value);
95+
}
96+
97+
return attributes;
98+
}
99+
}
61100
}

Griddly.Mvc/GriddlySettings.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,14 @@ public GriddlySettings<TRow> Column(string caption = null, string format = null,
482482
return Column<object>(null, caption, format, expressionString, defaultSort, className, isExportOnly, width, summaryFunction, summaryValue, template, filter, htmlAttributes, headerHtmlAttributes, defaultSortOrder, value);
483483
}
484484

485-
public GriddlySettings<TRow> SelectColumn(Expression<Func<TRow, object>> id, object summaryValue = null)
485+
public GriddlySettings<TRow> SelectColumn(Expression<Func<TRow, object>> id, object summaryValue = null, Func<TRow, object> inputHtmlAttributesTemplate = null)
486486
{
487487
RowId(id, "id");
488488

489-
Add(new GriddlySelectColumn()
489+
Add(new GriddlySelectColumn<TRow>()
490490
{
491-
SummaryValue = summaryValue
491+
SummaryValue = summaryValue,
492+
InputHtmlAttributesTemplate = inputHtmlAttributesTemplate
492493
});
493494

494495
return this;

Griddly/Views/Home/TestGrid.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Title = "Row Select Test",
1111
ClassName = "test-grid"
1212
}
13-
.SelectColumn(x => x.Id)
13+
.SelectColumn(x => x.Id, inputHtmlAttributesTemplate: x => new { data_testattr = x.Id })
1414
.RowId(x => x.FirstName)
1515
.RowId(x => x.LastName)
1616
.RowId(x => x.NullThing)

0 commit comments

Comments
 (0)