Skip to content

Commit 45d5a99

Browse files
committed
Work on editly:
-upgrade to latest griddly version -refine keyboard & click navigation -fix validation -only show one editor at a time regardless of template -cell underlying value attribute -drop-down value support -parse/format text -save events -implement destroy -bind/unbind independently from create/destroy -transparent editing while paging, filtering, sorting -escape key resets to original value
1 parent 8f4c446 commit 45d5a99

File tree

9 files changed

+291
-177
lines changed

9 files changed

+291
-177
lines changed

Griddly.Mvc/GriddlyColumn.cs

Lines changed: 27 additions & 0 deletions
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,31 @@ 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+
object value = null;
163+
164+
try
165+
{
166+
value = UnderlyingValueTemplate((TRow)row);
167+
}
168+
catch (NullReferenceException)
169+
{
170+
// Eat
171+
}
172+
catch (Exception ex)
173+
{
174+
throw new InvalidOperationException("Error rendering underlying value or column \"" + Caption + "\"", ex);
175+
}
176+
177+
if (value == null)
178+
return null;
179+
else if (value is HtmlString)
180+
return (HtmlString)value;
181+
else
182+
return new HtmlString(value.ToString());
183+
}
184+
158185
public override object RenderCellValue(object row, bool stripHtml = false)
159186
{
160187
object value = null;

Griddly.Mvc/GriddlyFilterExtensions.cs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 6 additions & 4 deletions
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/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public ActionResult EditlyGrid(string item, int? quantityStart, int? quantityEnd
5858
if (isApproved != null)
5959
query = query.Where(x => x.IsApproved == isApproved);
6060

61-
return new GriddlyResult<SimpleOrder>(query);
61+
return new QueryableResult<SimpleOrder>(query);
6262
}
6363

6464
public GriddlyResult TestGrid(string firstName, int? zipStart, int? zipEnd)

0 commit comments

Comments
 (0)