mvc and angular

Introduction

This article shows how to create a Master and Detail Grid using AngularJS and WCF. In this article we will see:

  1. How to create a WCF Rest service and retrieve data from the database.

  2. How to install an AngularJS Package in our MVC application.

  3. How to create our AngularJS application to create our own Master Detail Grid.

  4. How to use a WCS service in AngularJS and bind the data of both a Master and Detail to our MVC View.
Note: a prerequisite is Visual Studio 2013. If you don't have Visual Studio 2013, you can download it from the Microsoft website.

Here we can see some basic and reference links for the following.

Windows Communication Foundation (WCF): WCF is a framework for building service-oriented applications.

Service-oriented application: Using this protocol the service can be shared and used over a network.

For example let's consider now we are working on a project and we need to create some common database function and those functions need to be used in multiple projects and the projects are in multiple places and connected via a network such as the internet.

In this case we can create a WCF service and we can write all our common database functions in our WCF service class. We can deploy our WCF in IIS and use the URL in our application to do DB functions. In the code part let's see how to create a WCF REST service and use it in our AngularJS application.

If you are interested in reading more details about WCF then kindly go to this link.

AngularJS

We might be be familiar with what is Model, View and View Model (MVVM) and Model, View and Controller (MVC) are. AngularJS is a JavaScript framework that is purely based on HTML CSS and JavaScript .

Similar to the MVC and MVVM patterns AngularJS uses the Model, View and Whatever (MVW) pattern.

In our example I have used Model, View and Service. In the code part let's see how to Install and create AngularJS in our MVC application.

If you are interested in reading more details about AngularJS then kindly go to this link.

Code Part

Create Database and Table

We will create an Order Master and Order Detail table to be used for the Master and Detail Grid data binding.

The following is the script to create a database, table and sample insert query.

