diff --git a/MVCGrid/Engine/GridEngine.cs b/MVCGrid/Engine/GridEngine.cs index e5892f5..b7bf31d 100644 --- a/MVCGrid/Engine/GridEngine.cs +++ b/MVCGrid/Engine/GridEngine.cs @@ -104,13 +104,13 @@ private RenderingModel PrepModel(int? totalRecords, List rows, Models.GridC if (model.Rows.Count == 0) { - model.NoResultsMessage = gridContext.GridDefinition.NoResultsMessage; + model.NoResultsMessage = gridContext.GridDefinition.NoResultsMessageExpression != null ? gridContext.GridDefinition.NoResultsMessageExpression() : gridContext.GridDefinition.NoResultsMessage; } - model.NextButtonCaption = gridContext.GridDefinition.NextButtonCaption; - model.PreviousButtonCaption = gridContext.GridDefinition.PreviousButtonCaption; - model.SummaryMessage = gridContext.GridDefinition.SummaryMessage; - model.ProcessingMessage = gridContext.GridDefinition.ProcessingMessage; + model.NextButtonCaption = gridContext.GridDefinition.NextButtonCaptionExpression != null ? gridContext.GridDefinition.NextButtonCaptionExpression() : gridContext.GridDefinition.NextButtonCaption; + model.PreviousButtonCaption = gridContext.GridDefinition.PreviousButtonCaptionExpression != null ? gridContext.GridDefinition.PreviousButtonCaptionExpression() : gridContext.GridDefinition.PreviousButtonCaption; + model.SummaryMessage = gridContext.GridDefinition.SummaryMessageExpression != null ? gridContext.GridDefinition.SummaryMessageExpression() : gridContext.GridDefinition.SummaryMessage; + model.ProcessingMessage = gridContext.GridDefinition.ProcessingMessageExpression != null ? gridContext.GridDefinition.ProcessingMessageExpression() : gridContext.GridDefinition.ProcessingMessage; model.PagingModel = null; if (gridContext.QueryOptions.ItemsPerPage.HasValue) @@ -122,7 +122,7 @@ private RenderingModel PrepModel(int? totalRecords, List rows, Models.GridC model.PagingModel.TotalRecords = totalRecords.Value; model.PagingModel.FirstRecord = (currentPageIndex * gridContext.QueryOptions.ItemsPerPage.Value) + 1; - if(model.PagingModel.FirstRecord > model.PagingModel.TotalRecords) + if (model.PagingModel.FirstRecord > model.PagingModel.TotalRecords) { model.PagingModel.FirstRecord = model.PagingModel.TotalRecords; } @@ -154,7 +154,7 @@ private void PrepColumns(Models.GridContext gridContext, RenderingModel model) Column renderingColumn = new Column(); model.Columns.Add(renderingColumn); renderingColumn.Name = col.ColumnName; - renderingColumn.HeaderText = col.HeaderText; + renderingColumn.HeaderText = col.HeaderTextExpression != null ? col.HeaderTextExpression() : col.HeaderText; if (gridContext.GridDefinition.Sorting && col.EnableSorting) { @@ -261,7 +261,10 @@ private static string RenderPreloadedGridHtml(HtmlHelper helper, IMVCGridDefinit foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(pageParameters)) { object obj2 = descriptor.GetValue(pageParameters); - pageParamsDict.Add(descriptor.Name, obj2.ToString()); + if (obj2 != null) + { + pageParamsDict.Add(descriptor.Name, obj2.ToString()); + } } } if (grid.PageParameterNames.Count > 0) diff --git a/MVCGrid/Interfaces/IMVCGridColumn.cs b/MVCGrid/Interfaces/IMVCGridColumn.cs index 2c25a3b..1134557 100644 --- a/MVCGrid/Interfaces/IMVCGridColumn.cs +++ b/MVCGrid/Interfaces/IMVCGridColumn.cs @@ -12,6 +12,7 @@ public interface IMVCGridColumn /// Header text to display for the current column, if different from ColumnName. /// string HeaderText { get; } + Func HeaderTextExpression { get; } /// /// A unique name for this column diff --git a/MVCGrid/Interfaces/IMVCGridDefinition.cs b/MVCGrid/Interfaces/IMVCGridDefinition.cs index d82a7b8..12bf3c6 100644 --- a/MVCGrid/Interfaces/IMVCGridDefinition.cs +++ b/MVCGrid/Interfaces/IMVCGridDefinition.cs @@ -57,26 +57,45 @@ public interface IMVCGridDefinition /// string NoResultsMessage { get; set; } + /// + /// Text to display when there are no results with expression + /// + Func NoResultsMessageExpression { get; set; } + /// /// Text to display on the "next" button /// string NextButtonCaption { get; set; } + /// + /// Text to display on the "next" button + /// + Func NextButtonCaptionExpression { get; set; } + /// /// Text to display on the "previous" button /// string PreviousButtonCaption { get; set; } + Func PreviousButtonCaptionExpression { get; set; } + /// /// Summary text to display in grid footer /// string SummaryMessage { get; set; } + /// + /// Summary text to display in grid footer + /// + Func SummaryMessageExpression { get; set; } + /// /// Text to display when query is processed /// string ProcessingMessage { get; set; } + Func ProcessingMessageExpression { get; set; } + /// /// Name of function to call before ajax call begins /// diff --git a/MVCGrid/Models/ColumnDefaults.cs b/MVCGrid/Models/ColumnDefaults.cs index c8b57f7..d02a7fe 100644 --- a/MVCGrid/Models/ColumnDefaults.cs +++ b/MVCGrid/Models/ColumnDefaults.cs @@ -18,10 +18,12 @@ public ColumnDefaults() Visible = true; SortColumnData = null; AllowChangeVisibility = false; + HeaderTextExpression = null; } public string ColumnName { get; set; } public string HeaderText { get; set; } + public Func HeaderTextExpression { get; set; } public bool EnableSorting { get; set; } public bool HtmlEncode { get; set; } public bool EnableFiltering { get; set; } diff --git a/MVCGrid/Models/GridColumn.cs b/MVCGrid/Models/GridColumn.cs index 2243a70..8c50b1b 100644 --- a/MVCGrid/Models/GridColumn.cs +++ b/MVCGrid/Models/GridColumn.cs @@ -75,6 +75,8 @@ public string HeaderText } } + public Func HeaderTextExpression { get; set; } + /// /// Template for formatting cell value /// diff --git a/MVCGrid/Models/GridColumnBuilder.cs b/MVCGrid/Models/GridColumnBuilder.cs index e0d3d58..fffcbcc 100644 --- a/MVCGrid/Models/GridColumnBuilder.cs +++ b/MVCGrid/Models/GridColumnBuilder.cs @@ -102,6 +102,12 @@ public GridColumnBuilder WithHeaderText(string text) return this; } + public GridColumnBuilder WithHeaderTextExpression(Func expression) + { + GridColumn.HeaderTextExpression = expression; + return this; + } + /// /// Enables sorting on this column diff --git a/MVCGrid/Models/GridDefaults.cs b/MVCGrid/Models/GridDefaults.cs index 9052315..7c50335 100644 --- a/MVCGrid/Models/GridDefaults.cs +++ b/MVCGrid/Models/GridDefaults.cs @@ -19,10 +19,15 @@ public GridDefaults() DefaultSortColumn = null; DefaultSortDirection = SortDirection.Unspecified; NoResultsMessage = "No results."; + NoResultsMessageExpression = null; + SummaryMessageExpression = null; NextButtonCaption = "Next"; + NextButtonCaptionExpression = null; PreviousButtonCaption = "Previous"; + PreviousButtonCaptionExpression = null; SummaryMessage = "Showing {0} to {1} of {2} entries"; ProcessingMessage = "Processing"; + ProcessingMessageExpression = null; ClientSideLoadingMessageFunctionName = null; ClientSideLoadingCompleteFunctionName = null; Filtering = false; @@ -54,11 +59,15 @@ public GridDefaults() public SortDirection DefaultSortDirection { get; set; } public string NoResultsMessage { get; set; } + public Func NoResultsMessageExpression { get; set; } public string NextButtonCaption { get; set; } + public Func NextButtonCaptionExpression { get; set; } public string PreviousButtonCaption { get; set; } + public Func PreviousButtonCaptionExpression { get; set; } public string SummaryMessage { get; set; } + public Func SummaryMessageExpression { get; set; } public string ProcessingMessage { get; set; } - + public Func ProcessingMessageExpression { get; set; } public string ClientSideLoadingMessageFunctionName { get; set; } public string ClientSideLoadingCompleteFunctionName { get; set; } public bool Filtering { get; set; } diff --git a/MVCGrid/Models/GridDefinition.cs b/MVCGrid/Models/GridDefinition.cs index 09dd8bb..50b528e 100644 --- a/MVCGrid/Models/GridDefinition.cs +++ b/MVCGrid/Models/GridDefinition.cs @@ -258,26 +258,39 @@ internal override List GetData(GridContext context, out int? totalRecords) /// public string NoResultsMessage { get; set; } + /// + /// Text to display when there are no results with expression. + /// + public Func NoResultsMessageExpression { get; set; } + /// /// Text to display on the "next" button. /// public string NextButtonCaption { get; set; } + public Func NextButtonCaptionExpression { get; set; } + /// /// Text to display on the "previous" button. /// public string PreviousButtonCaption { get; set; } + public Func PreviousButtonCaptionExpression { get; set; } + /// /// Summary text to display in grid footer /// public string SummaryMessage { get; set; } + public Func SummaryMessageExpression { get; set; } + /// /// Text to display when query is processed /// public string ProcessingMessage { get; set; } + public Func ProcessingMessageExpression { get; set; } + /// /// Name of function to call before ajax call begins /// diff --git a/MVCGrid/Models/MVCGridBuilder.cs b/MVCGrid/Models/MVCGridBuilder.cs index e623ef0..f5b49e1 100644 --- a/MVCGrid/Models/MVCGridBuilder.cs +++ b/MVCGrid/Models/MVCGridBuilder.cs @@ -224,6 +224,38 @@ public MVCGridBuilder WithNoResultsMessage(string noResultsMessage) return this; } + /// + /// Text to display when there are no results with expression + /// + public MVCGridBuilder WithNoResultsMessageExpression(Func expression) + { + GridDefinition.NoResultsMessageExpression = expression; + return this; + } + + public MVCGridBuilder WithNextButtonCaptionExpression(Func expression) + { + GridDefinition.NextButtonCaptionExpression = expression; + return this; + } + + public MVCGridBuilder WithPreviousButtonCaptionExpression(Func expression) + { + GridDefinition.PreviousButtonCaptionExpression = expression; + return this; + } + + public MVCGridBuilder WithSummaryMessageExpression(Func expression) + { + GridDefinition.SummaryMessageExpression = expression; + return this; + } + + public MVCGridBuilder WithProcessingMessageExpression(Func expression) + { + GridDefinition.ProcessingMessageExpression = expression; + return this; + } /// /// Name of function to call before ajax call begins /// diff --git a/MVCGrid/Web/MVCGridHtmlGenerator.cs b/MVCGrid/Web/MVCGridHtmlGenerator.cs index 4f5096d..a29567c 100644 --- a/MVCGrid/Web/MVCGridHtmlGenerator.cs +++ b/MVCGrid/Web/MVCGridHtmlGenerator.cs @@ -158,8 +158,8 @@ internal static string GenerateBasePageHtml(string gridName, IMVCGridDefinition if (renderLoadingDiv) { sbHtml.AppendFormat(""); } @@ -182,12 +182,16 @@ private static string GenerateJsonPageParameters(object pageParameters) foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(pageParameters)) { object obj2 = descriptor.GetValue(pageParameters); - pageParamsDict.Add(descriptor.Name, obj2.ToString()); + if (obj2 != null) + { + pageParamsDict.Add(descriptor.Name, obj2.ToString()); + } } } foreach (var col in pageParamsDict) { + string val = col.Value; if (sb.Length > 0) diff --git a/MVCGrid/Web/QueryStringParser.cs b/MVCGrid/Web/QueryStringParser.cs index 7a8c3dc..930ebf5 100644 --- a/MVCGrid/Web/QueryStringParser.cs +++ b/MVCGrid/Web/QueryStringParser.cs @@ -26,7 +26,7 @@ public static QueryOptions ParseOptions(IMVCGridDefinition grid, HttpRequest htt string qsKeyPage = grid.QueryStringPrefix + QueryStringSuffix_Page; string qsKeySort = grid.QueryStringPrefix + QueryStringSuffix_Sort; string qsKeyDirection = grid.QueryStringPrefix + QueryStringSuffix_SortDir; - string qsKeyEngine = grid.QueryStringPrefix + QueryStringSuffix_Engine; + string qsKeyEngine = QueryStringSuffix_Engine; string qsKeyPageSize = grid.QueryStringPrefix + QueryStringSuffix_ItemsPerPage; string qsColumns = grid.QueryStringPrefix + QueryStringSuffix_Columns; diff --git a/MVCGridExample/Controllers/TestController.cs b/MVCGridExample/Controllers/TestController.cs index 1e01307..8effb7d 100644 --- a/MVCGridExample/Controllers/TestController.cs +++ b/MVCGridExample/Controllers/TestController.cs @@ -45,6 +45,7 @@ public override void RegisterGrids() .WithAllowChangingPageSize(false) .WithFiltering(true) .WithNoResultsMessage("Please enter a year to search for. No results found.") + .WithNoResultsMessageExpression(() => "beişey") .AddColumns(cols => { cols.Add("Year").WithHeaderText("Year")