Skip to content

Commit

Permalink
added column defaults and tweaked demos
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Harrison committed Feb 25, 2015
1 parent a8aa188 commit ff04719
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 72 deletions.
1 change: 1 addition & 0 deletions MVCGrid/MVCGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Engine\GridEngine.cs" />
<Compile Include="Interfaces\IMVCGridRenderingEngine.cs" />
<Compile Include="Interfaces\IMVCGridTemplatingEngine.cs" />
<Compile Include="Models\ColumnDefaults.cs" />
<Compile Include="Models\ColumnVisibility.cs" />
<Compile Include="Models\MVCGridBuilder.cs" />
<Compile Include="Models\GridColumnBuilder.cs" />
Expand Down
32 changes: 32 additions & 0 deletions MVCGrid/Models/ColumnDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MVCGrid.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MVCGrid.Models
{
public class ColumnDefaults : IMVCGridColumn
{
public ColumnDefaults()
{
ColumnName = null;
HeaderText = null;
EnableSorting = false;
HtmlEncode = true;
EnableFiltering = false;
Visible = true;
SortColumnData = null;
AllowChangeVisibility = false;
}

public string ColumnName { get; set; }
public string HeaderText { get; set; }
public bool EnableSorting { get; set; }
public bool HtmlEncode { get; set; }
public bool EnableFiltering { get; set; }
public bool Visible { get; set; }
public object SortColumnData { get; set; }
public bool AllowChangeVisibility { get; set; }
}
}
24 changes: 19 additions & 5 deletions MVCGrid/Models/GridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ public class GridColumn<T1> : IMVCGridColumn
private string _headerText = null;

public GridColumn()
: this(null, null, null)
: this(null, null, null, null)
{
}

public GridColumn(string columnName, string headerText, Func<T1, GridContext, string> valueExpression)
:this(columnName, headerText, valueExpression, null)
{

}

