Here, you will find the steps:

Step 1: Here, you will find the table that I used in the Application:

table

After creating the table, you need to fill it, as shown below:

fill

Step 2: Open Visual Studio and add New Project:

add New Project

add New Project

Step 3: Configuring Entity Data Model

Here, we need to follow the steps, as described below to configure EDM.

Configuring

Configuring

Configuring

Step 4: Add new controller

Right click on the controllers folder > Add > Controller > Enter controller name (‘Home’) > Add.

controller

HomeController.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace JQXGridMVC.Controllers
  7. {
  8. public class HomeController : Controller
  9. {
  10. // DbContext
  11. DbPersonnesEntities db = new DbPersonnesEntities();
  12. //
  13. // GET: /Home/
  14. public ActionResult DisplayData()
  15. {
  16. return View();
  17. }
  18. public JsonResult GetCustomers()
  19. {
  20. // Retrieve all data customers from database (DbPersonnes)
  21. var result = db.Customers.ToList();
  22. return Json(result, JsonRequestBehavior.AllowGet);
  23. }
  24. }
  25. }
DisplayData.cshtml
  1. @model IEnumerable<JQXGridMVC.Customers>
  2. @{
  3. ViewBag.Title = "Data Customers";
  4. }
  5. <h2> Data Customers</h2>
  6. <div id="gridCustomers" style="margin:20px auto;"></div>
  7. @section scripts {
  8. <script type="text/javascript" src="http://jqwidgets.com/jquery-widgets-demo/scripts/jquery-1.11.1.min.js"></script>
  9. <script type="text/javascript" src="http://jqwidgets.com/jquery-widgets-demo/jqwidgets/jqx-all.js"></script>
  10. <link rel="stylesheet" type="text/css" href="http://jqwidgets.com/jquery-widgets-demo/jqwidgets/styles/jqx.base.css" />
  11. <script type="text/javascript">
  12. $(document).ready(function () {
  13. // In this part, you need to prepare your data
  14. var source =
  15. {
  16. datatype: "json",
  17. // Here you will declare all fields that must be used in the grid
  18. datafields: [
  19. { name: 'CustomerID', type: 'number' },
  20. { name: 'CustomerName', type: 'string' },
  21. { name: 'CustomerEmail', type: 'string' },
  22. { name: 'CustomerZipCode', type: 'number' },
  23. { name: 'CustomerCountry', type: 'string' },
  24. { name: 'CustomerCity', type: 'string' }
  25. ],
  26. // call the action which retrieve data customers in json format
  27. url: 'Home/GetCustomers'
  28. };
  29. var dataAdapter = new $.jqx.dataAdapter(source);
  30. // displaying data in the grid with jqxGrid
  31. $("#gridCustomers").jqxGrid(
  32. {
  33. width: 800,
  34. source: dataAdapter,
  35. pageable: true,
  36. sortable: true,
  37. columns: [
  38. { text: "Customer ID", datafield: "CustomerID" },
  39. { text: "Customer Name", datafield: "CustomerName" },
  40. { text: "Customer Email", datafield: "CustomerEmail" },
  41. { text: "Customer ZipCode", datafield: "CustomerZipCode" },
  42. { text: "Customer Country", datafield: "CustomerCountry" },
  43. { text: "Customer City", datafield: "CustomerCity" }
  44. ]
  45. });
  46. });
  47. </script>
  48. }
Step 5: Run Application

Application