2017-04-01 5 views
10

안녕하세요 저는 angularjs와 datatable js가있는 ASP.NET MVC를 사용하여 하나의 응용 프로그램을 만들고 있습니다.여분의 행과 열을 사용하여 각도 j와 데이터 테이블을 사용하여 데이터를 바인딩하는 방법

this 도움말의 도움으로 각도 j의 데이터 테이블을 사용하여 데이터를 표시하는 테이블을 구현했습니다.

그러나 나는 정적과 같은 HTML에서 열 이름과 같은 기능을 사용하여 데이터를 바인딩 할 : 문서 저자

사용 작업을하고있다 :

<table id="entry-grid" datatable="" dt-options="dtOptions" 
     dt-columns="dtColumns" class="table table-hover"> 
</table> 

하지만 난에 의해 이런 식으로하고 싶지 나는 또한 N 추가를 클릭 버튼에 동일한 기능을 사용하여 표 안에 새 열을 추가 할

<table id="tblusers" class="table table-bordered table-striped table-condensed datatable"> 
    <thead> 
    <tr> 
     <th width="2%"></th> 
     <th>User Name</th> 
     <th>Email</th> 
     <th>LoginID</th> 
     <th>Location Name</th> 
     <th>Role</th> 
     <th width="7%" class="center-text">Active</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="user in Users"> 
     <td><a href="#" ng-click="DeleteUser(user)"><span class="icon-trash"></span></a></td> 
     <td><a class="ahyperlink" href="#" ng-click="EditUser(user)">{{user.UserFirstName}} {{user.UserLastName}}</a></td> 
     <td>{{user.UserEmail}}</td> 
     <td>{{user.LoginID}}</td> 
     <td>{{user.LocationName}}</td> 
     <td>{{user.RoleName}}</td> 
     <td class="center-text" ng-if="user.IsActive == true"><span class="icon-check2"></span></td> 
     <td class="center-text" ng-if="user.IsActive == false"><span class="icon-close"></span></td> 
    </tr> 
    </tbody> 
</table> 

: 내 데이터에 따라 NG 반복을 사용하여 동일한 기능 이상 사용 기록.

가능합니까?

예 가능한 경우 어떻게하면 jsfiddle 또는 다른 편집기에서 나를 보여 주면 미리 감사 할 수 있습니다.

하십시오 "각 방법"을 사용하는

+0

당신은 당신의 코드를이 [도움말]에서 볼 수 –

+0

@SamuelJMathew 모든 코드 (http://www.dotnetawesome.com/2016에 대한 몇 가지 빛을 던져 컨트롤러와 지시 코드를 추가 개 pls 수 있습니다 /01/datatables-in-angularjs-and-aspnet-mvc.html) HTML에서 정적으로 바인드 할 질문에 작성한 코드를 제외하고 동일한 코드가 변경되지 않았습니다. –

답변

8
당신은 davidkonrad로 사용할 수

단지 구조 아래와 같이 주석의 link을 제안 다음과 같이 각도로 컨트롤러를 만듭니다.

var app = angular.module('MyApp1', ['datatables']); 
app.controller('homeCtrl', ['$scope', 'HomeService', 
    function ($scope, homeService) { 

     $scope.GetCustomers = function() { 
      homeService.GetCustomers() 
       .then(
       function (response) { 
        debugger; 
        $scope.Customers = response.data; 
       }); 
     } 

     $scope.GetCustomers(); 
    }]) 

서비스 :

app.service('HomeService', ["$http", "$q", function ($http, $q) { 

    this.GetCustomers = function() { 
     debugger; 
     var request = $http({ 
      method: "Get", 
      url: "/home/getdata" 
     }); 
     return request; 
    } 
}]); 
+0

Ohhhh 당신을 다시 만나서 반갑습니다 그것이 작동하는지 아닌지 보자! –

+0

예, 위대한 선생님으로 일하는 중 하나의 문제는 정렬을위한 두 개의 아이콘을 보여 주며 일부 디자인 문제가 있지만 확인해 보겠습니다. 덕분에 언제나 당신은 나를 다시 도왔습니다. davidkonrad에게도 감사드립니다. –

+1

당신은 반가워요. davidkonrad의 대답도 받아 들일 수 있습니다. 세부적으로 확인하지는 않았지만 작동해야합니다. –

4

지시한다 각-dataTables가 datatable="ng"에 의해 데모 비주얼 스튜디오 편집기에서 만든 DOWNLOAD 소스 코드 :

<table id="entry-grid" 
    datatable="ng" 
    dt-options="dtOptions" 
    dt-columns="dtColumns" 
    class="table table-hover"> 
</table> 

그런 다음 열 인덱스보다는 JSON을 해결하기 위해 dtColumns 변경 항목 수 :

$scope.dtColumns = [ 
    DTColumnBuilder.newColumn(0).withTitle('').withOption('width', '2%'), 
    DTColumnBuilder.newColumn(1).withTitle('User Name'), 
    DTColumnBuilder.newColumn(2).withTitle('Email'), 
    DTColumnBuilder.newColumn(3).withTitle('LoginID'), 
    DTColumnBuilder.newColumn(4).withTitle('Location Name'), 
    DTColumnBuilder.newColumn(5).withTitle('Role Name'), 
    DTColumnBuilder.newColumn(6).withTitle('Active').withOption('width', '7%') 
]; 

<thead> 섹션을 건너 뛸 수 있습니다. f 위와 같이하십시오. 마지막으로 나는 하나에 두 개의 마지막 중복 <td> 년대를 줄일 :

HTML :

<table id="entry-grid" datatable="ng" class="table table-hover"> 
      <thead> 
       <tr> 
        <th> 
         CustomerId 
        </th> 
        <th>Company Name </th> 
        <th>Contact Name</th> 
        <th> 
         Phone 
        </th> 
        <th> 
         City 
        </th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="c in Customers"> 
        <td>{{c.CustomerID}}</td> 
        <td>{{c.CompanyName}}</td> 
        <td>{{c.ContactName}}</td> 
        <td>{{c.Phone}}</td>\ 
        <td>{{c.City}}</td> 
       </tr> 
      </tbody> 
     </table> 

<td class="center-text"> 
    <span ng-show="user.IsActive == true" class="icon-check2"></span> 
    <span ng-show="user.IsActive == false" class="icon-close"></span> 
</td> 
+0

나는 당신의 코드를 시도했지만 나에게 콘솔에서 에러를 준다 "undefined의 속성 'match'을 읽을 수 없다.이 [code] (https://drive.google.com/open?id= 0B5YJVBXabqS7b0ZYcml3OUlQVzA) 귀하가 귀하의 의견을 변경하고 선생님 께 감사드립니다. –

+0

@padhiyar, C# 백엔드가있는 각진 프로젝트를 보는 재미 :) 링크가 포함 된 주석을 삭제하십시오. 문제는 this->'$ scope.dtOptions = DTOptionsBuilder.newOptions()입니다.with aption ('ajax', {url : "/ home/getdata", type : "POST"})'이제 각도가 ng-repeat 인 렌더링을 할 수 없습니다. – davidkonrad

+0

'dtOptions = DTOptionsBuilder.newOptions() .PaginationType ('full_numbers')'등, 즉 skip'withOption ('ajax')'을 완전히 사용하면 효과가 있다고 확신합니다. – davidkonrad