diff --git a/Mvc.JQuery.Datatables.Example/App_Start/RegisterDatatablesModelBinder.cs b/Mvc.JQuery.Datatables.Example/App_Start/RegisterDatatablesModelBinder.cs deleted file mode 100644 index ffb88f5..0000000 --- a/Mvc.JQuery.Datatables.Example/App_Start/RegisterDatatablesModelBinder.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Web; -using System.Web.Mvc; -using System.Web.WebPages; - -[assembly: PreApplicationStartMethod(typeof(Mvc.JQuery.Datatables.Example.App_Start.RegisterDatatablesModelBinder), "Start")] - -namespace Mvc.JQuery.Datatables.Example.App_Start { - public static class RegisterDatatablesModelBinder { - public static void Start() { - ModelBinders.Binders.Add(typeof(DataTablesParam), new DataTablesModelBinder()); - } - } -} diff --git a/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs b/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs index 77a75e1..545d1c5 100644 --- a/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs +++ b/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs @@ -51,9 +51,10 @@ public DataTablesResult GetUsers(DataTablesParam dataTableParam) public class UserView { + [DataTables(SortDirection = SortDirection.Ascending)] public int Id { get; set; } - [DataTables( DisplayName = "Full Name")] + [DataTables(DisplayName = "Full Name", MRenderFunction = "test")] public string Name { get; set; } diff --git a/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj b/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj index f27766b..f4a762a 100644 --- a/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj +++ b/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj @@ -76,13 +76,9 @@ - - ..\packages\WebActivator.1.5\lib\net40\WebActivator.dll - - diff --git a/Mvc.JQuery.Datatables.Example/Views/Home/Index.cshtml b/Mvc.JQuery.Datatables.Example/Views/Home/Index.cshtml index 83dd0c8..3a2b628 100644 --- a/Mvc.JQuery.Datatables.Example/Views/Home/Index.cshtml +++ b/Mvc.JQuery.Datatables.Example/Views/Home/Index.cshtml @@ -1,53 +1,48 @@ @{ ViewBag.Title = "title"; } -@Html.DataTableIncludes(jqueryUi:true) +@Html.DataTableIncludes(jqueryUi: true) +

Strongly typed datatable example

 Nuget install-package Mvc.JQuery.Datatables
+    
+Nuget install-package EmbeddedResourceVirtualPathProvider or Nuget install-package Mvc.JQuery.Datatables.Templates
+
 

- In the controller: + Create a controller (see example)

-public DataTablesResult<UserView> GetUsers(DataTablesParam dataTableParam)
+public class SomeController : Controller 
 {
-    var users = new List<User>
-    (
-        Enumerable.Range(1, 100).Select(i => new User(){Id = i, Email = "user" + i + "@@gmail.com", Name = "User" + i})
-    ).AsQueryable();
-
-    return DataTablesResult.Create(users, dataTableParam, user => new UserView()
+    ...
+    public DataTablesResult<UserView> GetUsers(DataTablesParam dataTableParam)
     {
-        Id = user.Id,
-        Name = user.Name
-    });
+        IQueryable<User> users = ... //take a queryable from your database...
+        var userViews = users.Select(u => new UserView(u)); //...transform it into a view object ...
+        return DataTablesResult.Create(userViews, dataTableParam)  //...and return a DataTablesResult
+    }
 }
 

-and in the view... - -

-@@using Mvc.JQuery.Datatables
-@@using Mvc.JQuery.Datatables.Example.Controllers
+    and render the partial (see example)
 
-<link type="text/css" href="@@Url.Content("~/Content/DataTables-1.8.2/media/css/demo_table.css")" rel="stylesheet"/>
-<script src="@@Url.Content("~/Scripts/DataTables-1.8.2/media/js/jquery.dataTables.js")" type="text/javascript"></script>
+    
+        //include these scripts
+        <link type="text/css" href="@@Url.Content("~/Content/DataTables-1.8.2/media/css/demo_table.css")" rel="stylesheet"/>
+        <script src="@@Url.Content("~/Scripts/DataTables-1.8.2/media/js/jquery.dataTables.js")" type="text/javascript"></script>
 
-@@Html.Partial("DataTable", Html.DataTableVm("table-id", (HomeController h) => h.GetUsers(null)))
+        @@Html.Partial("DataTable", Html.DataTableVm("table-id", (HomeController h) => h.GetUsers(null)))
 
-can also use 
-
-@@Html.Partial("DataTable", Html.DataTableVm("table-id", "/home/getusers", "Id", "Name", "Email"))
-
+

-

Voila

- +

