Thoughts from Dan Miser RSS 2.0
# Monday, July 30, 2012
I'm trying to settle on a standard for a grid component for use in an ASP.NET MVC app. It looks like datatables.net is the winner for now.

Here is my quick run-down on how to get it working:

  • Using NuGet, install Mvc.Jquery.Datatables
  • Using NuGet, install EmbeddedVirtualPathProvider.
  • In the generated App_Code\RegisterVirtualPathProvide.cs file, add the following line where the comment tells you to. These last 2 steps are needed to get the grid to show up on the page.
    
    {typeof(Mvc.JQuery.Datatables.DataTableVm).Assembly, @"..\Mvc.JQuery.Datatables"} 
    
  • The sample found here is a little outdated and the instructions on the page don't match what's happening inside the actual view. Use these instructions instead:
    • In the controller, you need to return a DataTablesResult (not an IDataTablesResult). The assembly relies on finding an action with this return type, so that also means that you can't redirect views, which isn't the worst thing since this should be an AJAX request anyways.
    • In the view, add this to the top (instead of the calls to the link and script tags cited in the page:
      
      @Html.DataTableIncludes(jqueryUi:false)
      
    • In the view, the code should look similar to this where you want the grid (remember, you need to have the controller action method return DataTablesResult in order for this to work):
      
      @{
        var vm = Html.DataTableVm("table-id", (DashboardController h) => h.GetWireHistoryData(null));
      }
      @Html.Partial("DataTable", vm)
      

There is a good series expanding on datatables usag in ASP.NET MVC over at codeproject.com.

Thanks to Harry for the NuGet package. It definitely will make keeping things up to date much easier.

Monday, July 30, 2012 8:46:19 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
ASP.NET MVC
Navigation
Archive
<November 2014>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)