posts - 81, comments - 262, trackbacks - 0

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,

View the complete Controller here,

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 4, 2009 6:25 PM | Filed Under [ Web Programming ]

Powered by:
Powered By Subtext Powered By ASP.NET