Skip to content

Commit 7dee074

Browse files
committed
example added
1 parent 6479aa0 commit 7dee074

File tree

7 files changed

+184
-1
lines changed

7 files changed

+184
-1
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
namespace Examples.Mvc.Controllers
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Web.Mvc;
6+
using Examples.Data;
7+
using JQDT.MVC;
8+
9+
public class CustomersController : Controller
10+
{
11+
private AdventureWorks context;
12+
13+
public CustomersController()
14+
{
15+
this.context = new Data.AdventureWorks();
16+
}
17+
18+
// GET: Customer
19+
public ActionResult Index()
20+
{
21+
return View();
22+
}
23+
24+
[JQDataTable]
25+
public ActionResult GetCustomersData()
26+
{
27+
return this.View(this.context.Customers.Select(x => new
28+
{
29+
CustomerID = x.CustomerID,
30+
Person = new PersonModel
31+
{
32+
FirstName = x.Person.FirstName
33+
},
34+
Store = new StoreModel
35+
{
36+
Name = x.Store.Name
37+
}
38+
}));
39+
}
40+
}
41+
42+
public partial class PersonModel
43+
{
44+
public int BusinessEntityID { get; set; }
45+
46+
public string PersonType { get; set; }
47+
48+
public bool NameStyle { get; set; }
49+
50+
public string Title { get; set; }
51+
52+
public string FirstName { get; set; }
53+
54+
public string MiddleName { get; set; }
55+
56+
public string LastName { get; set; }
57+
58+
public string Suffix { get; set; }
59+
60+
public int EmailPromotion { get; set; }
61+
62+
public string AdditionalContactInfo { get; set; }
63+
64+
public string Demographics { get; set; }
65+
66+
public Guid rowguid { get; set; }
67+
68+
public DateTime ModifiedDate { get; set; }
69+
70+
public virtual Employee Employee { get; set; }
71+
72+
public virtual BusinessEntity BusinessEntity { get; set; }
73+
}
74+
75+
public partial class StoreModel
76+
{
77+
public int BusinessEntityID { get; set; }
78+
79+
public string Name { get; set; }
80+
81+
public int? SalesPersonID { get; set; }
82+
83+
public string Demographics { get; set; }
84+
85+
public string rowguid { get; set; }
86+
87+
public DateTime ModifiedDate { get; set; }
88+
89+
public virtual BusinessEntity BusinessEntity { get; set; }
90+
}
91+
}

src/Examples/Examples.Mvc/Examples.Mvc.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
<Compile Include="App_Start\FilterConfig.cs" />
156156
<Compile Include="App_Start\RouteConfig.cs" />
157157
<Compile Include="Controllers\AdventureWorksController.cs" />
158+
<Compile Include="Controllers\CustomersController.cs" />
158159
<Compile Include="Controllers\HomeController.cs" />
159160
<Compile Include="Global.asax.cs">
160161
<DependentUpon>Global.asax</DependentUpon>
@@ -260,6 +261,7 @@
260261
<Content Include="Views\AdventureWorks\Index.cshtml" />
261262
<Content Include="Views\AdventureWorks\Products.cshtml" />
262263
<Content Include="Views\AdventureWorks\Vendors.cshtml" />
264+
<Content Include="Views\Customers\Index.cshtml" />
263265
</ItemGroup>
264266
<ItemGroup>
265267
<Folder Include="App_Data\" />
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
@{
3+
ViewBag.Title = "Index";
4+
Layout = "~/Views/Shared/_Layout.cshtml";
5+
}
6+
7+
<table class="display" cellspacing="0" width="100%">
8+
<thead>
9+
<tr>
10+
<th>Id</th>
11+
<th>First Name</th>
12+
<th>Store Name</th>
13+
</tr>
14+
</thead>
15+
16+
<tfoot>
17+
<tr>
18+
<th>Id</th>
19+
<th>First Name</th>
20+
<th>Store Name</th>
21+
</tr>
22+
</tfoot>
23+
</table>
24+
25+
@section Scripts {
26+
<script>
27+
$('tfoot th').each(function () {
28+
var title = $(this).text();
29+
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
30+
});
31+
32+
var table = $('table').DataTable({
33+
"proccessing": true,
34+
"serverSide": true,
35+
"ajax": {
36+
url: "@Url.Action("GetCustomersData", "Customers")",
37+
type: 'POST'
38+
},
39+
"language": {
40+
"search": "",
41+
"searchPlaceholder": "Search..."
42+
},
43+
"columns": [
44+
{ "data": "CustomerID", "searchable": false },
45+
{ "data": "Person.FirstName", "searchable": true },
46+
{ "data": "Store.Name", "searchable": true },
47+
],
48+
//"columnDefs": [
49+
// {
50+
// "render": function (data, type, row) {
51+
// date = new Date(parseInt(row.ModifiedDate.replace("/Date(", "").replace(")/", ""), 10));
52+
53+
// return date.toISOString();
54+
// },
55+
// "targets": 4
56+
// },
57+
// {
58+
// "render": function (data, type, row) {
59+
// if (!row.DiscontinuedDate) return '';
60+
// date = new Date(parseInt(row.DiscontinuedDate.replace("/Date(", "").replace(")/", ""), 10));
61+
62+
// return date.toLocaleDateString();
63+
// },
64+
// "targets": 5
65+
// }
66+
//]
67+
});
68+
69+
table.columns().every(function () {
70+
var that = this;
71+
72+
$('input', this.footer()).on('change', function () {
73+
if (that.search() !== this.value) {
74+
that
75+
.search(this.value)
76+
.draw();
77+
}
78+
});
79+
});
80+
</script>
81+
}

