diff --git a/MVCGrid/Interfaces/IMVCGridDefinition.cs b/MVCGrid/Interfaces/IMVCGridDefinition.cs index 494d3e0..6d667e7 100644 --- a/MVCGrid/Interfaces/IMVCGridDefinition.cs +++ b/MVCGrid/Interfaces/IMVCGridDefinition.cs @@ -9,7 +9,6 @@ namespace MVCGrid.Interfaces internal interface IMVCGridDefinition { IEnumerable GetColumns(); - GridConfiguration GridConfiguration { get; } string QueryStringPrefix { get; } bool PreloadData { get; } bool Paging { get; set; } diff --git a/MVCGrid/MVCGrid.csproj b/MVCGrid/MVCGrid.csproj index 0ccf9b9..863d0b0 100644 --- a/MVCGrid/MVCGrid.csproj +++ b/MVCGrid/MVCGrid.csproj @@ -62,7 +62,7 @@ - + diff --git a/MVCGrid/Models/GridConfiguration.cs b/MVCGrid/Models/GridConfiguration.cs deleted file mode 100644 index 111e024..0000000 --- a/MVCGrid/Models/GridConfiguration.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MVCGrid.Models -{ - public class GridConfiguration - { - public GridConfiguration() - { - TableCssClasses = new HashSet(); - ItemsPerPage = 20; - } - - public HashSet TableCssClasses { get; set; } - - public int ItemsPerPage { get; set; } - - public static GridConfiguration CopyFrom(GridConfiguration sourceConfig) - { - GridConfiguration destConfig = new GridConfiguration(); - - foreach (string item in sourceConfig.TableCssClasses) - { - destConfig.TableCssClasses.Add(item); - } - - destConfig.ItemsPerPage = sourceConfig.ItemsPerPage; - - return destConfig; - } - } -} diff --git a/MVCGrid/Models/GridDefaults.cs b/MVCGrid/Models/GridDefaults.cs new file mode 100644 index 0000000..e9c71b9 --- /dev/null +++ b/MVCGrid/Models/GridDefaults.cs @@ -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; } + } +} diff --git a/MVCGrid/Models/GridDefinition.cs b/MVCGrid/Models/GridDefinition.cs index 98df8fd..8b36995 100644 --- a/MVCGrid/Models/GridDefinition.cs +++ b/MVCGrid/Models/GridDefinition.cs @@ -15,35 +15,32 @@ public abstract class GridDefinitionBase public class GridDefinition : 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>(); + + 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>(); - NoResultsMessage = DefaultNoResultsMessage; - _defaultRenderingEngine = typeof(MVCGrid.Rendering.BootstrapRenderingEngine); } - public GridConfiguration GridConfiguration { get; set; } - public IEnumerable GetColumns() { - List interfaceList = new List(); - foreach (var col in Columns) - { - interfaceList.Add(col); - } - return interfaceList; + return Columns.Cast(); } public void AddColumn(GridColumn column) @@ -153,17 +150,7 @@ internal override List 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; } } } diff --git a/MVCGrid/Web/MVCGridHtmlGenerator.cs b/MVCGrid/Web/MVCGridHtmlGenerator.cs index 678312b..59f9350 100644 --- a/MVCGrid/Web/MVCGridHtmlGenerator.cs +++ b/MVCGrid/Web/MVCGridHtmlGenerator.cs @@ -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("
", HtmlUtility.GetContainerHtmlId(gridName), HtmlUtility.ContainerCssClass); diff --git a/MVCGridExample/App_Start/MVCGridConfig.cs b/MVCGridExample/App_Start/MVCGridConfig.cs index 70f9e5a..8af92d9 100644 --- a/MVCGridExample/App_Start/MVCGridConfig.cs +++ b/MVCGridExample/App_Start/MVCGridConfig.cs @@ -15,8 +15,6 @@ public class MVCGridConfig { public static void RegisterGrids() { - GridConfiguration globalConfig = SetupGlobalConfiguration(); - MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder() .AddColumns(cols => { @@ -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) @@ -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() { "table", "table-striped", "table-bordered" }; - return globalConfig; - } } } \ No newline at end of file diff --git a/MVCGridExample/Content/MVCGridConfig.txt b/MVCGridExample/Content/MVCGridConfig.txt index 70f9e5a..eefc5dd 100644 --- a/MVCGridExample/Content/MVCGridConfig.txt +++ b/MVCGridExample/Content/MVCGridConfig.txt @@ -15,8 +15,6 @@ namespace MVCGridExample { public static void RegisterGrids() { - GridConfiguration globalConfig = SetupGlobalConfiguration(); - MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder() .AddColumns(cols => { @@ -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() { "table", "table-striped", "table-bordered" }; - return globalConfig; - } } } \ No newline at end of file diff --git a/MVCGridExample/Views/Demo/Preloading.cshtml b/MVCGridExample/Views/Demo/Preloading.cshtml index 1bca992..956f9f4 100644 --- a/MVCGridExample/Views/Demo/Preloading.cshtml +++ b/MVCGridExample/Views/Demo/Preloading.cshtml @@ -6,6 +6,7 @@

@ViewBag.Title

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.

+

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.

@Html.MVCGrid("Preloading") diff --git a/MVCGridExample/Views/GettingStarted/Index.cshtml b/MVCGridExample/Views/GettingStarted/Index.cshtml index d87b329..f1fe223 100644 --- a/MVCGridExample/Views/GettingStarted/Index.cshtml +++ b/MVCGridExample/Views/GettingStarted/Index.cshtml @@ -9,7 +9,7 @@
  • MVC 3 or greater
  • jQuery
  • -
  • Bootstrap 3
  • +
  • Bootstrap 3 (Or you can create your own custom style.)

Installation