Skip to content

Commit c854bdc

Browse files
committed
Merge pull request #60 from programcsharp/feature-editable
Merge in editly
2 parents c899abd + cd51d00 commit c854bdc

23 files changed

+3560
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ obj/
3030
[Dd]ebug*/
3131
[Rr]elease*/
3232
Ankh.NoLoad
33+
.vs/
3334

3435
#Tooling
3536
_ReSharper*/

Build/CommonAssemblyInfo.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
// by using the '*' as shown below:
1818
[assembly: AssemblyVersion("1.4.5")]
1919
[assembly: AssemblyFileVersion("1.4.5")]
20+
[assembly: AssemblyInformationalVersion("1.4.5-editlyalpha2")]

Build/build.proj

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<Libs Include="$(BaseDir)\Griddly.Mvc\bin\$(Configuration)\Griddly.Mvc.dll" />
2727
<Content Include="$(BaseDir)\Griddly\**\griddly.js" />
2828
<Content Include="$(BaseDir)\Griddly\**\griddly.css" />
29-
<Content Include="$(BaseDir)\Griddly\**\Griddly\*.*" />
29+
<Content Include="$(BaseDir)\Griddly\**\Griddly\*.*" />
30+
<Content Include="$(BaseDir)\Griddly\**\editly.js" />
3031
</ItemGroup>
3132

3233
<Exec Command="rd $(PackageDir) /s /q" />

Griddly.Mvc/GriddlyColumn.cs

+29
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public GriddlyColumn()
3131

3232
public GriddlyFilter Filter { get; set; }
3333

34+
public abstract HtmlString RenderUnderlyingValue(object row);
3435
public abstract HtmlString RenderCell(object row, GriddlySettings settings, bool encode = true);
3536
public abstract object RenderCellValue(object row, bool stripHtml = false);
3637

@@ -76,6 +77,7 @@ public virtual HtmlString RenderValue(object value, bool encode = true)
7677
public class GriddlyColumn<TRow> : GriddlyColumn
7778
{
7879
public Func<TRow, object> Template { get; set; }
80+
public Func<TRow, object> UnderlyingValueTemplate { get; set; }
7981
public Func<TRow, string> ClassNameTemplate { get; set; }
8082
public Func<TRow, object> HtmlAttributesTemplate { get; set; }
8183

@@ -155,6 +157,33 @@ public override HtmlString RenderCell(object row, GriddlySettings settings, bool
155157
return RenderValue(value, encode);
156158
}
157159

160+
public override HtmlString RenderUnderlyingValue(object row)
161+
{
162+
if (UnderlyingValueTemplate == null) return null;
163+
164+
object value = null;
165+
166+
try
167+
{
168+
value = UnderlyingValueTemplate((TRow)row);
169+
}
170+
catch (NullReferenceException)
171+
{
172+
// Eat
173+
}
174+
catch (Exception ex)
175+
{
176+
throw new InvalidOperationException("Error rendering underlying value or column \"" + Caption + "\"", ex);
177+
}
178+
179+
if (value == null)
180+
return null;
181+
else if (value is HtmlString)
182+
return (HtmlString)value;
183+
else
184+
return new HtmlString(value.ToString());
185+
}
186+
158187
public override object RenderCellValue(object row, bool stripHtml = false)
159188
{
160189
object value = null;

Griddly.Mvc/GriddlyFilterExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static GriddlyFilterList FilterList(this GriddlyColumn column, IEnumerabl
113113
return filter;
114114
}
115115

116-
static string GetField(GriddlyColumn column)
116+
public static string GetField(GriddlyColumn column)
117117
{
118118
string value = null;
119119

Griddly.Mvc/GriddlySelectColumn.cs

+5
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,10 @@ public override object RenderCellValue(object row, bool stripHtml = false)
5252
{
5353
return null;
5454
}
55+
56+
public override HtmlString RenderUnderlyingValue(object row)
57+
{
58+
return null;
59+
}
5560
}
5661
}

Griddly.Mvc/GriddlySettings.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public GriddlySettings<TRow> RowId(Expression<Func<TRow, object>> expression, st
394394
return this;
395395
}
396396

397-
public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>> expression, string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, bool isExportOnly = false, string width = null, SummaryAggregateFunction? summaryFunction = null, object summaryValue = null, Func<TRow, object> template = null, Func<GriddlyColumn, GriddlyFilter> filter = null, Func<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0)
397+
public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>> expression, string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, bool isExportOnly = false, string width = null, SummaryAggregateFunction? summaryFunction = null, object summaryValue = null, Func<TRow, object> template = null, Func<GriddlyColumn, GriddlyFilter> filter = null, Func<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0, Expression<Func<TRow, object>> value = null)
398398
{
399399
ModelMetadata metadata = null;
400400

@@ -446,6 +446,7 @@ public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>>
446446
if (headerHtmlAttributes != null && !(headerHtmlAttributes is IDictionary<string, object>))
447447
headerHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(headerHtmlAttributes);
448448

449+
var valueTemplate = value == null ? null : value.Compile();
449450
Add(new GriddlyColumn<TRow>()
450451
{
451452
Template = template,
@@ -460,15 +461,16 @@ public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>>
460461
IsExportOnly = isExportOnly,
461462
Width = width,
462463
HtmlAttributesTemplate = htmlAttributes,
463-
HeaderHtmlAttributes = (IDictionary<string, object>)headerHtmlAttributes
464+
HeaderHtmlAttributes = (IDictionary<string, object>)headerHtmlAttributes,
465+
UnderlyingValueTemplate = valueTemplate
464466
}, filter);
465467

466468
return this;
467469
}
468470