Voila!

Custom placement for Position filter:
@@ -55,6 +50,7 @@ can also use @using Mvc.JQuery.Datatables @using Mvc.JQuery.Datatables.Example.Controllers +@using Mvc.JQuery.Datatables.Models @{ var vm = Html.DataTableVm("table-id", (HomeController h) => h.GetUsers(null)); //vm.JsOptions.Add("iDisplayLength", 25); @@ -62,37 +58,54 @@ can also use vm.ColumnFilter = true; vm.FilterOn("Position", new { sSelector = "#custom-filter-placeholder-position" }).Select("Engineer", "Tester", "Manager") .FilterOn("Id").NumberRange(); - //.FilterOn("Number").CheckBoxes(Enum.GetNames(typeof(Numbers))); + //.FilterOn("Number").CheckBoxes(Enum.GetNames(typeof(Numbers))); vm.StateSave = true; - //vm.Language = "{ 'sUrl': '" + Url.Content("~/Content/jquery.dataTables.lang.de-DE.txt") + "' }"; - - vm.Language = "{" + - " 'sProcessing': 'Bitte warten...'," + - " 'sLengthMenu': '_MENU_ Einträge anzeigen'," + - " 'sZeroRecords': 'Keine Einträge vorhanden.'," + - " 'sInfo': '_START_ bis _END_ von _TOTAL_ Einträgen'," + - " 'sInfoEmpty': '0 bis 0 von 0 Einträgen'," + - " 'sInfoFiltered': '(gefiltert von _MAX_ Einträgen)'," + - " 'sInfoPostFix': ''," + - " 'sSearch': 'Suchen'," + - " 'sUrl': ''," + - " 'oPaginate': {" + - " 'sFirst': 'Erster'," + - " 'sPrevious': 'Zurück'," + - " 'sNext': 'Weiter'," + - " 'sLast': 'Letzter'" + - " }" + - "}"; -} -@Html.Partial("DataTable", vm) - - - + if (Request.QueryString["lang"] == "de") + { + //vm.Language = "{ 'sUrl': '" + Url.Content("~/Content/jquery.dataTables.lang.de-DE.txt") + "' }"; + vm.Language = new Language + { + sProcessing = "Bitte warten...", + sLengthMenu = "_MENU_ Einträge anzeigen", + sZeroRecords = "Keine Einträge vorhanden.", + sInfo = "_START_ bis _END_ von _TOTAL_ Einträgen", + sInfoEmpty = "0 bis 0 von 0 Einträgen", + sInfoFiltered = "(gefiltert von _MAX_ Einträgen)", + sInfoPostFix = "", + sSearch = "Suchen", + sUrl = "", + oPaginate = new Paginate() + { + sFirst = "Erster", + sPrevious = "Zurück", + sNext = "Weiter", + sLast = "Letzter" + } + }.ToJsonString(); + } +} + +@Html.Partial("DataTable", vm) +
+
+ @if (Request.QueryString["lang"] != "de") + { + See table with Language settings applied + } + else + { + Turn off language settings + } +
diff --git a/Mvc.JQuery.Datatables.Example/Views/Shared/_Layout.cshtml b/Mvc.JQuery.Datatables.Example/Views/Shared/_Layout.cshtml index 7d96acb..f7f49ba 100644 --- a/Mvc.JQuery.Datatables.Example/Views/Shared/_Layout.cshtml +++ b/Mvc.JQuery.Datatables.Example/Views/Shared/_Layout.cshtml @@ -54,17 +54,7 @@ -
-
-
-

@Html.ActionLink("My MVC Application", "Index", "Home")

- - @Html.Partial("_LogOnPartial") -
-
-
+
@RenderBody()
diff --git a/Mvc.JQuery.Datatables.Example/packages.config b/Mvc.JQuery.Datatables.Example/packages.config index efe6314..0ec494d 100644 --- a/Mvc.JQuery.Datatables.Example/packages.config +++ b/Mvc.JQuery.Datatables.Example/packages.config @@ -17,5 +17,4 @@ - \ No newline at end of file diff --git a/Mvc.JQuery.Datatables.Templates/Views/Shared/DataTable.cshtml b/Mvc.JQuery.Datatables.Templates/Views/Shared/DataTable.cshtml index fd5cbd3..3f7ae90 100644 --- a/Mvc.JQuery.Datatables.Templates/Views/Shared/DataTable.cshtml +++ b/Mvc.JQuery.Datatables.Templates/Views/Shared/DataTable.cshtml @@ -35,6 +35,7 @@ } var $table = $('#@Model.Id'); var dt = $table.dataTable({ + "aaSorting": @Html.Raw(Model.ColumnSortingString), "bProcessing": true, "bStateSave": @Html.Raw(Model.StateSave ? "true" : "false"), "bServerSide": true, diff --git a/Mvc.JQuery.Datatables.sln.DotSettings.user b/Mvc.JQuery.Datatables.sln.DotSettings.user index 7f927f9..410b7a4 100644 --- a/Mvc.JQuery.Datatables.sln.DotSettings.user +++ b/Mvc.JQuery.Datatables.sln.DotSettings.user @@ -5,4 +5,4 @@ True True ThingsAreCalledCorrectly - <Session><Elements><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.EntityFramework" type="NUnitTestFixtureElement" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests" type="NUnitTestFixtureElement" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.Linq" type="NUnitTestFixtureElement" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.Linq.ExecuteParams" ParentId="Mvc.JQuery.DataTables.Tests.Linq" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.Linq" MethodName="ExecuteParams" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.EntityFramework.ExecuteParams" ParentId="Mvc.JQuery.DataTables.Tests.EntityFramework" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.EntityFramework" MethodName="ExecuteParams" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.Linq.ExecuteParamsAndTransform" ParentId="Mvc.JQuery.DataTables.Tests.Linq" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.Linq" MethodName="ExecuteParamsAndTransform" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.EntityFramework.ExecuteParamsAndTransform" ParentId="Mvc.JQuery.DataTables.Tests.EntityFramework" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.Linq" MethodName="ExecuteParamsAndTransform" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.FilterTests" MethodName="SearchQueryTests" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^123$&quot;,System.Int32,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^456$&quot;,System.Int32,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^Ched&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^Cheddar&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^Cheddar$&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^False$&quot;,System.Boolean,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^True$&quot;,System.Boolean,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;123&quot;,System.Int32,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;456&quot;,System.Int32,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;asdf&quot;,System.String,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;Cheddar&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;False&quot;,System.Boolean,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;True&quot;,System.Boolean,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /></Elements></Session> \ No newline at end of file + <Session><Elements><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.EntityFramework" type="NUnitTestFixtureElement" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests" type="NUnitTestFixtureElement" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.Linq" type="NUnitTestFixtureElement" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.Linq.ExecuteParams" ParentId="Mvc.JQuery.DataTables.Tests.Linq" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.Linq" MethodName="ExecuteParams" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.EntityFramework.ExecuteParams" ParentId="Mvc.JQuery.DataTables.Tests.EntityFramework" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.EntityFramework" MethodName="ExecuteParams" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.Linq.ExecuteParamsAndTransform" ParentId="Mvc.JQuery.DataTables.Tests.Linq" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.Linq" MethodName="ExecuteParamsAndTransform" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.EntityFramework.ExecuteParamsAndTransform" ParentId="Mvc.JQuery.DataTables.Tests.EntityFramework" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.Linq" MethodName="ExecuteParamsAndTransform" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests" type="NUnitTestElement" TypeName="Mvc.JQuery.DataTables.Tests.FilterTests" MethodName="SearchQueryTests" Project="53671C41-666D-4269-A12A-BA6C2F209E7A" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^123$&quot;,System.Int32,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^456$&quot;,System.Int32,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^False$&quot;,System.Boolean,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^Ched&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^Cheddar&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^Cheddar$&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;^True$&quot;,System.Boolean,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;123&quot;,System.Int32,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;456&quot;,System.Int32,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;asdf&quot;,System.String,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;False&quot;,System.Boolean,False)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;Cheddar&quot;,System.String,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /><UnitTestElement Provider="nUnit" Id="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests(&quot;True&quot;,System.Boolean,True)" ParentId="Mvc.JQuery.DataTables.Tests.FilterTests.SearchQueryTests" type="NUnitRowTestElement" /></Elements></Session> \ No newline at end of file diff --git a/Mvc.JQuery.Datatables/App_Start/RegisterDatatablesModelBinder.cs.pp b/Mvc.JQuery.Datatables/App_Start/RegisterDatatablesModelBinder.cs.pp deleted file mode 100644 index 6568901..0000000 --- a/Mvc.JQuery.Datatables/App_Start/RegisterDatatablesModelBinder.cs.pp +++ /dev/null @@ -1,14 +0,0 @@ -using System.Web.Mvc; -using System.Web.WebPages; - - -[assembly: WebActivator.PreApplicationStartMethod(typeof($rootnamespace$.App_Start.RegisterDatatablesModelBinder), "Start")] - -namespace $rootnamespace$.App_Start { - public static class RegisterDatatablesModelBinder { - public static void Start() { - if (!ModelBinders.Binders.ContainsKey(typeof(Mvc.JQuery.Datatables.DataTablesParam))) - ModelBinders.Binders.Add(typeof(Mvc.JQuery.Datatables.DataTablesParam), new Mvc.JQuery.Datatables.DataTablesModelBinder()); - } - } -} diff --git a/Mvc.JQuery.Datatables/DataTableConfigVm.cs b/Mvc.JQuery.Datatables/DataTableConfigVm.cs index f118533..19222bb 100644 --- a/Mvc.JQuery.Datatables/DataTableConfigVm.cs +++ b/Mvc.JQuery.Datatables/DataTableConfigVm.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Web.Routing; using System.Web.Script.Serialization; +using Mvc.JQuery.Datatables.Models; namespace Mvc.JQuery.Datatables { @@ -14,10 +15,12 @@ public class ColDef public bool Sortable { get; set; } public Type Type { get; set; } public bool Searchable { get; set; } + public SortDirection SortDirection { get; set; } + public string MRenderFunction { get; set; } - public static ColDef Create(string name, string p1, Type propertyType, bool visible = true, bool sortable = true) + public static ColDef Create(string name, string p1, Type propertyType, bool visible = true, bool sortable = true, SortDirection sortDirection = SortDirection.None, string mRenderFunction = null) { - return new ColDef() {Name = name, DisplayName = p1, Type = propertyType, Visible = visible, Sortable = sortable}; + return new ColDef() {Name = name, DisplayName = p1, Type = propertyType, Visible = visible, Sortable = sortable, SortDirection = sortDirection, MRenderFunction = mRenderFunction }; } } public class DataTableConfigVm @@ -106,6 +109,14 @@ public string Dom } } + public string ColumnSortingString + { + get + { + return convertColumnSortingToJson(Columns); + } + } + public bool ShowPageSizes { get; set; } public bool StateSave { get; set; } @@ -243,6 +254,7 @@ private static string convertColumnDefsToJson(IEnumerable columns) var nonSortableColumns = columns.Select((x, idx) => x.Sortable ? -1 : idx).Where( x => x > -1).ToArray(); var nonVisibleColumns = columns.Select((x, idx) => x.Visible ? -1 : idx).Where(x => x > -1).ToArray(); var nonSearchableColumns = columns.Select((x, idx) => x.Searchable ? -1 : idx).Where(x => x > -1).ToArray(); + var mRenderColumns = columns.Select((x, idx) => string.IsNullOrEmpty(x.MRenderFunction) ? new { x.MRenderFunction, Index = -1 } : new { x.MRenderFunction, Index = idx }).Where(x => x.Index > -1).ToArray(); var defs = new List(); @@ -252,9 +264,24 @@ private static string convertColumnDefsToJson(IEnumerable columns) defs.Add(new { bVisible = false, aTargets = nonVisibleColumns }); if (nonSearchableColumns.Any()) defs.Add(new { bSearchable = false, aTargets = nonSearchableColumns }); + if (mRenderColumns.Any()) + foreach (var mRenderColumn in mRenderColumns) + { + defs.Add(new { mRender = "%" + mRenderColumn.MRenderFunction + "%", aTargets = new[] {mRenderColumn.Index} }); + } + + if (defs.Count > 0) + return new JavaScriptSerializer().Serialize(defs).Replace("\"%", "").Replace("%\"", ""); + + return "[]"; + } + + private static string convertColumnSortingToJson(IEnumerable columns) + { + var sortList = columns.Select((c, idx) => c.SortDirection == SortDirection.None ? new dynamic[] { -1, "" } : (c.SortDirection == SortDirection.Ascending ? new dynamic[] { idx, "asc" } : new dynamic[] { idx, "desc" })).Where(x => x[0] > -1).ToArray(); - if (defs.Count > 0) - return new JavaScriptSerializer().Serialize(defs); + if (sortList.Length > 0) + return new JavaScriptSerializer().Serialize(sortList); return "[]"; } diff --git a/Mvc.JQuery.Datatables/DataTablesHelper.cs b/Mvc.JQuery.Datatables/DataTablesHelper.cs index 029aabc..dd5d17a 100644 --- a/Mvc.JQuery.Datatables/DataTablesHelper.cs +++ b/Mvc.JQuery.Datatables/DataTablesHelper.cs @@ -47,7 +47,9 @@ public static DataTableConfigVm DataTableVm(this HtmlHelpe Sortable = pi.Item2.Sortable, Visible = pi.Item2.Visible, Searchable = pi.Item2.Searchable, - Type = pi.Item1.PropertyType + Type = pi.Item1.PropertyType, + SortDirection = pi.Item2.SortDirection, + MRenderFunction = pi.Item2.MRenderFunction }); } columns = columnList.ToArray(); diff --git a/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs b/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs index 69c71cd..89add0f 100644 --- a/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs +++ b/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs @@ -56,7 +56,16 @@ public DataTablesAttribute() public bool Sortable { get; set; } public int? Order { get; set; } public string DisplayName { get; set; } + public SortDirection SortDirection { get; set; } + public string MRenderFunction { get; set; } public bool Visible { get; set; } } + + public enum SortDirection + { + None, + Ascending, + Descending + } } \ No newline at end of file diff --git a/Mvc.JQuery.Datatables/Models/oLanguage.cs b/Mvc.JQuery.Datatables/Models/oLanguage.cs new file mode 100644 index 0000000..db58e6f --- /dev/null +++ b/Mvc.JQuery.Datatables/Models/oLanguage.cs @@ -0,0 +1,31 @@ +using System.Web.Script.Serialization; + +namespace Mvc.JQuery.Datatables.Models +{ + public class Paginate + { + public string sFirst { get; set; } + public string sPrevious { get; set; } + public string sNext { get; set; } + public string sLast { get; set; } + } + + public class Language + { + public string sProcessing { get; set; } + public string sLengthMenu { get; set; } + public string sZeroRecords { get; set; } + public string sInfo { get; set; } + public string sInfoEmpty { get; set; } + public string sInfoFiltered { get; set; } + public string sInfoPostFix { get; set; } + public string sSearch { get; set; } + public string sUrl { get; set; } + public Paginate oPaginate { get; set; } + + public string ToJsonString() + { + return new JavaScriptSerializer().Serialize(this); + } + } +} \ No newline at end of file diff --git a/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj b/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj index 9d78540..00020e4 100644 --- a/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj +++ b/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj @@ -34,10 +34,6 @@ - - True - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - @@ -48,9 +44,6 @@ - - ..\packages\WebActivator.1.5\lib\net40\WebActivator.dll - @@ -61,6 +54,7 @@ + @@ -71,10 +65,7 @@ Views\Shared\DataTable.cshtml - - - Designer - + diff --git a/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.nuspec b/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.nuspec index 931d93e..62dfbe4 100644 --- a/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.nuspec +++ b/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.nuspec @@ -12,7 +12,4 @@ Copyright 2011 jquery datatables iqueryable razor - - - \ No newline at end of file diff --git a/Mvc.JQuery.Datatables/RegisterDatatablesModelBinder.cs b/Mvc.JQuery.Datatables/RegisterDatatablesModelBinder.cs new file mode 100644 index 0000000..4dc0b74 --- /dev/null +++ b/Mvc.JQuery.Datatables/RegisterDatatablesModelBinder.cs @@ -0,0 +1,15 @@ +using System.Web; +using System.Web.Mvc; +using System.Web.WebPages; +using Mvc.JQuery.Datatables; + +[assembly: PreApplicationStartMethod(typeof(RegisterDatatablesModelBinder), "Start")] + +namespace Mvc.JQuery.Datatables { + public static class RegisterDatatablesModelBinder { + public static void Start() { + if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesParam))) + ModelBinders.Binders.Add(typeof(DataTablesParam), new Mvc.JQuery.Datatables.DataTablesModelBinder()); + } + } +} diff --git a/Mvc.JQuery.Datatables/packages.config b/Mvc.JQuery.Datatables/packages.config deleted file mode 100644 index 6385f6b..0000000 --- a/Mvc.JQuery.Datatables/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/WebActivator.1.5/WebActivator.1.5.nupkg b/packages/WebActivator.1.5/WebActivator.1.5.nupkg deleted file mode 100644 index e31d7a7..0000000 Binary files a/packages/WebActivator.1.5/WebActivator.1.5.nupkg and /dev/null differ diff --git a/packages/WebActivator.1.5/lib/net40/WebActivator.dll b/packages/WebActivator.1.5/lib/net40/WebActivator.dll deleted file mode 100644 index 7f70e86..0000000 Binary files a/packages/WebActivator.1.5/lib/net40/WebActivator.dll and /dev/null differ diff --git a/packages/repositories.config b/packages/repositories.config index 91b6799..56cb62e 100644 --- a/packages/repositories.config +++ b/packages/repositories.config @@ -2,5 +2,4 @@ - \ No newline at end of file