开发者

Sorting, Filtering and Paging in ASP.NET MVC

开发者 https://www.devze.com 2022-12-17 06:17 出处:网络
What is the best approach to implement these features and which part of project would involved? I see some example of JavaScript grids, but I\'m talking about a general approach which best fits the M

What is the best approach to implement these features and which part of project would involved?

I see some example of JavaScript grids, but I'm talking about a general approach which best fits the MVC architec开发者_JAVA技巧ture.

I've considered configuring routes and models to implement these features but I don't have a clear idea that if this is the right approach to implementing such features. On the one hand, I think if we put logic in routes (item/page/sort/), we would have benefits like bookmarking and avoiding JavaScript. On the other hand if we use JavaScript grids, we can have behavior like the old school grid views in ASP.NET web forms.

I find that using HTML helpers may be useful for paging, but have no idea if they are good for sorting or not. I've looked at jQuery, tableSorter and quick search plug-ins, but they work just on the currently-fetched data and won't help in real sorting and filtering that may need to touch the database. I have some thoughts on using these tools side by side with AJAX to get something which works, but I have no idea if there are similar efforts done yet anywhere.

Another approach I looked at was using Dynamic Data on web forms, but I didn't find any suggestions out there as to whether or not it is a good idea to integrate MVC and DD. I know implementing filtering and sorting for an individual case is simple (although it has some issues like using Dynamic LINQ, which is not yet a standard approach), but creating a sorting or filtering tool which works in all cases is the idea I'm looking for. (Maybe this is because I want have something in hand when web form developers are wondering why I'm writing same code each time I want to implement a sort scenario for different Entities).


Here's my solution based on jqGrid: http://sprokhorenko.blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html

It is a bit specific to S#arp Architecture and NHibernate, so I'm not sure if it suits your needs. But it's modular so for example it's easy to tweak base repository implementation.

Basically it's just jqGrid with all its pros and cons but integrated into MVC:

  1. control all formatting and editing with attributes on ViewModel
  2. automatic requests, sorting/filtering/paging handling
  3. automatic CRUD handling
  4. Can handle both DB and list based repositories
  5. no bookmarkable routes/links...

All you need is to provide ViewModel with attribute and override couple of template CRUD methods (can be as little as just InternalConstructEntity().


You could check out MVContrib, they have pretty good grid support. http://www.codeplex.com/MVCContrib

For LOB Applications the Telerik Controls might be a good solution.


I personally use jQuery DataTables. It's very simple and has a well-defined server-side request. I've written a plugin for jQuery DataTables with C# and MVC. It uses the standard jQuery DataTables request and manipulates an IQeryable instance accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号