2016-07-03 7 views
2

단일 열만있는 테이블에서 작업하고 있습니다. 값은 문자열 배열에서 채워집니다. 하지만 정렬 작업을 수행 할 수 없습니다.스마트 테이블 정렬이 작동하지 않습니다.

내가 여기서 잘못하고있는 것은 무엇입니까?

단계 시도 :

1)은 세인트 안전 SRC 속성을 검증. 검색이 정상적으로 작동합니다. 그래서 st-safe-src 속성이 올바르게 설정되었다고 가정합니다.

2)) <th st-sort-default="true">

3)

4 <th st-sort="user">을 시도 시도 컨트롤러

01 위해 설계자

$scope.Users = {}; 
$scope.RawCollection = {}; 
to 

$scope.Users = []; 
$scope.RawCollection = []; 

코드를 변경

<div ng-app="myApp"> 
    <div ng-controller="myController"> 
     <br /> 
     <br /> 
     <h4 style="padding-left: 24px; font-size: 15px">Select Role</h4> 
     <select style="margin-left:24px" ng-change="HandleRoleChange(SelectedRole)" ng-model="SelectedRole" ng-options="x for x in Roles"></select> 

     <br /> 
     <br /> 
     <input class="defaultTextBox" style="margin-left:24px ; height:25px ; padding-top : 1px ; font-family:Arial, Helvetica, sans-serif" type="text" ng-model="NewUser"> <input class="btn btn-info" type="button" value="Add User" ng-click="AddNewUser()" /> 
     <br /> 
     <table st-table="Users" st-safe-src="RawCollection" class="table table-striped" style="width:200px"> 
      <thead> 
       <tr> 
        <th st-sort="user"> 
         User 
        </th> 
       </tr> 
       <tr style="height:30px"> 
         <th><input style="height:25px" st-search="" class="form-control" placeholder="Search Name ...... " type="text" /></th> 
        </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="user in Users track by $index">     
        <td>{{user}}</td> 
       </tr> 
      </tbody> 
     </table> 
    </div> 
</div> 

코드 시도 23,516,

<script type="text/javascript"> 

     var app = angular.module("myApp", ['smart-table']); 
     app.controller("myController", VM); 

     function VM($scope, $q, $http) { 

      $scope.Roles = {}; 
      $scope.SelectedRole = ""; 
      $scope.Users = []; 
      $scope.NewUser = ""; 
      $scope.RawCollection = []; 

      var defer_Roles = $q.defer(); 
      var promise_Roles = defer_Roles.promise; 
      promise_Roles.then(receivedRoles, '', ''); 

      var defer_Users = $q.defer(); 
      var promise_Users = defer_Users.promise; 
      promise_Users.then('', '', receivedUsers); 

      function getAllRoles() { 

       $http.get("http://localhost/SBUXTerminalMonitorWebAPI/api/UserData?roleName=").success(function myfunction(roles) { 

        defer_Roles.resolve(roles); 
       }); 
      } 
      function receivedRoles(roles) { 
       $scope.Roles = roles; 
       $scope.SelectedRole = roles[0]; 
       getUsersForRole(roles[0]); 
      } 

      getAllRoles(); 

      $scope.HandleRoleChange = function (selectedRole) { 
       getUsersForRole(selectedRole); 
      } 

      function getUsersForRole(roleName) { 
       $http.get("http://localhost/SBUXTerminalMonitorWebAPI/api/UserData?roleName=" + roleName).success(function myfunction(users) { 
        defer_Users.notify(users); 
       }); 
      } 
      function receivedUsers(users) { 
       $scope.Users = users; 
       $scope.RawCollection = $scope.Users; 
      } 

      $scope.AddNewUser = function() { 
       $http.post("http://localhost/SBUXTerminalMonitorWebAPI/api/UserData?newUser=" + $scope.NewUser, $scope.SelectedRole).success(function myfunction() { 
        getUsersForRole($scope.SelectedRole); 
        $scope.NewUser = ""; 
       }); 
      } 
     } 

    </script> 
+0

당신이 게시 할 수 오브젝트 귀하의 데이터 구조? 어쨌든 다음을 사용해야합니다 :' 사용자' – developer033

+0

아마도 문서의 예제에 따라 사용자 정의 분류기를 사용해야 할 것입니다. 그냥'value'를 반환 – charlietfl

+0

@ developer033 WebAPI는 IEnumerable 을 반환합니다. $ scope의 스크린 샷을 게시하길 원하십니까? 사용자는 디버그 시간을 보십니까? – Ananth

답변

2

같은 시도 : 객체의 배열에 배열을 매핑 할 수 있습니다

$scope.getters={ 
    colsort: function (value) {    
     return value; 
    } 
} 

보기

<th st-sort="getters.colsort"> 

최악의 경우를 다음 각에서 생성 된 속성 이름을 사용

+0

위대한 작품! 왜 그것이 처음으로 작동하지 않았는 지 말해 줄 수 있습니까? – Ananth

+2

'user'를 사용하면 객체에서 속성을 찾을 것을 제안합니다. 문자열 배열이 있으므로 속성이 없습니다. 따라서 함수를 사용하는 대신 문자열을 반환합니다. – charlietfl

관련 문제