posts - 54, comments - 164, trackbacks - 4

My Links

Archives

Post Categories

Projects

Web Dev

Paging with Filters and Sorts added to Unifico

Two new additions were added to Unifico: filtering on fields and sorting on fields with the help of Html Extension methods.

A PagingSet class was defined to contain configuration options for the paging. In this way a View can still page on more than one list and maintain complete control over the Html rendered. Every string used in the Html Helpers is pulled from the configuration (A default is made available).

Several extension methods were added to the Html Helper to make rendering the controls easier.

The filtering html form can be rendered with <%= Html.FilterInput(Paging, "Go") %> Where "go" is the button text.

A sortable column header can be rendered with <%= Html.PageSorting(Paging, "Email","E-Mail")%>

Where the paging configuration has been passed from the controller, leaving the paging control completely in the hands of the controller:

<% PageResponse<User> Users = (PageResponse<User>)ViewData.Model;

PagingSet Paging = (PagingSet)ViewData["PagingSet"];

%>

View the complete "View" here, http://www.codeplex.com/unifico/SourceControl/changeset/view/1798#54414

View the complete Controller here, http://www.codeplex.com/unifico/SourceControl/changeset/view/1798#44699

The end result of all this is paging that executes through the PageRequest class, so that no changes are required of the Service and paging that executes in SQL. It also has the nice benefit of residing completely in the QueryString and not requiring changes to the Controller's Action's parameters.

An example path created from paging with sorting and filtering: /Admin/Account/Users?expr=asdf9&filterby=All&orderby=Name&asc=False&page=1

And the SQL it generates.

exec sp_executesql N'SELECT TOP (10) [t0].[UserID] AS [ID], [t0].[Name], [t0].[Password], [t0].[Email]
FROM [dbo].[User] AS [t0]
WHERE ([t0].[Name] = @p0) OR ([t0].[Name] = @p1)
ORDER BY [t0].[Name] DESC',N'@p0 nvarchar(5),@p1 nvarchar(5)',@p0=N'asdf9',@p1=N'asdf9'

Print | posted on Sunday, January 04, 2009 6:25 PM | Filed Under [ Web Programming ]

kick it on DotNetKicks.com

Feedback

Gravatar

# re: Paging with Filters and Sorts added to Unifico

Hey I got the latest on your Unifico solution, and you seem to have forgotten to check in the PageSet class. I also checked on Codeplex under the Paging folder, and it wasn't there.
1/5/2009 1:19 PM | Khalid Abuhakmeh
Gravatar

# re: Paging with Filters and Sorts added to Unifico

Added, my apologies!

http://www.codeplex.com/unifico/SourceControl/changeset/view/1945#60446
1/5/2009 1:37 PM | Charles
Gravatar

# re: Paging with Filters and Sorts added to Unifico

Well it's a good start to an application, but there are a few things you should look at. First is your use of IoC, it's good that you are using it, but I don't think you are using it correctly.

public AccountAdminController()
{
accountService = ObjectFactory.GetInstance<IAccountService>();
}

Your constructor should look something like this

public AccountAdminController(IAccountService accountService)
{
_accountService = accountService;
}
This way anytime an AccountAdminController is created, the user is forced to pass that AccountService in. Rob Conery wrote a controllerfactory for MVC, check it out.

Also you could drastically reduce your ExpressionHelper class by using some reflection. You won't have those large if statements.

Also use IList<T> instead of List<T> (more loosely coupled).

Those are the first things I saw, but it is a pretty decent start. Hope that helps. Check out my blog too :)
1/5/2009 4:01 PM | Khalid Abuhakmeh
Gravatar

# re: Paging with Filters and Sorts added to Unifico

Thank you Khalid.

I think you might be right on the IoC. I will have to check out Rob’s controllerfactory. I agree on IList and will make that change.

With regard to the reflection, I am afraid to over use it for performance reasons. My thought is it’s faster to do a comparison than reflection. Though a large condition set may look bad, it should outperform? I did find a few ways to clean it up which need to be added as well.

You have been added to my feed :)

1/5/2009 10:29 PM | Charles
Gravatar

# re: Paging with Filters and Sorts added to Unifico

feed reader*
1/5/2009 10:31 PM | Charles

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 5 and 2 and type the answer here:

Powered by: