Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unnecessary query prefix for engine #102

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions MVCGrid/Engine/GridEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ private RenderingModel PrepModel(int? totalRecords, List<Row> 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)
Expand All @@ -122,7 +122,7 @@ private RenderingModel PrepModel(int? totalRecords, List<Row> 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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions MVCGrid/Interfaces/IMVCGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IMVCGridColumn
/// Header text to display for the current column, if different from ColumnName.
/// </summary>
string HeaderText { get; }
Func<string> HeaderTextExpression { get; }

/// <summary>
/// A unique name for this column
Expand Down
19 changes: 19 additions & 0 deletions MVCGrid/Interfaces/IMVCGridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,45 @@ public interface IMVCGridDefinition
/// </summary>
string NoResultsMessage { get; set; }

/// <summary>
/// Text to display when there are no results with expression
/// </summary>
Func<string> NoResultsMessageExpression { get; set; }

/// <summary>
/// Text to display on the "next" button
/// </summary>
string NextButtonCaption { get; set; }

/// <summary>
/// Text to display on the "next" button
/// </summary>
Func<string> NextButtonCaptionExpression { get; set; }

/// <summary>
/// Text to display on the "previous" button
/// </summary>
string PreviousButtonCaption { get; set; }

Func<string> PreviousButtonCaptionExpression { get; set; }

/// <summary>
/// Summary text to display in grid footer
/// </summary>
string SummaryMessage { get; set; }

/// <summary>
/// Summary text to display in grid footer
/// </summary>
Func<string> SummaryMessageExpression { get; set; }

/// <summary>
/// Text to display when query is processed
/// </summary>
string ProcessingMessage { get; set; }

Func<string> ProcessingMessageExpression { get; set; }

/// <summary>
/// Name of function to call before ajax call begins
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions MVCGrid/Models/ColumnDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> HeaderTextExpression { get; set; }
public bool EnableSorting { get; set; }
public bool HtmlEncode { get; set; }
public bool EnableFiltering { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions MVCGrid/Models/GridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public string HeaderText
}
}

public Func<string> HeaderTextExpression { get; set; }

/// <summary>
/// Template for formatting cell value
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions MVCGrid/Models/GridColumnBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public GridColumnBuilder<T1> WithHeaderText(string text)
return this;
}

public GridColumnBuilder<T1> WithHeaderTextExpression(Func<string> expression)
{
GridColumn.HeaderTextExpression = expression;
return this;
}


/// <summary>
/// Enables sorting on this column
Expand Down
11 changes: 10 additions & 1 deletion MVCGrid/Models/GridDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,11 +59,15 @@ public GridDefaults()
public SortDirection DefaultSortDirection { get; set; }

public string NoResultsMessage { get; set; }
public Func<string> NoResultsMessageExpression { get; set; }
public string NextButtonCaption { get; set; }
public Func<string> NextButtonCaptionExpression { get; set; }
public string PreviousButtonCaption { get; set; }
public Func<string> PreviousButtonCaptionExpression { get; set; }
public string SummaryMessage { get; set; }
public Func<string> SummaryMessageExpression { get; set; }
public string ProcessingMessage { get; set; }

public Func<string> ProcessingMessageExpression { get; set; }
public string ClientSideLoadingMessageFunctionName { get; set; }
public string ClientSideLoadingCompleteFunctionName { get; set; }
public bool Filtering { get; set; }
Expand Down
13 changes: 13 additions & 0 deletions MVCGrid/Models/GridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,39 @@ internal override List<Row> GetData(GridContext context, out int? totalRecords)
/// </summary>
public string NoResultsMessage { get; set; }

/// <summary>
/// Text to display when there are no results with expression.
/// </summary>
public Func<string> NoResultsMessageExpression { get; set; }

/// <summary>
/// Text to display on the "next" button.
/// </summary>
public string NextButtonCaption { get; set; }

public Func<string> NextButtonCaptionExpression { get; set; }

/// <summary>
/// Text to display on the "previous" button.
/// </summary>
public string PreviousButtonCaption { get; set; }

public Func<string> PreviousButtonCaptionExpression { get; set; }

/// <summary>
/// Summary text to display in grid footer
/// </summary>
public string SummaryMessage { get; set; }

public Func<string> SummaryMessageExpression { get; set; }

/// <summary>
/// Text to display when query is processed
/// </summary>
public string ProcessingMessage { get; set; }

public Func<string> ProcessingMessageExpression { get; set; }

/// <summary>
/// Name of function to call before ajax call begins
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions MVCGrid/Models/MVCGridBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,38 @@ public MVCGridBuilder<T1> WithNoResultsMessage(string noResultsMessage)
return this;
}

/// <summary>
/// Text to display when there are no results with expression
/// </summary>
public MVCGridBuilder<T1> WithNoResultsMessageExpression(Func<string> expression)
{
GridDefinition.NoResultsMessageExpression = expression;
return this;
}

public MVCGridBuilder<T1> WithNextButtonCaptionExpression(Func<string> expression)
{
GridDefinition.NextButtonCaptionExpression = expression;
return this;
}

public MVCGridBuilder<T1> WithPreviousButtonCaptionExpression(Func<string> expression)
{
GridDefinition.PreviousButtonCaptionExpression = expression;
return this;
}

public MVCGridBuilder<T1> WithSummaryMessageExpression(Func<string> expression)
{
GridDefinition.SummaryMessageExpression = expression;
return this;
}

public MVCGridBuilder<T1> WithProcessingMessageExpression(Func<string> expression)
{
GridDefinition.ProcessingMessageExpression = expression;
return this;
}
/// <summary>
/// Name of function to call before ajax call begins
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions MVCGrid/Web/MVCGridHtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ internal static string GenerateBasePageHtml(string gridName, IMVCGridDefinition
if (renderLoadingDiv)
{
sbHtml.AppendFormat("<div id='MVCGrid_Loading_{0}' class='text-center' style='visibility: hidden'>", gridName);
sbHtml.AppendFormat("&nbsp;&nbsp;&nbsp;<img src='{0}/ajaxloader.gif' alt='{1}' style='width: 15px; height: 15px;' />", HtmlUtility.GetHandlerPath(), def.ProcessingMessage);
sbHtml.AppendFormat("&nbsp;{0}...", def.ProcessingMessage);
sbHtml.AppendFormat("&nbsp;&nbsp;&nbsp;<img src='{0}/ajaxloader.gif' alt='{1}' style='width: 15px; height: 15px;' />", HtmlUtility.GetHandlerPath(), def.ProcessingMessageExpression != null ? def.ProcessingMessageExpression() : def.ProcessingMessage);
sbHtml.AppendFormat("&nbsp;{0}...", def.ProcessingMessageExpression != null ? def.ProcessingMessageExpression() : def.ProcessingMessage);
sbHtml.Append("</div>");
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion MVCGrid/Web/QueryStringParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions MVCGridExample/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down