2016-07-03 9 views
2

ただ1つの列を持つテーブルを作成しています。値は文字列配列から取り込まれます。しかし、私は並べ替えを動作させることはできません。スマートテーブルの並べ替えが機能しない

私はここで間違っていますか?試してみました

ステップ:

1)ST-安全-src属性を検証しました。検索は正常に動作しています。だから私はst-safe-src属性が正しく設定されていると仮定します。

2)<th st-sort="user">

4を試みた)<th st-sort-default="true">

3を試みた)は、コントローラ

01デザイナ

<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> 

コードため

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

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

コードを変更しようとしました

<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

で作成されたプロパティ名を使用することができます投稿できますあなたのデータ構造?とにかくあなたは次のものを使うべきです: ' User' – developer033

+0

おそらくdocsの例に従ってカスタムソーターを使わなければなりません。単に値を返す – charlietfl

+0

@ developer033 WebAPIはIEnumerable を返します。どのように$スコープのスクリーンショットを投稿したいですか?ユーザーはデバッグ時間を見ますか? – Ananth

答えて

2

は次のようなものを試してみてください:

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

ビュー

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

最悪の場合には、オブジェクトの配列にあなたの配列をマッピングして、各オブジェクト

+0

素晴らしい作品!なぜそれが最初に動作しなかったのか教えていただけますか? – Ananth

+2

'user'を使ってオブジェクト内のプロパティを探すことを提案しています。文字列配列があるので、プロパティはありません。関数を使う代わりに、文字列を返すだけです – charlietfl

関連する問題