469-
public GriddlySettings<TRow> Column(string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, bool isExportOnly = false, string width = null, SummaryAggregateFunction? summaryFunction = null, object summaryValue = null, Func<TRow, object> template = null, Func<GriddlyColumn, GriddlyFilter> filter = null, Func<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0)
471+
public GriddlySettings<TRow> Column(string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, bool isExportOnly = false, string width = null, SummaryAggregateFunction? summaryFunction = null, object summaryValue = null, Func<TRow, object> template = null, Func<GriddlyColumn, GriddlyFilter> filter = null, Func<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0, Expression<Func<TRow, object>> value = null)
470472
{
471-
return Column<object>(null, caption, format, expressionString, defaultSort, className, isExportOnly, width, summaryFunction, summaryValue, template, filter, htmlAttributes, headerHtmlAttributes, defaultSortOrder);
473+
return Column<object>(null, caption, format, expressionString, defaultSort, className, isExportOnly, width, summaryFunction, summaryValue, template, filter, htmlAttributes, headerHtmlAttributes, defaultSortOrder, value);
472474
}
473475

474476
public GriddlySettings<TRow> SelectColumn(Expression<Func<TRow, object>> id, object summaryValue = null)

Griddly/App_Start/BundleConfig.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public class BundleConfig
88
public static void RegisterBundles(BundleCollection bundles)
99
{
1010
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
11-
"~/Scripts/jquery-{version}.js"));
11+
"~/Scripts/jquery-{version}.js",
12+
"~/Scripts/jquery.validate.js",
13+
"~/Scripts/jquery.validate.unobtrusive.js"));
1214

1315
// Use the development version of Modernizr to develop with and learn from. Then, when you're
1416
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.

Griddly/Controllers/HomeController.cs

+40
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,46 @@ public ActionResult HistoryTest()
2121
return View();
2222
}
2323

24+
25+
public ActionResult Editly()
26+
{
27+
return View();
28+
}
29+
30+
public ActionResult EditlyGrid(string item, int? quantityStart, int? quantityEnd, decimal? totalStart, decimal? totalEnd, string firstName, string lastName, bool? isApproved)
31+
{
32+
this.SetGriddlyDefault(ref isApproved, "isApproved", true);
33+
34+
IQueryable<SimpleOrder> query = _indexTestData;
35+
36+
if (!string.IsNullOrWhiteSpace(item))
37+
query = query.Where(x => x.Item.ToLower().Contains(item.ToLower()));
38+
39+
if (quantityStart != null && quantityEnd != null)
40+
query = query.Where(x => x.Quantity >= quantityStart && x.Quantity <= quantityEnd);
41+
if (quantityStart != null)
42+
query = query.Where(x => x.Quantity >= quantityStart);
43+
if (quantityEnd != null)
44+
query = query.Where(x => x.Quantity <= quantityEnd);
45+
46+
if (totalStart != null && totalEnd != null)
47+
query = query.Where(x => x.Total >= totalStart && x.Total <= totalEnd);
48+
if (totalStart != null)
49+
query = query.Where(x => x.Total >= totalStart);
50+
if (totalEnd != null)
51+
query = query.Where(x => x.Total <= totalEnd);
52+
53+
if (!string.IsNullOrWhiteSpace(firstName))
54+
query = query.Where(x => x.Person.FirstName.ToLower().Contains(firstName.ToLower()));
55+
if (!string.IsNullOrWhiteSpace(lastName))
56+
query = query.Where(x => x.Person.LastName.ToLower().Contains(lastName.ToLower()));
57+
58+
if (isApproved != null)
59+
query = query.Where(x => x.IsApproved == isApproved);
60+
61+
return new QueryableResult<SimpleOrder>(query);
62+
}
63+
2464
public GriddlyResult TestGrid(string firstName, int? zipStart, int? zipEnd)
2565
{
2666
IQueryable<TestGridItem> query = _testData;

Griddly/Griddly.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<Content Include="Scripts\bootstrap-multiselect.js" />
171171
<Content Include="Scripts\bootstrap.js" />
172172
<Content Include="Scripts\bootstrap.min.js" />
173+
<Content Include="Scripts\editly.js" />
173174
<Content Include="Scripts\griddly.js" />
174175
<Content Include="Scripts\bootstrap.min.js.map">
175176
<DependentUpon>bootstrap.min.js</DependentUpon>
@@ -187,6 +188,11 @@
187188
<None Include="Scripts\jquery-2.1.0.intellisense.js" />
188189
<Content Include="Scripts\jquery-2.1.0.js" />
189190
<Content Include="Scripts\jquery-2.1.0.min.js" />
191+
<None Include="Scripts\jquery.validate-vsdoc.js" />
192+
<Content Include="Scripts\jquery.validate.js" />
193+
<Content Include="Scripts\jquery.validate.min.js" />
194+
<Content Include="Scripts\jquery.validate.unobtrusive.js" />
195+
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
190196
<Content Include="Scripts\modernizr-2.7.1.js" />
191197
<Content Include="Scripts\npm.js" />
192198
<Content Include="Scripts\respond.js" />
@@ -249,6 +255,8 @@
249255
<Content Include="Views\Home\IndexGrid.cshtml" />
250256
<Content Include="Views\Shared\Griddly\GriddlyFilterInline.cshtml" />
251257
<Content Include="Views\Shared\Griddly\GriddlyFilterForm.cshtml" />
258+
<Content Include="Views\Home\Editly.cshtml" />
259+
<Content Include="Views\Home\EditlyGrid.cshtml" />
252260
<Content Include="Views\Home\HistoryTest.cshtml" />
253261
</ItemGroup>
254262
<ItemGroup>

Griddly/Scripts/_references.js

284 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)