Run this script in your SQL Server. I have used SQL Server 2008 R2.

  1. --create DataBase
  2. Create Database OrderManagement
  3. -- Create OrderMasters Table
  4. CREATE TABLE [dbo].[OrderMasters](
  5. [Order_No] [varchar](20) NOT NULL,
  6. [Table_ID] [varchar](20) NOT NULL,
  7. [Description] [varchar](200) NOT NULL,
  8. [Order_DATE] [datetime] NOT NULL,
  9. [Waiter_Name] [varchar](20) NOT NULL
  10. CONSTRAINT [PK_OrderMasters] PRIMARY KEY CLUSTERED
  11. (
  12. [Order_No] ASC
  13. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  14. ) ON [PRIMARY]
  15. -- Insert OrderMasters sample data
  16. INSERT INTO [OrderMasters]
  17. ([Order_No],[Table_ID] ,[Description],[Order_DATE],[Waiter_Name])
  18. VALUES
  19. ('ORD_001','T1','Order for Table T1',GETDATE(),'SHANU' )
  20. INSERT INTO [OrderMasters]
  21. ([Order_No],[Table_ID] ,[Description],[Order_DATE],[Waiter_Name])
  22. VALUES
  23. ('ORD_002','T2','Order for Table T2',GETDATE(),'Afraz' )
  24. INSERT INTO [OrderMasters]
  25. ([Order_No],[Table_ID] ,[Description],[Order_DATE],[Waiter_Name])
  26. VALUES
  27. ('ORD_003','T3','Order for Table T3',GETDATE(),'Afreen')
  28. CREATE TABLE [dbo].[OrderDetails](
  29. [Order_Detail_No] [varchar](20) NOT NULL,
  30. [Order_No] [varchar](20) CONSTRAINT fk_OrderMasters FOREIGN KEY REFERENCES OrderMasters(Order_No),
  31. [Item_Name] [varchar](20) NOT NULL,
  32. [Notes] [varchar](200) NOT NULL,
  33. [QTY] INT NOT NULL,
  34. [Price] INT NOT NULL
  35. CONSTRAINT [PK_OrderDetails] PRIMARY KEY CLUSTERED
  36. (
  37. [Order_Detail_No] ASC
  38. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  39. ) ON [PRIMARY]
  40. --Now let’s insert the 3 items for the above Order No 'Ord_001'.
  41. INSERT INTO [OrderDetails]
  42. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  43. VALUES
  44. ('OR_DT_001','ORD_001','Ice Cream','Need very Cold',2 ,160)
  45. INSERT INTO [OrderDetails]
  46. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  47. VALUES
  48. ('OR_DT_002','ORD_001','Coffee','Hot and more Suger',1 ,80)
  49. INSERT INTO [OrderDetails]
  50. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  51. VALUES
  52. ('OR_DT_003','ORD_001','Burger','Spicy',3 ,140)
  53. INSERT INTO [OrderDetails]
  54. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  55. VALUES
  56. ('OR_DT_004','ORD_002','Pizza','More Chees and Large',1 ,350)
  57. INSERT INTO [OrderDetails]
  58. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  59. VALUES
  60. ('OR_DT_005','ORD_002','Cola','Need very Cold',3 ,50)
  61. INSERT INTO [OrderDetails]
  62. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  63. VALUES
  64. ('OR_DT_006','ORD_003','IDLY','Hot',3 ,40)
  65. INSERT INTO [OrderDetails]
  66. ([Order_Detail_No],[Order_No],[Item_Name],[Notes],[QTY] ,[Price])
  67. VALUES
  68. ('OR_DT_007','ORD_003','Thosa','Hot',3 ,50)
  69. -- To Select and test Order Master and Details
  70. Select * FROM OrderMasters
  71. Select * From OrderDetails

Create WCF REST Service

Open Visual Studio 2013 then select "File" -> "New" -> "Project..." then select WCF Service Application then select your project path and name your WCF service and click OK.

new wcf service

Once we have created our WCF Service we can see “IService.CS” and “Service1.svc” in the Solution Explorer as in the following.

solution explorer

The following code will be automatically created for all the IService.CS files. We can change and write our own code here.

  1. public interface IService1
  2. {
  3. [OperationContract]
  4. string GetData(int value);
  5. [OperationContract]
  6. CompositeType GetDataUsingDataContract(CompositeType composite);
  7. // TODO: Add your service operations here
  8. }
  9. // Use a data contract as illustrated in the sample below to add composite types to service operations.
  10. [DataContract]
  11. public class CompositeType
  12. {
  13. bool boolValue = true;
  14. string stringValue = "Hello ";
  15. [DataMember]
  16. public bool BoolValue
  17. {
  18. get { return boolValue; }
  19. set { boolValue = value; }
  20. }
  21. [DataMember]
  22. public string StringValue
  23. {
  24. get { return stringValue; }
  25. set { stringValue = value; }
  26. }
  27. }

Data Contract

In our example we need to get both an Order Master and an Order Details from the database, so I have created two Data Contracts, “OrderMasterDataContract” and “OrderDetailDataContract”.

Here we can see we have declarared all our Table column names as Data Member.

  1. public class OrderDataContract
  2. {
  3. [DataContract]
  4. public class OrderMasterDataContract
  5. {
  6. [DataMember]
  7. public string Order_No { get; set; }
  8. [DataMember]
  9. public string Table_ID { get; set; }
  10. [DataMember]
  11. public string Description { get; set; }
  12. [DataMember]
  13. public string Order_DATE { get; set; }
  14. [DataMember]
  15. public string Waiter_Name { get; set; }
  16. }
  17. [DataContract]
  18. public class OrderDetailDataContract
  19. {
  20. [DataMember]
  21. public string Order_Detail_No { get; set; }
  22. [DataMember]
  23. public string Order_No { get; set; }
  24. [DataMember]
  25. public string Item_Name { get; set; }
  26. [DataMember]
  27. public string Notes { get; set; }
  28. [DataMember]
  29. public string QTY { get; set; }
  30. [DataMember]
  31. public string Price { get; set; }
  32. }
  33. }

Service Contract

In the Operation Contract we can see “WebInvoke” and “WebGet” for retrieving the data from the database in the REST Serivce.

  1. RequestFormat = WebMessageFormat.Json,
  2. ResponseFormat = WebMessageFormat.Json,

Here we can see both of the request and response formats. Here I have used the JavaScript Object Notation (JSON) format.

Here I have declared the 3 methods “GetOrderMaster”, “SearchOrderMaster” and “OrderDetails” . The “GetOrderMaster” method gets the Order Master records. In the “OrderDetails” method the Order_No parameter provides the order detail filter by Order Number.

  1. [ServiceContract]
  2. public interface IService1
  3. {
  4. [OperationContract]
  5. [WebInvoke(Method = "GET",
  6. RequestFormat = WebMessageFormat.Json,
  7. ResponseFormat = WebMessageFormat.Json,
  8. UriTemplate = "/GetOrderMaster/")]
  9. List<OrderDataContract.OrderMasterDataContract> GetOrderMaster();
  10. [OperationContract]
  11. [WebGet(RequestFormat = WebMessageFormat.Json,
  12. ResponseFormat = WebMessageFormat.Json,
  13. UriTemplate = "/SearchOrderMaster/{Order_No}")]
  14. OrderDataContract.OrderMasterDataContract SearchOrderMaster(string Order_No);
  15. [OperationContract]
  16. [WebInvoke(Method = "GET",
  17. RequestFormat = WebMessageFormat.Json,
  18. ResponseFormat = WebMessageFormat.Json,
  19. UriTemplate = "/OrderDetails/{Order_No}")]
  20. List<OrderDataContract.OrderDetailDataContract> OrderDetails(string Order_No);
  21. }

Iservice.Cs: Complete Source Code

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.ServiceModel.Web;
  7. using System.Text;
  8. namespace Shanu_WCFDBService
  9. {
  10. // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
  11. [ServiceContract]
  12. public interface IService1
  13. {
  14. [OperationContract]
  15. [WebInvoke(Method = "GET",
  16. RequestFormat = WebMessageFormat.Json,
  17. ResponseFormat = WebMessageFormat.Json,
  18. UriTemplate = "/GetOrderMaster/")]
  19. List<OrderDataContract.OrderMasterDataContract> GetOrderMaster();
  20. [OperationContract]
  21. [WebGet(RequestFormat = WebMessageFormat.Json,
  22. ResponseFormat = WebMessageFormat.Json,
  23. UriTemplate = "/SearchOrderMaster/{Order_No}")]
  24. OrderDataContract.OrderMasterDataContract SearchOrderMaster(string Order_No); [OperationContract]
  25. [WebInvoke(Method = "GET",
  26. RequestFormat = WebMessageFormat.Json,
  27. ResponseFormat = WebMessageFormat.Json,
  28. UriTemplate = "/OrderDetails/{Order_No}")]
  29. List<OrderDataContract.OrderDetailDataContract> OrderDetails(string Order_No);
  30. }
  31. public class OrderDataContract
  32. {
  33. [DataContract]
  34. public class OrderMasterDataContract
  35. {
  36. [DataMember]
  37. public string Order_No { get; set; }
  38. [DataMember]
  39. public string Table_ID { get; set; }
  40. [DataMember]
  41. public string Description { get; set; }
  42. [DataMember]
  43. public string Order_DATE { get; set; }
  44. [DataMember]
  45. public string Waiter_Name { get; set; }
  46. }
  47. [DataContract]
  48. public class OrderDetailDataContract
  49. {
  50. [DataMember]
  51. public string Order_Detail_No { get; set; }
  52. [DataMember]
  53. public string Order_No { get; set; }
  54. [DataMember]
  55. public string Item_Name { get; set; }
  56. [DataMember]
  57. public string Notes { get; set; }
  58. [DataMember]
  59. public string QTY { get; set; }
  60. [DataMember]
  61. public string Price { get; set; }
  62. }
  63. }
  64. }

Add Database using ADO.NET Entity Data Model

Right-click your WCF project and select Add New Item tehn select ADO.NET Entity Data Model and click Add.

adonet entity data

Select EF Designer from the Database and click "Next".

ef designer from database

Click "New Connection".

 new connection

Here we can select our Database Server Name and enter your DB server SQL Server Authentication User ID and Password. We have already created our database as “OrderManagement” so we can select the database and click OK.

connection properties

Click Next and select tables that need to be used. In our example we need to use “OrderMasters" and “orderDetails”. Select both tables and click "Finish".

entity data model wizard

Here we can see that now we have created our OrderManagementModel.

order management model

Service1.SVC

“Service.SVC.CS” implements the IService Interface and overrides and defines all the methods of the Operation Contract.

For example here we can see I have implemented the IService1 in the Service1 class. Created the object for our Entity model and in GetOrderMaster using a LINQ Query I have selected the data from the OrderMasters table and the result was added to the list.

  1. public class Service1 : IService1
  2. {
  3. OrderManagementEntities OME;
  4. public Service1()
  5. {
  6. OME = new OrderManagementEntities();
  7. }
  8. public List<OrderDataContract.OrderMasterDataContract> GetOrderMaster()
  9. {
  10. var query = (from a in OME.OrderMasters
  11. select a).Distinct();
  12. List<OrderDataContract.OrderMasterDataContract> orderMasterList = new List<OrderDataContract.OrderMasterDataContract>();
  13. query.ToList().ForEach(rec =>
  14. {
  15. orderMasterList.Add(new OrderDataContract.OrderMasterDataContract
  16. {
  17. Order_No = Convert.ToString(rec.Order_No),
  18. Table_ID = rec.Table_ID,
  19. Description = rec.Description,
  20. Order_DATE = Convert.ToString(rec.Order_DATE),
  21. Waiter_Name = rec.Waiter_Name
  22. });
  23. });
  24. return orderMasterList;
  25. }

Service.SVC.CS: Complete Source Code

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.ServiceModel.Web;
  7. using System.Text;
  8. using Shanu_WCFDBService.Model;
  9. namespace Shanu_WCFDBService
  10. {
  11. public class Service1 : IService1
  12. {
  13. OrderManagementEntities OME;
  14. public Service1()
  15. {
  16. OME = new OrderManagementEntities();
  17. }
  18. public List<OrderDataContract.OrderMasterDataContract> GetOrderMaster()
  19. {
  20. var query = (from a in OME.OrderMasters
  21. select a).Distinct();
  22. List<OrderDataContract.OrderMasterDataContract> orderMasterList = new List<OrderDataContract.OrderMasterDataContract>();
  23. query.ToList().ForEach(rec =>
  24. {
  25. orderMasterList.Add(new OrderDataContract.OrderMasterDataContract
  26. {
  27. Order_No = Convert.ToString(rec.Order_No),
  28. Table_ID = rec.Table_ID,
  29. Description = rec.Description,
  30. Order_DATE = Convert.ToString(rec.Order_DATE),
  31. Waiter_Name = rec.Waiter_Name
  32. });
  33. });
  34. return orderMasterList;
  35. }
  36. public OrderDataContract.OrderMasterDataContract SearchOrderMaster(string Order_No)
  37. {
  38. OrderDataContract.OrderMasterDataContract OrderMaster = new OrderDataContract.OrderMasterDataContract();
  39. try
  40. {
  41. var query = (from a in OME.OrderMasters
  42. where a.Order_No.Equals(Order_No)
  43. select a).Distinct().FirstOrDefault();
  44. OrderMaster.Order_No = Convert.ToString(query.Order_No);
  45. OrderMaster.Table_ID = query.Table_ID;
  46. OrderMaster.Description = query.Description;
  47. OrderMaster.Order_DATE = Convert.ToString(query.Order_DATE);
  48. OrderMaster.Waiter_Name = query.Waiter_Name;
  49. }
  50. catch (Exception ex)
  51. {
  52. throw new FaultException<string>
  53. (ex.Message);
  54. }
  55. return OrderMaster;
  56. }
  57. public List<OrderDataContract.OrderDetailDataContract> OrderDetails(string Order_No)
  58. {
  59. var query = (from a in OME.OrderDetails
  60. where a.Order_No.Equals(Order_No)
  61. select a).Distinct();
  62. List<OrderDataContract.OrderDetailDataContract> OrderDetailList = new List<OrderDataContract.OrderDetailDataContract>();
  63. query.ToList().ForEach(rec =>
  64. {
  65. OrderDetailList.Add(new OrderDataContract.OrderDetailDataContract
  66. {
  67. Order_Detail_No = Convert.ToString(rec.Order_Detail_No),
  68. Order_No = Convert.ToString(rec.Order_No),
  69. Item_Name = rec.Item_Name,
  70. Notes = rec.Notes,
  71. QTY = Convert.ToString(rec.QTY),
  72. Price = Convert.ToString(rec.Price)
  73. });
  74. });
  75. return OrderDetailList;
  76. }
  77. }
  78. }

Web.Config

In the WCF project's “Web.Config”, make the following changes:

  1. Change <add binding="basicHttpsBinding" scheme="https" /> to <add binding="webHttpBinding" scheme="http" />

  2. Replace the </behaviors> to:
    1. <endpointBehaviors>
    2. <behavior>
    3. <webHttp helpEnabled="True"/>
    4. </behavior>
    5. </endpointBehaviors>
    6. </behaviors>
Run WCF Service

Now we have created our WCF Rest service, let's run and test our service.

run wcf service

In our service URL we can add our method name and we can see the JSON result data from the database.

get order master

So now we have completed our WCF and now it's time to create our MVC AngularJS application.

We can add a new project to our existing project and create a new MVC web application as in the following.

Right-click the project in the solution and click Add New Project then enter your project name and click "OK".

ass aspnet web app

Select MVC and click "OK".

select mvc

Now we have created our MVC application and it's time to add our WCF Service and install the AngularJS package to our solution.

Add WCF Service: Right-click MVC Solution and click Add then click Service Reference.

add reference

Enter your WCF URL and click GO. Here my WCF URL is http://localhost:2505/Service1.svc.

Add your name and click "OK".

add service reference

Now we have successfully added our WCF Service to our MVC application.

wcf service added

Procedure to Install AngularJS package

Right-click your MVC project and click "Manage NuGet Packages".

manage nuget package

Select Online and Search for AngularJS. Select the AngularJs and click Install.

install angularjs

Now we have Installed the AngularJS package into our MVC Project. Now let's create our AngularJs.

Procedure to Create AngularJs Script Files

Right-click the Script folder and create your own folder to create the AngularJs Model/Controller and Service JavaScript. In your script folder add three JavaScript files and name them Modules.js, Controllers.js and Services.js as in the following.

scripts

Modules.js: Here we add the reference to the Angular.js JavaScript and create an angular module named “RESTClientModule”.

  1. /// <reference path="../angular.js" />
  2. /// <reference path="../angular.min.js" />
  3. var app;
  4. (function () {
  5. app = angular.module("RESTClientModule", []);
  6. })();

Services.js: Here we add the reference to the Angular.js JavaScript and our Module.js.

Here we provide a name for our service and we use this name in controllers.js. Here for the Angular service I have given the name "AngularJs_WCFService". You can give your own name but be careful of changing the name in Controllers.js. Here we can see in the method since I have passed the URL of our webservice.

  1. /// <reference path="../angular.js" />
  2. /// <reference path="../angular.min.js" />
  3. /// <reference path="Modules.js" />
  4. app.service("AngularJs_WCFService", function ($http) {
  5. //Get Order Master Records
  6. this.getOrdermaster = function () {
  7. return $http.get("http://localhost:2505/Service1.svc/GetOrderMaster");
  8. };
  9. //Search Order Master Records
  10. this.getSearchOrder = function (OrderNO) {
  11. return $http.get("http://localhost:2505/Service1.svc/SearchOrderMaster/" + OrderNO);
  12. }
  13. //Search Order Details Records
  14. this.getOrderDetail = function (OrderNO) {
  15. return $http.get("http://localhost:2505/Service1.svc/OrderDetails/" + OrderNO);
  16. }
  17. });

Controllers.js: Here we add the reference to the Angular.js JavaScript and our Module.js and Services.js. The same as for the services for the controller I have given the name "AngularJs_WCFController".

First I get the current data and store the date using $scope.date.

I have created the method GetOrderMasters() and using the Services module I get the obtained Order Master table and bind the result to the “$scope.OrderMastersDisp = pl.data”. The same as that we create all the rest of the methods.

  1. /// <reference path="../angular.js" />
  2. /// <reference path="../angular.min.js" />
  3. /// <reference path="Modules.js" />
  4. /// <reference path="Services.js" />
  5. app.controller("AngularJs_WCFController", function ($scope, $window, AngularJs_WCFService) {
  6. $scope.date = new Date();
  7. GetOrderMasters();
  8. //To Get All Records
  9. function GetOrderMasters() {
  10. var promiseGet = AngularJs_WCFService.getOrdermaster();
  11. promiseGet.then(function (pl) {
  12. $scope.OrderMastersDisp = pl.data
  13. },
  14. function (errorPl) {
  15. });
  16. }
  17. Hidetables()
  18. function Hidetables() {
  19. $scope.isRowHidden = false;
  20. }
  21. $scope.get = function (Order) {
  22. if (Order == null) {
  23. return;
  24. }
  25. if (Order.isRowHidden == true) {
  26. Order.isRowHidden = false;
  27. var promiseGet = AngularJs_WCFService.getOrderDetail(Order.Order_No);
  28. promiseGet.then(function (pl) {
  29. $scope.OrderDetailDisp = pl.data
  30. },
  31. function (errorPl) {
  32. });
  33. }
  34. else {
  35. Order.isRowHidden = true;
  36. }
  37. }
  38. });

So now we have created our Angular Js Module, Controller and Service. So what is next?

Create MVC Control and View to display our result.

Add Controller

Right-click Controllers then select Add Controller then select MVC 5 Controller –Empty then click Add.

add controler

Change the Controller name and here I have given it the name “OrderManagementController” and click OK.

Add View

Right-click on the Controller Index and click Add View.

add view

Name the View “Index”.

In the View design your page and reference angular.Js, Modules.js, Services.js and Controllers.js.

In AngulaJS we use {{ }} to bind or display the data. Here we can see that first I create one table and for that a table.

First in the table I have used the data-ng-controller="AngularJs_WCFController" and here we can see the data-ng-controller will be used to bind the data of the controller to our HTML table.

Using <tbody data-ng-repeat="detail in OrderDetailDisp"> we can get all the records and using the <td><span>{{order.Order_No}}</span></td> bind all the data inside the table. The same as that we create an Inner Table. When the user clicks on the Details button I will display the Order Details table.

  1. <html data-ng-app="RESTClientModule">
  2. @{
  3. ViewBag.Title = "SHANU AngularJs / WCF and Master Detail Grid";
  4. }
  5. <body>
  6. <img src="~/Images/blank.gif" alt="" width="1" height="10" />
  7. <table width="99%" style=" border-bottom:3px solid #3273d5;">
  8. <tr>
  9. <td width=" 250">
  10. <table width="99%">
  11. <tr>
  12. <td>
  13. Welcome Mr. {{'SHANU'}} .
  14. </td>
  15. </tr>
  16. </table>
  17. </td>
  18. <td class="style1" align="center">
  19. <h3>Order Master / Detail Grid using Angular JS and WCF in MVC :)</h3>
  20. </td>
  21. <td align="right">
  22. <div ng-controller="AngularJs_WCFController">
  23. Today Date is :
  24. {{date | date:'yyyy-MM-dd'}}
  25. </div>
  26. </td>
  27. </tr>
  28. </table>
  29. <img src="~/Images/blank.gif" alt="" width="1" height="10" />
  30. <table id="tblContainer" data-ng-controller="AngularJs_WCFController" style='width: 99%;table-layout:fixed;'>
  31. <tr>
  32. <td>
  33. <table style=" background-color:#ECF3F4; border: solid 2px #3273d5; padding: 5px;width: 99%;table-layout:fixed;">
  34. <tr style="height: 30px; background-color:#336699 ; color:#FFFFFF ;">
  35. <th width="60"></th>
  36. <th>Order No</th>
  37. <th>Table ID</th>
  38. <th>Notes</th>
  39. <th>Order DATE</th>
  40. <th>Waiter Name</th>
  41. <th></th>
  42. </tr>
  43. <tbody data-ng-repeat="order in OrderMastersDisp">
  44. <tr>
  45. <td width="60">
  46. <input type="button" id="Detail" value="Detail" data-ng-click="get(order)" />
  47. </td>
  48. <td><span>{{order.Order_No}}</span></td>
  49. <td><span>{{order.Table_ID}}</span></td>
  50. <td><span>{{order.Description}}</span></td>
  51. <td><span>{{order.Order_DATE}}</span></td>
  52. <td><span>{{order.Waiter_Name}}</span></td>
  53. <td></td>
  54. </tr>
  55. <tr id={{order.Order_No}} ng-hide="order.isRowHidden" ng-init="get(order)">
  56. <td> </td>
  57. <td colspan="6">
  58. <table style=" background-color:#ECF3F4; border: solid 2px #3273d5; padding: 5px;width: 99%;table-layout:fixed;">
  59. <tr style="height: 30px; background-color:#336699 ; color:#FFFFFF ;">
  60. <th>Order No</th>
  61. <th>Order Detail No</th>
  62. <th>Item Name</th>
  63. <th>Comments</th>
  64. <th>QTY</th>
  65. <th>Price</th>
  66. </tr>
  67. <tbody data-ng-repeat="detail in OrderDetailDisp">
  68. <tr>
  69. <td><span>{{detail.Order_No}}</span></td>
  70. <td><span>{{detail.Order_Detail_No}}</span></td>
  71. <td><span>{{detail.Item_Name}}</span></td>
  72. <td><span>{{detail.Notes}}</span></td>
  73. <td><span>{{detail.QTY}}</span></td>
  74. <td><span>{{detail.Price}}</span></td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </td>
  79. </tr>
  80. </tbody>
  81. </table>
  82. </td>
  83. </tr>
  84. </table>
  85. </body>
  86. </html>
  87. <script src="~/Scripts/angular.js"></script>
  88. <script src="~/Scripts/ShanuAngularScript/Modules.js"></script>
  89. <script src="~/Scripts/ShanuAngularScript/Services.js"></script>
  90. <script src="~/Scripts/ShanuAngularScript/Controllers.js"></script>

Run your program

Here we can see that when I run the program, first I display the Order Master records in the table.

run program

When the user clicks on the Detail button I will display the details of the order in the next row.

order details

Supported browsers: Chrome and Firefox.