Introduction

In this article, you will learn about master details, using jqWidgets Framework with AngularJS. I hope, you will like this.

Note - You can download zip file from jqWidgets.

Create your Application

Open Visual Studio and select File, click New Project.

The "New Project" Window will pop up. Select ASP.NET Web Application (.NET Framework), name your project and click OK.

template

Next, new Window will pop up for selecting the template. We are going to choose Empty and click OK.

Part

Angular Part

Here, we need to create a new folder, which includes two JS files respectively- Customer App.js and CustomerController.js.

Angular

In order to create new JS files. Right click on CustomerApp folder > Add > JavaScript File.

Angular

Angular

CustomerApp.js

  1. var app = angular.module('myApp', ['ngRoute', 'jqwidgets']);
  2. app.config(['$routeProvider', function($routeProvider) {
  3. $routeProvider.when('/MasterDetail', {
  4. templateUrl: '/CustomerApp/Views/MasterDetailsDemo.html',
  5. controller: 'CustomerController'
  6. }).otherwise({
  7. controller: 'CustomerController'
  8. });
  9. }]);
As you can see above, we have definedAngularJS module(in our case myApp) and injecting ngRoute module, which allows us to use routing thenjqwidgetsmodule to use Master Details control.

CustomerController.js
  1. app.controller('CustomerController', function($scope) {
  2. $scope.orderGrid = {};
  3. $scope.customerGrid = {};
  4. $scope.customers = [{
  5. "CustomerID": "ALFKI",
  6. "CompanyName": "Alfreds Futterkiste",
  7. "ContactName": "Maria Anders",
  8. "ContactTitle": "Sales Representative",
  9. "City": "Berlin",
  10. "Country": "Germany"
  11. }, {
  12. "CustomerID": "ANATR",
  13. "CompanyName": "Ana Trujillo Emparedados y helados",
  14. "ContactName": "Ana Trujillo",
  15. "ContactTitle": "Owner",
  16. "City": "Mxico D.F.",
  17. "Country": "Mexico",
  18. }, {
  19. "CustomerID": "ANTON",
  20. "CompanyName": "Antonio Moreno Taquera",
  21. "ContactName": "Antonio Moreno",
  22. "ContactTitle": "Owner",
  23. "City": "Mxico D.F.",
  24. "Country": "Mexico"
  25. }];
  26. $scope.orders = [{
  27. "OrderID": 10248,
  28. "CustomerID": "ALFKI",
  29. "EmployeeID": 5,
  30. "OrderDate": "1996-07-04 00:00:00",
  31. "RequiredDate": "1996-08-01 00:00:00",
  32. "ShippedDate": "1996-07-16 00:00:00",
  33. "ShipVia": 3,
  34. "Freight": 32.3800,
  35. "ShipName": "Vins et alcools Chevalier"
  36. }, {
  37. "OrderID": 10249,
  38. "CustomerID": "ALFKI",
  39. "EmployeeID": 6,
  40. "OrderDate": "1996-07-05 00:00:00",
  41. "RequiredDate": "1996-08-16 00:00:00",
  42. "ShippedDate": "1996-07-10 00:00:00",
  43. "ShipVia": 1,
  44. "Freight": 11.6100,
  45. "ShipName": "Toms Spezialitten"
  46. }, {
  47. "OrderID": 10250,
  48. "CustomerID": "ANATR",
  49. "EmployeeID": 4,
  50. "OrderDate": "1996-07-08 00:00:00",
  51. "RequiredDate": "1996-08-05 00:00:00",
  52. "ShippedDate": "1996-07-12 00:00:00",
  53. "ShipVia": 2,
  54. "Freight": 65.8300,
  55. "ShipName": "Hanari Carnes",
  56. }, {
  57. "OrderID": 10251,
  58. "CustomerID": "ANATR",
  59. "EmployeeID": 3,
  60. "OrderDate": "1996-07-08 00:00:00",
  61. "RequiredDate": "1996-08-05 00:00:00",
  62. "ShippedDate": "1996-07-15 00:00:00",
  63. "ShipVia": 1,
  64. "Freight": 41.3400,
  65. "ShipName": "Victuailles en stock"
  66. }, {
  67. "OrderID": 10252,
  68. "CustomerID": "ANTON",
  69. "EmployeeID": 4,
  70. "OrderDate": "1996-07-09 00:00:00",
  71. "RequiredDate": "1996-08-06 00:00:00",
  72. "ShippedDate": "1996-07-11 00:00:00",
  73. "ShipVia": 2,
  74. "Freight": 51.3000,
  75. "ShipName": "Suprmes dlices"
  76. }];
  77. $scope.ordersData = [];
  78. $scope.customerGridSettings = {
  79. width: 850,
  80. height: 250,
  81. source: $scope.customers,
  82. keyboardnavigation: true,
  83. columns: [{
  84. text: 'Company Name',
  85. datafield: 'CompanyName',
  86. width: 250
  87. }, {
  88. text: 'Contact Name',
  89. datafield: 'ContactName',
  90. width: 150
  91. }, {
  92. text: 'Contact Title',
  93. datafield: 'ContactTitle',
  94. width: 180
  95. }, {
  96. text: 'City',
  97. datafield: 'City',
  98. width: 120
  99. }, {
  100. text: 'Country',
  101. datafield: 'Country'
  102. }],
  103. rowselect: function(event) {
  104. var customerID = event.args.row.CustomerID;
  105. var records = new Array();
  106. var length = $scope.orders.length;
  107. for (var i = 0; i < length; i++) {
  108. var record = $scope.orders[i];
  109. if (record.CustomerID == customerID) {
  110. records[records.length] = record;
  111. }
  112. }
  113. $scope.ordersData = records;
  114. }
  115. };
  116. $scope.orderGridSettings = {
  117. width: 850,
  118. height: 250,
  119. source: $scope.ordersData,
  120. keyboardnavigation: true,
  121. columns: [{
  122. text: 'OrderID',
  123. datafield: 'OrderID',
  124. width: 100
  125. }, {
  126. text: 'OrderDate',
  127. datafield: 'OrderDate',
  128. cellsformat: 'd',
  129. width: 150
  130. }, {
  131. text: 'Shipped Date',
  132. datafield: 'ShippedDate',
  133. cellsformat: 'd',
  134. width: 150
  135. }, {
  136. text: 'Ship Name',
  137. datafield: 'ShipName'
  138. }]
  139. };
  140. });
