Skip to content

Commit

Permalink
Modified RetrieveData method to take GridContext for consistency and …
Browse files Browse the repository at this point in the history
…for access to GridName. Consolidated documentation grid configurations.
  • Loading branch information
Joe Harrison committed Feb 11, 2015
1 parent 49838cf commit 24bb27e
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 172 deletions.
4 changes: 2 additions & 2 deletions MVCGrid/Models/GridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public void AddColumn(GridColumn<T1> column)

private List<GridColumn<T1>> Columns { get; set; }

public Func<QueryOptions, QueryResult<T1>> RetrieveData { get; set; }
public Func<GridContext, QueryResult<T1>> RetrieveData { get; set; }
public Func<T1, GridContext, string> RowCssClassExpression { get; set; }

internal override List<Row> GetData(GridContext context, out int? totalRecords)
{
List<Row> resultRows = new List<Row>();

var queryResult = RetrieveData(context.QueryOptions);
var queryResult = RetrieveData(context);
totalRecords = queryResult.TotalRecords;

if (context.GridDefinition.Paging && !totalRecords.HasValue)
Expand Down
8 changes: 7 additions & 1 deletion MVCGrid/Models/MVCGridBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public MVCGridBuilder<T1> AddColumns(Action<GridColumnListBuilder<T1>> columns)
return this;
}

public MVCGridBuilder<T1> WithRetrieveDataMethod(Func<QueryOptions, QueryResult<T1>> retrieveData)
public MVCGridBuilder<T1> AddColumn(GridColumn<T1> column)
{
GridDefinition.AddColumn(column);
return this;
}

public MVCGridBuilder<T1> WithRetrieveDataMethod(Func<GridContext, QueryResult<T1>> retrieveData)
{
GridDefinition.RetrieveData = retrieveData;
return this;
Expand Down
164 changes: 82 additions & 82 deletions MVCGridExample/App_Start/MVCGridConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public static void RegisterGrids()
.WithPaging(true)
.WithItemsPerPage(10)
.WithPreloadData(true)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -109,8 +111,9 @@ public static void RegisterGrids()
})
.WithSorting(true)
.WithDefaultSortColumn("LastName")
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;
var result = new QueryResult<Person>();

using (var db = new SampleDatabaseEntities())
Expand Down Expand Up @@ -160,8 +163,10 @@ public static void RegisterGrids()
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

var result = new QueryResult<Person>();

using (var db = new SampleDatabaseEntities())
Expand Down Expand Up @@ -218,8 +223,10 @@ public static void RegisterGrids()
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -262,8 +269,10 @@ public static void RegisterGrids()
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -315,8 +324,10 @@ public static void RegisterGrids()
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -352,8 +363,10 @@ public static void RegisterGrids()
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -387,8 +400,10 @@ public static void RegisterGrids()
.WithItemsPerPage(10)
.WithClientSideLoadingMessageFunctionName("showLoading")
.WithClientSideLoadingCompleteFunctionName("hideLoading")
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -430,8 +445,10 @@ public static void RegisterGrids()
.WithPaging(true)
.WithItemsPerPage(10)
.WithFiltering(true)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -496,8 +513,10 @@ public static void RegisterGrids()
.WithItemsPerPage(10)
.WithClientSideLoadingMessageFunctionName("showLoading")
.WithClientSideLoadingCompleteFunctionName("hideLoading")
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -543,8 +562,10 @@ public static void RegisterGrids()
.WithPaging(true)
.WithItemsPerPage(10)
.WithQueryStringPrefix("grid1")
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand Down Expand Up @@ -578,8 +599,10 @@ public static void RegisterGrids()
.WithPaging(true)
.WithItemsPerPage(10)
.WithQueryStringPrefix("grid2")
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

TestItemRepository repo = new TestItemRepository();
int totalRecords;
var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(), options.SortColumn, options.SortDirection == SortDirection.Dsc);
Expand Down Expand Up @@ -620,8 +643,10 @@ public static void RegisterGrids()
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(20)
.WithRetrieveDataMethod((options) =>
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;

int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

Expand All @@ -641,79 +666,54 @@ public static void RegisterGrids()
);