public GridColumn(string columnName, string headerText, Func<T1, GridContext, string> valueExpression, ColumnDefaults columnDefaults)
{
if (!String.IsNullOrWhiteSpace(columnName))
{
Expand All @@ -32,10 +38,18 @@ public GridColumn(string columnName, string headerText, Func<T1, GridContext, st
this.ValueExpression = valueExpression;
}

EnableSorting = false;
HtmlEncode = true;
EnableFiltering = false;
Visible = true;
if (columnDefaults == null)
{
columnDefaults = new ColumnDefaults();
}

EnableSorting = columnDefaults.EnableSorting;
HtmlEncode = columnDefaults.HtmlEncode;
EnableFiltering = columnDefaults.EnableFiltering;
Visible = columnDefaults.Visible;
SortColumnData = columnDefaults.SortColumnData;
AllowChangeVisibility = columnDefaults.AllowChangeVisibility;

}

/// <summary>
Expand Down
24 changes: 20 additions & 4 deletions MVCGrid/Models/GridColumnBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ namespace MVCGrid.Models
{
public class GridColumnListBuilder<T1>
{
private ColumnDefaults _columnDefaults = null;

public GridColumnListBuilder()
: this(null)
{
}

public GridColumnListBuilder(ColumnDefaults columnDefaults)
{
ColumnBuilders = new List<GridColumnBuilder<T1>>();

_columnDefaults = columnDefaults;
}

public List<GridColumnBuilder<T1>> ColumnBuilders { get; set; }
Expand All @@ -26,7 +35,7 @@ public GridColumnBuilder<T1> Add(string columnName)

public GridColumnBuilder<T1> Add(string columnName, string headerText, Func<T1, GridContext, string> valueExpression)
{
GridColumnBuilder<T1> col = new GridColumnBuilder<T1>(columnName, headerText, valueExpression);
GridColumnBuilder<T1> col = new GridColumnBuilder<T1>(columnName, headerText, valueExpression, _columnDefaults);

ColumnBuilders.Add(col);

Expand All @@ -44,18 +53,25 @@ public GridColumnBuilder<T1> Add(GridColumn<T1> column)

public class GridColumnBuilder<T1>
{
public GridColumnBuilder():this(null,null,null)
public GridColumnBuilder()
: this(null, null, null, null)
{
}

public GridColumnBuilder(string columnName)
: this(columnName, null, null)
: this(columnName, null, null, null)
{
}

public GridColumnBuilder(string columnName, string headerText, Func<T1, GridContext, string> valueExpression)
:this(columnName, headerText, valueExpression, null)
{

}

public GridColumnBuilder(string columnName, string headerText, Func<T1, GridContext, string> valueExpression, ColumnDefaults columnDefaults)
{
GridColumn = new GridColumn<T1>(columnName, headerText, valueExpression);
GridColumn = new GridColumn<T1>(columnName, headerText, valueExpression, columnDefaults);
}

public GridColumn<T1> GridColumn { get; set; }
Expand Down
47 changes: 25 additions & 22 deletions MVCGrid/Models/GridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,39 @@ public abstract class GridDefinitionBase

public class GridDefinition<T1> : GridDefinitionBase, IMVCGridDefinition
{
public GridDefinition() : this(new GridDefaults())
public GridDefinition() : this(null)
{
}

public GridDefinition(GridDefaults gridDefaults):base()
public GridDefinition(GridDefaults gridDefaults)
: base()
{
Columns = new List<GridColumn<T1>>();

if (gridDefaults != null)
if (gridDefaults == null)
{
this.PreloadData = gridDefaults.PreloadData;
this.Paging = gridDefaults.Paging;
this.ItemsPerPage = gridDefaults.ItemsPerPage;
this.Sorting = gridDefaults.Sorting;
this.DefaultSortColumn = gridDefaults.DefaultSortColumn;
this.NoResultsMessage = gridDefaults.NoResultsMessage;
this.ClientSideLoadingMessageFunctionName = gridDefaults.ClientSideLoadingMessageFunctionName;
this.ClientSideLoadingCompleteFunctionName = gridDefaults.ClientSideLoadingCompleteFunctionName;
this.Filtering = gridDefaults.Filtering;
this.RenderingEngine = gridDefaults.RenderingEngine;
this.TemplatingEngine = gridDefaults.TemplatingEngine;
this.AdditionalSettings = gridDefaults.AdditionalSettings;
this.RenderingMode = gridDefaults.RenderingMode;
this.ViewPath = gridDefaults.ViewPath;
this.QueryStringPrefix = gridDefaults.QueryStringPrefix;
this.ErrorMessageHtml = gridDefaults.ErrorMessageHtml;
this.AdditionalQueryOptionNames = gridDefaults.AdditionalQueryOptionNames;
this.AllowChangingPageSize = gridDefaults.AllowChangingPageSize;
this.MaxItemsPerPage = gridDefaults.MaxItemsPerPage;
gridDefaults = new GridDefaults();
}
this.PreloadData = gridDefaults.PreloadData;
this.Paging = gridDefaults.Paging;
this.ItemsPerPage = gridDefaults.ItemsPerPage;
this.Sorting = gridDefaults.Sorting;
this.DefaultSortColumn = gridDefaults.DefaultSortColumn;
this.NoResultsMessage = gridDefaults.NoResultsMessage;
this.ClientSideLoadingMessageFunctionName = gridDefaults.ClientSideLoadingMessageFunctionName;
this.ClientSideLoadingCompleteFunctionName = gridDefaults.ClientSideLoadingCompleteFunctionName;
this.Filtering = gridDefaults.Filtering;
this.RenderingEngine = gridDefaults.RenderingEngine;
this.TemplatingEngine = gridDefaults.TemplatingEngine;
this.AdditionalSettings = gridDefaults.AdditionalSettings;
this.RenderingMode = gridDefaults.RenderingMode;
this.ViewPath = gridDefaults.ViewPath;
this.QueryStringPrefix = gridDefaults.QueryStringPrefix;
this.ErrorMessageHtml = gridDefaults.ErrorMessageHtml;
this.AdditionalQueryOptionNames = gridDefaults.AdditionalQueryOptionNames;
this.AllowChangingPageSize = gridDefaults.AllowChangingPageSize;
this.MaxItemsPerPage = gridDefaults.MaxItemsPerPage;

}

public IEnumerable<IMVCGridColumn> GetColumns()
Expand Down
16 changes: 15 additions & 1 deletion MVCGrid/Models/MVCGridBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,28 @@ namespace MVCGrid.Models
{
public class MVCGridBuilder<T1>
{
ColumnDefaults _columnDefaults = null;

public MVCGridBuilder()
{
GridDefinition = new GridDefinition<T1>();
}

public MVCGridBuilder(GridDefaults gridDefaults)
: this(gridDefaults, null)
{
}

public MVCGridBuilder(ColumnDefaults columnDefaults)
: this(null, columnDefaults)
{
}

public MVCGridBuilder(GridDefaults gridDefaults, ColumnDefaults columnDefaults)
{
GridDefinition = new GridDefinition<T1>(gridDefaults);

_columnDefaults = columnDefaults;
}

public GridDefinition<T1> GridDefinition { get; set; }
Expand All @@ -38,7 +52,7 @@ public MVCGridBuilder<T1> AddColumn(string name, string headerText, Func<T1, Gri

public MVCGridBuilder<T1> AddColumns(Action<GridColumnListBuilder<T1>> columns)
{
GridColumnListBuilder<T1> cols=new GridColumnListBuilder<T1>();
GridColumnListBuilder<T1> cols = new GridColumnListBuilder<T1>(_columnDefaults);
columns.Invoke(cols);

foreach (var col in cols.ColumnBuilders)
Expand Down
Loading

0 comments on commit ff04719

Please sign in to comment.