Académique Documents
Professionnel Documents
Culture Documents
Introduction
Here in this article, we will see how to Implement jQuery Datatable in ASP.NET MVC application
DataTables is a most powerful and easy to use jQuery plugin for display tabular data (table list
with support for Pagination, searching, State saving, Multi-column sorting with data type dete
and lots more with ZERO or minimal configuration. Most important It is open source.
Do you have AngularJS application? Please visit datatables in AngularJS and asp.net mvc in or
implement datatables in angular application.
Before this article, I have explained How to use Telerik Grid in MVC4 application , How to displa
database data in webgrid in mvc and more about gridview for display tabular data in our applic
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 1/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
DataTables is very easy to use. We just need to add 1 CSS file, and 1 js file and 3 lines of jqu
code as below to start.
1. //cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css
2. //cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js
3. <script>
4. $(document).ready(function () {
5. $('#myTable').DataTable();
6. });
7. </script>
8.
But it will be useful when I will fetch data from server side for display in jQuery DataTable. So,
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 2/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
we will see How to fetch data from server side and display in jQuery DataTable.
Dotnet Awesome HOME ASP.NET MVC JQUERY ANGULAR
Just follow the following steps in order Implement jQuery Datatable (Ba
initialization) in ASP.NET MVC application.
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 3/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
Chose your data connection > select your database > next > Select tables > enter Model
Dotnet Awesome HOME ASP.NET MVC JQUERY ANGULAR
Namespace > Finish.
Step-6: Add new action into the controller to get the view where we will
implement jQuery DataTable
Here I have added "Index" Action into "Home" Controller. Please write this following code
1. public ActionResult Index()
2. {
3. return View();
4. }
5.
Step-7: Add view for the action (here "Index") & design.
Right Click on Action Method (here right click on Index action) > Add View... > Enter View Nam
Select View Engine (Razor) > Add.
Complete HTML code
1. @{
2. ViewBag.Title = "Index";
3. }
4.
5. <h2>Part 1 : Implement jQuery Datatable in ASP.NET MVC</h2>
6. <div style="width:90%; margin:0 auto;">
7. <table id="myTable">
8. <thead>
9. <tr>
10. <th>Employee Name</th>
11. <th>Company</th>
12. <th>Phone</th>
13. <th>Country</th>
14. <th>City</th>
15. <th>Postal Code</th>
16. </tr>
17. </thead>
18. </table>
19. </div>
20. <style>
21. tr.even {
22. background-color: #F5F5F5 !important;
23. }
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 4/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
Step-8: Add another action (here "loaddata") for fetch data from the
database.
1. public ActionResult loaddata()
2. {
3. using (MyDatabaseEntities dc = new MyDatabaseEntities())
4. {
5. // dc.Configuration.LazyLoadingEnabled = false; // if your table is r
6. var data = dc.Customers.OrderBy(a => a.ContactName).ToList();
7. return Json(new { data = data }, JsonRequestBehavior.AllowGet);
8. }
9. }
10.
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 5/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
PREVIOUS NEXT
Creating Google Maps Sample App with AngularJS jQuery Datatable server side pagination and sor
and asp.net MVC in ASP.NET MVC
sourav mondal
RELATED POSTS:
39 Comments Dotnetawesome
1 Lo
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 6/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
Dotnet Awesome
jagadeesh kumar • a year ago
HOME ASP.NET MVC JQUERY ANGULAR
HI,I am getting data into view but paging and sorting are not applying to my page plz help me
△ ▽ • Reply • Share ›
I tried some thing like the code bellow but does not work
DataTable dtTemp = new DataTable();
List<dictionary<string, object="">> rows = new List<dictionary<string, object="">>();
System.Web.Script.Serialization.JavaScriptSerializer serializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
Dictionary<string, object=""> row;
dtTemp = tbl.Clone();
foreach (DataRow dr in tbl.Rows)
{
row = new Dictionary<string, object="">();
foreach (DataColumn col in tbl.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
I am passing parameters and loading data but the data is not rendering into the datatable
$(document).ready(function () {
$('#btnSearch').click(function () {
debugger;
loader()
});
function loader() {
$('#ReportDT').DataTable({
"ajax": {
"url": '@Url.Action("GetTransactions", "Report")',
"data": {
$ $
see more
△ ▽ • Reply • Share ›
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 8/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
Dotnet Awesome
Marjorie Espejo • 2 years ago
HOME ASP.NET MVC JQUERY ANGULAR
Hi! Thank you for this very useful tutorial. Likewise, I have error encountered on javascript. Can
help me with these problem?
Thank you in advance.
⛺
△ ▽ • Reply • Share ›
△ ▽ • Reply • Share ›
sections have been defined but have not been rendered for the layout page
△ ▽ • Reply • Share ›
Dotnet
CanAwesome
you do an example that includes edit save and delete
HOME records.
ASP.NET MVC JQUERY ANGULAR
△ ▽ • Reply • Share ›
@section scripts{
// Add something here
}
△ ▽ • Reply • Share ›
if no, please check your query once, have you executed your query before return?
△ ▽ • Reply • Share ›
⛺
△ ▽ • Reply • Share ›
Dotnet Awesome
Same codes on the above. HOME ASP.NET MVC JQUERY ANGULAR
△ ▽ • Reply • Share ›
"columns": [
{ "data": "Country", "autoWidth": true },
{
"data": "CustomerID",
"render": function (data, type, full, meta) {
return 'Edit';
}
}
]
△ ▽ • Reply • Share ›
⛺
△ ▽ • Reply • Share ›
ALSO ON DOTNETAWESOME
Angular 2 components | DotNet - awesome Import Excel Sheet Data in MS SQL serv
1 comment • 2 years ago Database using AngularJS | DotNet - …
VINAY KUMAR GUPTA — Nice article please 3 comments • 2 years ago
publish angular 2 with web api integration Mujahid Hussain — Dear Sir,Hope you are
only uploads 200 rows. is there in way to
increase the rows records.
✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy
Event/Scheduler calendar in asp.net MVC (70) JQUERY (47) GRID (24) ANGULARJS (2
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 13/14
17/02/2019 Implement jQuery Datatable in ASP.NET MVC application | DotNet - awesome
http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html 14/14