src/Examples/Examples.Mvc/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<li>@Html.ActionLink("Adventure Works Employees", "Index", "AdventureWorks")</li>
2525
<li>@Html.ActionLink("Adventure Works Products", "Products", "AdventureWorks")</li>
2626
<li>@Html.ActionLink("Adventure Works Vendors", "Vendors", "AdventureWorks")</li>
27+
<li>@Html.ActionLink("Customers", "Index", "Customers")</li>
2728
</ul>
2829
</div>
2930
</div>

src/Examples/Examples.Mvc/Web.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
1111
</configSections>
1212
<connectionStrings>
13-
<add name="AdventureWorks" connectionString="data source=.;initial catalog=AdventureWorks2014;integrated security=True" providerName="System.Data.SqlClient" />
13+
<add name="AdventureWorks" connectionString="data source=.;initial catalog=AdventureWorks2014;integrated security=True;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
1414
</connectionStrings>
1515
<appSettings>
1616
<add key="webpages:Version" value="3.0.0.0" />

src/ExamplesDatabase.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Download examples database from here, restore it and fix the connection string in the web.config file of the Examples.Mvc project.
2+
https://msftdbprodsamples.codeplex.com/downloads/get/880661

src/jQueryDT.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notes", "Notes", "{E67DAB1D
4141
TypesSwitches.txt = TypesSwitches.txt
4242
EndProjectSection
4343
EndProject
44+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "db", "db", "{E0C08F20-EB2E-4FC5-8260-5BA8D0CAD7E7}"
45+
ProjectSection(SolutionItems) = preProject
46+
ExamplesDatabase.txt = ExamplesDatabase.txt
47+
EndProjectSection
48+
EndProject
4449
Global
4550
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4651
Debug|Any CPU = Debug|Any CPU
@@ -117,6 +122,7 @@ Global
117122
{647240F0-6F49-426C-A49F-BE7BA6DDBD81} = {B9F020C7-E6AF-4839-A5F6-2FA6EFBB9D95}
118123
{51C58242-648E-4B17-A249-F2C844743A1B} = {EDCECD8E-0A03-4B35-878C-567E148A83BD}
119124
{E67DAB1D-82C4-415C-AB45-812BFF3091A7} = {EDCECD8E-0A03-4B35-878C-567E148A83BD}
125+
{E0C08F20-EB2E-4FC5-8260-5BA8D0CAD7E7} = {AD505AC4-1EFE-4ABF-ACAC-1A8F40606F60}
120126
EndGlobalSection
121127
GlobalSection(ExtensibilityGlobals) = postSolution
122128
SolutionGuid = {131DA7AE-7C14-4656-82C0-6F592D155809}

0 commit comments

Comments
 (0)