MVCGridDefinitionTable.Add("GridDefinitionGrid", new MVCGridBuilder<MethodDocItem>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("ReturnType")
.WithHeaderText("Return Type")
.WithHtmlEncoding(false)
.WithValueExpression((p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Return)));
cols.Add().WithColumnName("Name")
.WithHtmlEncoding(false)
.WithValueExpression((p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Name)));
cols.Add().WithColumnName("Description")
.WithValueExpression((p, c) => p.Description);
})
.WithPreloadData(true)
.WithRetrieveDataMethod((options) =>
{
var result = new QueryResult<MethodDocItem>();

DocumentationRepository repo = new DocumentationRepository();
result.Items = repo.GetData("GridDefinition");

return result;
})
var docsReturnTypeColumn = new GridColumn<MethodDocItem>()
{
ColumnName = "ReturnType",
HeaderText = "Return Type",
HtmlEncode = false,
ValueExpression = (p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Return))
};
var docsNameColumn = new GridColumn<MethodDocItem>()
{
ColumnName = "Name",
HtmlEncode = false,
ValueExpression = (p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Name))
};
var docsDescriptionColumn = new GridColumn<MethodDocItem>()
{
ColumnName = "Description",
ValueExpression = (p, c) => p.Description
};

Func<GridContext, QueryResult<MethodDocItem>> docsLoadData = (context) =>
{
var result = new QueryResult<MethodDocItem>();

DocumentationRepository repo = new DocumentationRepository();
result.Items = repo.GetData(context.GridName);

return result;
};

MVCGridDefinitionTable.Add("GridDefinition", new MVCGridBuilder<MethodDocItem>()
.AddColumn(docsReturnTypeColumn)
.AddColumn(docsNameColumn)
.AddColumn(docsDescriptionColumn)
.WithRetrieveDataMethod(docsLoadData)
);

MVCGridDefinitionTable.Add("GridColumnGrid", new MVCGridBuilder<MethodDocItem>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("ReturnType")
.WithHeaderText("Return Type")
.WithHtmlEncoding(false)
.WithValueExpression((p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Return)));
cols.Add().WithColumnName("Name")
.WithHtmlEncoding(false)
.WithValueExpression((p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Name)));
cols.Add().WithColumnName("Description")
.WithValueExpression((p, c) => p.Description);
})
.WithPreloadData(true)
.WithRetrieveDataMethod((options) =>
{
var result = new QueryResult<MethodDocItem>();

DocumentationRepository repo = new DocumentationRepository();
result.Items = repo.GetData("GridColumn");

return result;
})
MVCGridDefinitionTable.Add("GridColumn", new MVCGridBuilder<MethodDocItem>()
.AddColumn(docsReturnTypeColumn)
.AddColumn(docsNameColumn)
.AddColumn(docsDescriptionColumn)
.WithRetrieveDataMethod(docsLoadData)
);

MVCGridDefinitionTable.Add("QueryOptionsGrid", new MVCGridBuilder<MethodDocItem>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("ReturnType")
.WithHeaderText("Return Type")
.WithHtmlEncoding(false)
.WithValueExpression((p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Return)));
cols.Add().WithColumnName("Name")
.WithHtmlEncoding(false)
.WithValueExpression((p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Name)));
cols.Add().WithColumnName("Description")
.WithValueExpression((p, c) => p.Description);
})
.WithPreloadData(true)
.WithRetrieveDataMethod((options) =>
{
var result = new QueryResult<MethodDocItem>();

DocumentationRepository repo = new DocumentationRepository();
result.Items = repo.GetData("QueryOptions");

return result;
})
MVCGridDefinitionTable.Add("QueryOptions", new MVCGridBuilder<MethodDocItem>()
.AddColumn(docsReturnTypeColumn)
.AddColumn(docsNameColumn)
.AddColumn(docsDescriptionColumn)
.WithRetrieveDataMethod(docsLoadData)
);


Expand Down
Loading

0 comments on commit 24bb27e

Please sign in to comment.