Create HTML Page

To add HTML Page, right click on Views folder> Add > HTML page.

HTML

MasterDetailsDemo.html
  1. <!DOCTYPEhtml>
  2. <html>
  3. <head>
  4. <title></title>
  5. <metacharsetmetacharset="utf-8" />
  6. </head>
  7. <body>
  8. <divclassdivclass="example-description">
  9. <div>
  10. <h3>
  11. Customers List
  12. </h3>
  13. <jqx-gridjqx-settingsjqx-gridjqx-settings="customerGridSettings" jqx-create="customerGridSettings" jqx-instance="customerGrid"></jqx-grid>
  14. <h3>
  15. Orders by Customer
  16. </h3>
  17. <jqx-gridjqx-settingsjqx-gridjqx-settings="orderGridSettings" jqx-create="orderGridSettings" jqx-instance="orderGrid"></jqx-grid>
  18. </div>
  19. </div>
  20. </body>
  21. </html>
Before running, we need to add some libraries inside index.html, as shown below-

Index.html
  1. <!DOCTYPEhtml>
  2. <html>
  3. <head>
  4. <title></title>
  5. <metacharsetmetacharset="utf-8" />
  6. <!-- CSS -->
  7. <linkhreflinkhref="CSS/jqx.base.css" rel="stylesheet" />
  8. </head>
  9. <bodyng-appbodyng-app="myApp">
  10. <divng-view>
  11. </div>
  12. <!-- AngularJS libraries-->
  13. <scriptsrcscriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js">
  14. </script>
  15. <scriptsrcscriptsrc="https://code.angularjs.org/1.4.7/angular-route.js">
  16. </script>
  17. <!-- JS libraries-->
  18. <scriptsrcscriptsrc="scripts/jquery-1.11.1.min.js">
  19. </script>
  20. <scriptsrcscriptsrc="scripts/jqxcore.js">
  21. </script>
  22. <scriptsrcscriptsrc="scripts/jqxdata.js">
  23. </script>
  24. <scriptsrcscriptsrc="scripts/jqxbuttons.js">
  25. </script>
  26. <scriptsrcscriptsrc="scripts/jqxcheckbox.js">
  27. </script>
  28. <scriptsrcscriptsrc="scripts/jqxgrid.js">
  29. </script>
  30. <scriptsrcscriptsrc="scripts/jqxgrid.selection.js">
  31. </script>
  32. <scriptsrcscriptsrc="scripts/jqxmenu.js">
  33. </script>
  34. <scriptsrcscriptsrc="scripts/jqxscrollbar.js">
  35. </script>
  36. <scriptsrcscriptsrc="scripts/jqxgrid.sort.js">
  37. </script>
  38. <scriptsrcscriptsrc="scripts/jqxangular.js">
  39. </script>
  40. <scriptsrcscriptsrc="scripts/demos.js">
  41. </script>
  42. <!-- CustomerApp.js -->
  43. <scriptsrcscriptsrc="CustomerApp/CustomerApp.js">
  44. </script>
  45. <!-- CustomerController.js -->
  46. <scriptsrcscriptsrc="CustomerApp/CustomerController.js">
  47. </script>
  48. </body>
  49. </html>
Output - To run your demo, press F5 and change URL address, as given below-
http://localhost:50035/#/MasterDetail

When you select the customer row, as given in the snapshot below, it will show all the orders related to the customer.

<!DOCTYPEhtml /> <html>  <head>     <title></title>     <metacharset="utf-8" /><bgsound cep=
That’s all. Please send your feedback and queries in the comments box.