Skip to content

Commit c89b888

Browse files
committed
Refactor IsExportOnly to RenderMode
1 parent ac8da0b commit c89b888

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

Griddly.Mvc/GriddlyColumn.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public abstract class GriddlyColumn
1515
public GriddlyColumn()
1616
{
1717
HeaderHtmlAttributes = new RouteValueDictionary();
18+
19+
RenderMode = ColumnRenderMode.Both;
1820
}
1921

2022
public string Caption { get; set; }
@@ -24,7 +26,7 @@ public GriddlyColumn()
2426
public int DefaultSortOrder { get; set; }
2527
public string ClassName { get; set; }
2628
public string Width { get; set; }
27-
public bool IsExportOnly { get; set; }
29+
public ColumnRenderMode RenderMode { get; set; }
2830
public SummaryAggregateFunction? SummaryFunction { get; set; }
2931
public object SummaryValue { get; set; }
3032
public IDictionary<string, object> HeaderHtmlAttributes { get; set; }
@@ -228,4 +230,11 @@ public enum SummaryAggregateFunction
228230
Min = 3,
229231
Max = 4
230232
}
233+
234+
public enum ColumnRenderMode
235+
{
236+
View = 1 << 0,
237+
Export = 1 << 1,
238+
Both = View | Export
239+
}
231240
}

Griddly.Mvc/GriddlyCsvResult.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ public override void ExecuteResult(ControllerContext context)
3434
{
3535
var export = _settings.Exports.FirstOrDefault(x => x.Name == _exportName);
3636
var columns = export == null ? _settings.Columns : export.Columns;
37-
if (export != null && export.UseGridColumns) columns.InsertRange(0, _settings.Columns);
3837

38+
if (export != null && export.UseGridColumns)
39+
columns.InsertRange(0, _settings.Columns);
40+
41+
columns.RemoveAll(x => !x.RenderMode.HasFlag(ColumnRenderMode.Export));
3942

4043
for (int i = 0; i < columns.Count; i++)
4144
w.WriteField(columns[i].Caption);

Griddly.Mvc/GriddlyExcelResult.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public override void ExecuteResult(ControllerContext context)
3232

3333
var export = _settings.Exports.FirstOrDefault(x => x.Name == _exportName);
3434
var columns = export == null ? _settings.Columns : export.Columns;
35-
if (export != null && export.UseGridColumns) columns.InsertRange(0, _settings.Columns);
35+
36+
if (export != null && export.UseGridColumns)
37+
columns.InsertRange(0, _settings.Columns);
38+
39+
columns.RemoveAll(x => !x.RenderMode.HasFlag(ColumnRenderMode.Export));
3640

3741
for (int i = 0; i < columns.Count; i++)
3842
{

Griddly.Mvc/GriddlyExport.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public GriddlyExport(string name, bool useGridColumns = false)
2929
: base(name, useGridColumns)
3030
{
3131
}
32-
public GriddlyExport<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<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0, Expression<Func<TRow, object>> value = null)
32+
public GriddlyExport<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>> expression, string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, ColumnRenderMode renderMode = ColumnRenderMode.Both, string width = null, SummaryAggregateFunction? summaryFunction = null, object summaryValue = null, Func<TRow, object> template = null, Func<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0, Expression<Func<TRow, object>> value = null)
3333
{
3434
ModelMetadata metadata = null;
3535

@@ -93,7 +93,7 @@ public GriddlyExport<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>> e
9393
DefaultSort = defaultSort,
9494
DefaultSortOrder = defaultSortOrder,
9595
ClassName = className,
96-
IsExportOnly = isExportOnly,
96+
RenderMode = renderMode,
9797
Width = width,
9898
HtmlAttributesTemplate = htmlAttributes,
9999
HeaderHtmlAttributes = (IDictionary<string, object>)headerHtmlAttributes,
@@ -103,9 +103,9 @@ public GriddlyExport<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>> e
103103
return this;
104104
}
105105

106-
public GriddlyExport<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<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0, Expression<Func<TRow, object>> value = null)
106+
public GriddlyExport<TRow> Column(string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, ColumnRenderMode renderMode = ColumnRenderMode.Both, string width = null, SummaryAggregateFunction? summaryFunction = null, object summaryValue = null, Func<TRow, object> template = null, Func<TRow, object> htmlAttributes = null, object headerHtmlAttributes = null, int defaultSortOrder = 0, Expression<Func<TRow, object>> value = null)
107107
{
108-
return Column<object>(null, caption, format, expressionString, defaultSort, className, isExportOnly, width, summaryFunction, summaryValue, template, htmlAttributes, headerHtmlAttributes, defaultSortOrder, value);
108+
return Column<object>(null, caption, format, expressionString, defaultSort, className, renderMode, width, summaryFunction, summaryValue, template, htmlAttributes, headerHtmlAttributes, defaultSortOrder, value);
109109
}
110110
}
111111
}

Griddly.Mvc/GriddlySettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public GriddlySettings<TRow> RowId(Expression<Func<TRow, object>> expression, st
403403
return this;
404404
}
405405

406-
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)
406+
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, ColumnRenderMode renderMode = ColumnRenderMode.Both, 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)
407407
{
408408
ModelMetadata metadata = null;
409409

@@ -467,7 +467,7 @@ public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>>
467467
DefaultSort = defaultSort,
468468
DefaultSortOrder = defaultSortOrder,
469469
ClassName = className,
470-
IsExportOnly = isExportOnly,
470+
RenderMode = renderMode,
471471
Width = width,
472472
HtmlAttributesTemplate = htmlAttributes,
473473
HeaderHtmlAttributes = (IDictionary<string, object>)headerHtmlAttributes,
@@ -477,9 +477,9 @@ public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>>
477477
return this;
478478
}
479479

480-
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)
480+
public GriddlySettings<TRow> Column(string caption = null, string format = null, string expressionString = null, SortDirection? defaultSort = null, string className = null, ColumnRenderMode renderMode = ColumnRenderMode.Both, 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)
481481
{
482-
return Column<object>(null, caption, format, expressionString, defaultSort, className, isExportOnly, width, summaryFunction, summaryValue, template, filter, htmlAttributes, headerHtmlAttributes, defaultSortOrder, value);
482+
return Column<object>(null, caption, format, expressionString, defaultSort, className, renderMode, width, summaryFunction, summaryValue, template, filter, htmlAttributes, headerHtmlAttributes, defaultSortOrder, value);
483483
}
484484

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

Griddly/Views/Shared/Griddly/Griddly.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@{
1515
GriddlySettings settings = (GriddlySettings)ViewBag.settings;
1616

17-
settings.Columns.RemoveAll(x => x.IsExportOnly);
17+
settings.Columns.RemoveAll(x => !x.RenderMode.HasFlag(ColumnRenderMode.View));
1818

1919
bool simple = ViewBag.isSimpleGriddly == true;
2020
bool isFirstRender = ViewContext.Controller.ControllerContext.IsChildAction || simple;

0 commit comments

Comments
 (0)