Skip to content

Commit

Permalink
Added grid defaults object. Turned on preloading by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Harrison committed Feb 11, 2015
1 parent 07d46c4 commit 49838cf
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 90 deletions.
1 change: 0 additions & 1 deletion MVCGrid/Interfaces/IMVCGridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace MVCGrid.Interfaces
internal interface IMVCGridDefinition
{
IEnumerable<IMVCGridColumn> GetColumns();
GridConfiguration GridConfiguration { get; }
string QueryStringPrefix { get; }
bool PreloadData { get; }
bool Paging { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion MVCGrid/MVCGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Compile Include="Interfaces\IMVCGridColumn.cs" />
<Compile Include="Interfaces\IMVCGridDefinition.cs" />
<Compile Include="Models\GridColumn.cs" />
<Compile Include="Models\GridConfiguration.cs" />
<Compile Include="Models\GridDefaults.cs" />
<Compile Include="Models\QueryResult.cs" />
<Compile Include="Models\GridDefinition.cs" />
<Compile Include="Models\SortDirection.cs" />
Expand Down
34 changes: 0 additions & 34 deletions MVCGrid/Models/GridConfiguration.cs

This file was deleted.

35 changes: 35 additions & 0 deletions MVCGrid/Models/GridDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MVCGrid.Models
{
public class GridDefaults
{
public GridDefaults()
{
PreloadData = true;
Paging = false;
ItemsPerPage = 20;
Sorting = false;
DefaultSortColumn = null;
NoResultsMessage = "No results.";
ClientSideLoadingMessageFunctionName = null;
ClientSideLoadingCompleteFunctionName = null;
Filtering = false;
DefaultRenderingEngine = typeof(MVCGrid.Rendering.BootstrapRenderingEngine);
}

public bool PreloadData { get; set; }
public bool Paging { get; set; }
public int ItemsPerPage { get; set; }
public bool Sorting { get; set; }
public string DefaultSortColumn { get; set; }
public string NoResultsMessage { get; set; }
public string ClientSideLoadingMessageFunctionName { get; set; }
public string ClientSideLoadingCompleteFunctionName { get; set; }
public bool Filtering { get; set; }
public Type DefaultRenderingEngine { get; set; }
}
}
47 changes: 17 additions & 30 deletions MVCGrid/Models/GridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,32 @@ public abstract class GridDefinitionBase

public class GridDefinition<T1> : GridDefinitionBase, IMVCGridDefinition
{
private Type _defaultRenderingEngine;
const string DefaultNoResultsMessage = "No results.";

public GridDefinition() : this(null)
public GridDefinition() : this(new GridDefaults())
{
}

public GridDefinition(GridConfiguration copyFromConfig):base()
public GridDefinition(GridDefaults gridDefaults):base()
{
if (copyFromConfig != null)
Columns = new List<GridColumn<T1>>();

if (gridDefaults != null)
{
GridConfiguration = GridConfiguration.CopyFrom(copyFromConfig);
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.DefaultRenderingEngine = gridDefaults.DefaultRenderingEngine;
}

Columns = new List<GridColumn<T1>>();
NoResultsMessage = DefaultNoResultsMessage;
_defaultRenderingEngine = typeof(MVCGrid.Rendering.BootstrapRenderingEngine);
}

public GridConfiguration GridConfiguration { get; set; }

public IEnumerable<IMVCGridColumn> GetColumns()
{
List<IMVCGridColumn> interfaceList = new List<IMVCGridColumn>();
foreach (var col in Columns)
{
interfaceList.Add(col);
}
return interfaceList;
return Columns.Cast<IMVCGridColumn>();
}

public void AddColumn(GridColumn<T1> column)
Expand Down Expand Up @@ -153,17 +150,7 @@ internal override List<Row> GetData(GridContext context, out int? totalRecords)
public string ClientSideLoadingMessageFunctionName { get; set; }
public string ClientSideLoadingCompleteFunctionName { get; set; }

public Type DefaultRenderingEngine
{
get
{
return _defaultRenderingEngine;
}
set
{
_defaultRenderingEngine = value;
}
}
public Type DefaultRenderingEngine { get; set; }
}

}
2 changes: 0 additions & 2 deletions MVCGrid/Web/MVCGridHtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ internal static string GenerateBasePageHtml(string gridName, IMVCGridDefinition
sbJson.Append("}");
//mvcGridName, qsPrefix: qsPrefix, preloaded: preload }

GridConfiguration config = def.GridConfiguration;

StringBuilder sbHtml = new StringBuilder();

sbHtml.AppendFormat("<div id='{0}' class='{1}'>", HtmlUtility.GetContainerHtmlId(gridName), HtmlUtility.ContainerCssClass);
Expand Down
12 changes: 1 addition & 11 deletions MVCGridExample/App_Start/MVCGridConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class MVCGridConfig
{
public static void RegisterGrids()
{
GridConfiguration globalConfig = SetupGlobalConfiguration();

MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>()
.AddColumns(cols =>
{
Expand Down Expand Up @@ -349,7 +347,7 @@ public static void RegisterGrids()
.WithHeaderText("Last Name")
.WithValueExpression((p, c) => p.LastName);
})
.WithPreloadData(true)
.WithPreloadData(false)
.WithSorting(true)
.WithDefaultSortColumn("LastName")
.WithPaging(true)
Expand Down Expand Up @@ -721,13 +719,5 @@ public static void RegisterGrids()

//MVCGridDefinitionTable.Add DO NOT DELETE - Needed for demo code parsing
}

private static GridConfiguration SetupGlobalConfiguration()
{
GridConfiguration globalConfig = new GridConfiguration();
globalConfig.ItemsPerPage = 10;
globalConfig.TableCssClasses = new HashSet<string>() { "table", "table-striped", "table-bordered" };
return globalConfig;
}
}
}
10 changes: 0 additions & 10 deletions MVCGridExample/Content/MVCGridConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace MVCGridExample
{
public static void RegisterGrids()
{
GridConfiguration globalConfig = SetupGlobalConfiguration();

MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>()
.AddColumns(cols =>
{
Expand Down Expand Up @@ -721,13 +719,5 @@ namespace MVCGridExample

//MVCGridDefinitionTable.Add DO NOT DELETE - Needed for demo code parsing
}

private static GridConfiguration SetupGlobalConfiguration()
{
GridConfiguration globalConfig = new GridConfiguration();
globalConfig.ItemsPerPage = 10;
globalConfig.TableCssClasses = new HashSet<string>() { "table", "table-striped", "table-bordered" };
return globalConfig;
}
}
}
1 change: 1 addition & 0 deletions MVCGridExample/Views/Demo/Preloading.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<h2>@ViewBag.Title</h2>

<p>With preloading turned on, the initial ajax call is not needed and the data will be loaded when the page loads. Subsequent calls are done with ajax.</p>
<p>Preloading is on by default. Below is an example of a grid with preloading turned off. If you refresh the page, you should see that an initial ajax call is made to load the table for the first time.</p>

@Html.MVCGrid("Preloading")

Expand Down
2 changes: 1 addition & 1 deletion MVCGridExample/Views/GettingStarted/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ul>
<li>MVC 3 or greater</li>
<li>jQuery</li>
<li>Bootstrap 3</li>
<li>Bootstrap 3 (Or you can create your own custom style.)</li>
</ul>

<h2>Installation</h2>
Expand Down

0 comments on commit 49838cf

Please sign in to comment.