diff --git a/MVCGrid/Interfaces/IMVCGridDefinition.cs b/MVCGrid/Interfaces/IMVCGridDefinition.cs index 0c85346..9c544e3 100644 --- a/MVCGrid/Interfaces/IMVCGridDefinition.cs +++ b/MVCGrid/Interfaces/IMVCGridDefinition.cs @@ -20,5 +20,7 @@ internal interface IMVCGridDefinition string ClientSideLoadingMessageFunctionName { get; set; } string ClientSideLoadingCompleteFunctionName { get; set; } bool Filtering { get; set; } + + Type HtmlWriterType { get; set; } } } diff --git a/MVCGrid/Models/GridDefinition.cs b/MVCGrid/Models/GridDefinition.cs index f9f6d98..a38c7ca 100644 --- a/MVCGrid/Models/GridDefinition.cs +++ b/MVCGrid/Models/GridDefinition.cs @@ -15,6 +15,7 @@ public abstract class GridDefinitionBase public class GridDefinition : GridDefinitionBase, IMVCGridDefinition { + private Type _htmlWriterType; const string DefaultNoResultsMessage = "No results."; public GridDefinition() : this(null) @@ -31,6 +32,7 @@ public GridDefinition(GridConfiguration copyFromConfig):base() Columns = new List>(); NoResultsMessage = DefaultNoResultsMessage; + _htmlWriterType = typeof(MVCGrid.Rendering.BootstrapHtmlWriter); } public GridConfiguration GridConfiguration { get; set; } @@ -147,6 +149,17 @@ internal override GridData GetData(GridContext context) public string ClientSideLoadingMessageFunctionName { get; set; } public string ClientSideLoadingCompleteFunctionName { get; set; } + public Type HtmlWriterType + { + get + { + return _htmlWriterType; + } + set + { + _htmlWriterType = value; + } + } } } diff --git a/MVCGrid/Rendering/HtmlRenderingEngine.cs b/MVCGrid/Rendering/HtmlRenderingEngine.cs index 5942693..81c5561 100644 --- a/MVCGrid/Rendering/HtmlRenderingEngine.cs +++ b/MVCGrid/Rendering/HtmlRenderingEngine.cs @@ -13,8 +13,11 @@ namespace MVCGrid.Rendering { public class HtmlRenderingEngine : IMVCGridRenderingEngine { - public HtmlRenderingEngine() + IMVCGridHtmlWriter _writer; + + public HtmlRenderingEngine(IMVCGridHtmlWriter writer) { + _writer = writer; } public void PrepareResponse(HttpResponse response) @@ -30,8 +33,7 @@ public void Render(GridData data, GridContext gridContext, Stream outputStream)/ { RenderingModel model = PrepModel(data, gridContext); - BootstrapHtmlWriter writer = new BootstrapHtmlWriter(); - var content = writer.WriteHtml(model); + var content = _writer.WriteHtml(model); using (StreamWriter sw = new StreamWriter(outputStream)) { diff --git a/MVCGrid/Web/HtmlExtensions.cs b/MVCGrid/Web/HtmlExtensions.cs index d7f8933..ba70e58 100644 --- a/MVCGrid/Web/HtmlExtensions.cs +++ b/MVCGrid/Web/HtmlExtensions.cs @@ -35,7 +35,8 @@ internal static IHtmlString MVCGrid(this HtmlHelper helper, string name, IMVCGri var gridContext = GridContextUtility.Create(HttpContext.Current, gridName, grid, options); - IMVCGridRenderingEngine renderingEngine = new HtmlRenderingEngine(); + IMVCGridHtmlWriter writer = (IMVCGridHtmlWriter)Activator.CreateInstance(gridContext.GridDefinition.HtmlWriterType, true); + IMVCGridRenderingEngine renderingEngine = new HtmlRenderingEngine(writer); var results = ((MVCGrid.Models.GridDefinitionBase)grid).GetData(gridContext); diff --git a/MVCGrid/Web/MVCGridHandler.cs b/MVCGrid/Web/MVCGridHandler.cs index e969f6b..2395065 100644 --- a/MVCGrid/Web/MVCGridHandler.cs +++ b/MVCGrid/Web/MVCGridHandler.cs @@ -174,7 +174,10 @@ private void HandleTable(HttpContext context) var gridContext = GridContextUtility.Create(context, gridName, grid, options); - IMVCGridRenderingEngine renderingEngine = DetermineRenderingEngine(context); + IMVCGridHtmlWriter writer = (IMVCGridHtmlWriter)Activator.CreateInstance(gridContext.GridDefinition.HtmlWriterType, true); + + IMVCGridRenderingEngine renderingEngine = DetermineRenderingEngine(context, writer); + //if (renderingEngine is HtmlRenderingEngine) //{ @@ -199,7 +202,7 @@ private void HandleTable(HttpContext context) renderingEngine.Render(results, gridContext, context.Response.OutputStream); } - private IMVCGridRenderingEngine DetermineRenderingEngine(HttpContext context) + private IMVCGridRenderingEngine DetermineRenderingEngine(HttpContext context, IMVCGridHtmlWriter writer) { IMVCGridRenderingEngine engine = null; @@ -214,7 +217,7 @@ private IMVCGridRenderingEngine DetermineRenderingEngine(HttpContext context) if (engine == null) { - engine = new HtmlRenderingEngine(); + engine = new HtmlRenderingEngine(writer); } return engine;