2017-02-10 96 views
0

我正在處理angularjs應用程序。我正在根據用戶輸入的值顯示角度UI網格。我想顯示一條消息,說沒有記錄找到當沒有值顯示在角度的UI網格。 請查看演示herejavascript顯示消息時無數據顯示

當用戶在From文本字段中輸入Atlanta和Chicago在To文本字段並單擊SearchLocations時,它將顯示UI網格。當用戶鍵入某些東西而不是顯示空白時,我想顯示NO記錄喜好消息。 另一個問題是我想添加一個單選按鈕的列,以便用戶可以選擇該單選按鈕時,他們要選擇行。我無法成功地在網格的每一行顯示單選按鈕,並添加一個新列。 任何建議都會非常有幫助。作爲新手面臨着許多問題需要解決。謝謝。

JS代碼:

angular.module('myApp', ['ngAnimate', 'ui.bootstrap','ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit','ui.grid.cellNav']); 
     angular.module('myApp').controller('citiesCtrl',function($scope){ 
      // $scope. places = undefined; 
      $scope.items = ["Atlanta", "Chicago", "NewYork"]; 
      $scope.selectAction = function() { 
       console.log($scope.places1); 

      }; 
     }); 

    /*Controller for searchLocations button*/ 
     angular.module('myApp').controller('searchController', ['$scope', function($scope) { 
      $scope.places = ['', '']; 
      $scope.searchValue = ''; 

      $scope.submit = function() { 
       if ($scope.places[0].length > 0 && $scope.places[1].length > 0) { 
        $scope.searchValue = $scope.places[0] + $scope.places[1]; 
       } 
      }; 

      $scope.users = [ 
       {'name' : 'AtlantaChicago', 
        'show' : true, 
        'details' : [ 
         {"Travel Date": "10/10/2014", commute:"Bus"}, 
         {"Travel Date": "10/11/2014", commute:"flight"}] 
       }, 
       {'name' : 'NewYorkChicago', 
        'show' : true, 
        'details': [ 
         {"Travel Date": "3/15/2016", commute:"flight"}, 
         {"Travel Date": "10/12/2016", commute:"flight"}, 
        ] 
       } 
      ]; 
      $scope.gridOptions = { 
       enableFiltering: true, 
       columnDefs: [ 
        { name: 'Travel Date', width: '5%'}, 
        { name: 'Departurecommute', enableFiltering: false, width: '12%' } 
       ], 
       rowHeight: 20, 
       enableHorizontalScrollbar:2 

      }; 
     }]); 

HTML代碼:

<div class="row"> 
     <div class="form-group" ng-controller="citiesCtrl"> 
      <label>From</label> 
      <input type="text" ng-model="places[0]" placeholder="Type Departure City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
     <div class="form-group" ng-controller="citiesCtrl"> 
      <label>To</label> 
      <input type="text" ng-model="places[1]" placeholder="Type Destination City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
    </div> 

    <input type="button" value="SearchLocations" ng-click="submit()"> 

    <div ng-repeat="user in users | filter: {name: searchValue} : true "> 
     <h3>First Grid</h3> 
     <div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div> 
    </div> 

我嘗試添加一個單選按鈕,每一行,但未能得到它顯示出來。 我試着將下面的代碼添加到新添加的列中,以便它在每行中顯示單選按鈕,以便用戶可以選擇任何一行。

{ 
      name: 'ReleaseAction', width: '350', 
      cellTemplate: '<div class="btn-group" ng-init="releaseAction=0"><input ng-model="releaseAction" type="radio" value="0" style="width:20px">&nbsp;Add</div>' 
     }, 

當沒有網格顯示並在UI網格中的每一行顯示單選按鈕時,顯示消息的任何siggestions會很有幫助。

回答

1

您可以將您的ng-repeat數據集打包成新的variable,您可以在其中檢查「數據」的可用性。

<div ng-repeat="user in filteredUsers = (users | filter: {name: searchValue} : true)"> 
    <h3>First Grid</h3> 
    <div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div> 
</div> 

然後在你的看法時,有沒有結果,你可以添加一個消息:

<div ng-if="!filteredUsers.length"> 
    No data available 
</div> 

更新你的代碼中看到Plnkr

+0

可以請你在我的演示編輯HTTP:// plnkr .co/edit/CZPRn60ufiXcCbc54iye?p =預覽。正如我試過那個你建議它沒有出現的那個。感謝你的幫助。 – user3684675

+0

看到我更新的答案:) –

+0

感謝它的工作。我在我的帖子中詢問的另一個場景是在用戶界面網格的每一行顯示單選按鈕,我試着按照上面的帖子顯示,但它沒有出現。我接受了答案,但是您能否幫我出來在網格的每一行顯示單選按鈕,以便用戶可以選擇任意一行。 – user3684675