Tuesday, 11 November 2008

Using ExtJS grid in your ASP.NET MVC application

In this second code drop for the WineCellarManager on ASP.NET MVC I added an ExtJs grid. To be able to run the new version there are a couple of things you'll need to do:

Update your database schema

A new Migration was added  to the migration project: Migration003AddWineRelatedTables.

You run this migration with the Migrator.Console which you'll find in the "libs" directory. Here is an example command that you can use to run it: "Migrator.Console.exe "SqlServer" "Server=localhost\SQLEXPRESS;initial catalog=wines;Integrated Security=SSPI" d:\OSS\WineCellarManagerASPNETMVC\WineCellar.Migrator\bin\Debug\WineCellar.Migrator.dll" You do have to change the path to the migrator assembly of course and probably also the connection string.

Update Rhino.Security operations

I have added a WineController which has some actions but to be able to use them you should update your Rhino.Security operations. To do that: run the application and navigate to: localhost:portnumber/Permission/Generate. When you look in the code of the "PermissionController" you'll notice that it adds those permissions for a user called "bart". That's the one that is being added by migration 2 as well. If you want another user: change migration 2 and the PermissionsController.

Add some wines to your database

Navigate to localhost http://localhost:portnumber/Wine/GenerateWines. The system will add some wines to the database and show a message when that is done. If you want the grid to work correctly you should use this way of adding wines because otherwise they are not added to the Lucene index.

Now you should be set to go. If I missed something here, please let me know!

What's new: ExtJs grid

The list of wines is shown using an ExtJS grid. Out of the box this grid has some pretty cool features. For most of them there is of course some server side code needed. Following features are implemented (next to the features that are out of the box supported by the grid and don't need a server side):

  1. Paging: Rhino.Tools - FutureQueryOf is being used here
  2. Filtering and sorting on each column of the grid: A big thank you to NHibernate Criteria
  3. Quick search box: wouldn't have been possible without NHibernate.Search.

You can check out the "GetWines" action method in the "WineController" to see how it's done and underneath is a screenshot of the grid.

image

I use a HtmlHelper extensions method to generate the grid (see class: HtmlHelperExtensions). Doing so you avoid having to type a lot of JS code each time you want this grid on your page and each grid looks exactly the same because it is generated in the same way ;-)

If there is anything unclear let me know!

The code is here: http://code.google.com/p/winecellarmanager/

5 comments:

Luke said...

Thanks for providing this code - it is serving as an excellent reference for both ASP.NET MVC and Ayende's Rhino stack.

nokiola said...

Good job Bart. Thanks for putting all these together.Many thanks!

yasi8h said...

Nice post. i did something like what you have done. but it have grid filtering in it. A Grid with Ajax/Pagination/Sorting/Filtering on ASP.net MVC with ExtJS and Enitiy Framework - http://thekindofme.wordpress.com/2009/02/05/a-grid-with-ajax-pagination-sorting-filtering-on-aspnet-mvc-with-extjs-and-ef/

Bart said...

@yasi8h Cool, we also have grid filtering and stuff like that, we even have a quick search box. I just not did not write on that yet.
btw, I would be interested to see how you get all filters that were applied?

eda said...

live119|live119論壇|
角色扮演|跳蛋|情趣跳蛋|煙火批發|煙火|情趣用品|SM|
按摩棒|電動按摩棒|飛機杯|自慰套|自慰套|情趣內衣|
潤滑液|內衣|性感內衣|自慰器|
充氣娃娃|AV|情趣|衣蝶|

G點|性感丁字褲|吊帶襪|丁字褲|無線跳蛋|性感睡衣|