11

Qui ho creato campione per il completamento automatico, che sta lavorando bene e ho bisogno di fare qualche modifica sul this.currently funziona cosìCome eseguire il dropdown del completamento automatico come una griglia in angularJS?

enter image description here

ma quello che ho bisogno è esattamente ho bisogno di mostrare la discesa come vista a griglia. alcuni come questo enter image description here

può

qualsiasi aiuto su questo? .. grazie

var app = angular.module('app', ['ui.bootstrap']); 
 

 
    app.controller('TypeaheadCtrl', function ($scope, $http, limitToFilter, filterFilter) { 
 

 
    
 
    $scope.sample_data = [{ 
 
     "name": "Nelson", 
 
     "designation":"Senior Developer", 
 
     "company": "acme", 
 
     "companydisplay": "abc" 
 
     }, 
 
     { 
 
     "name": "suresh", 
 
     "designation":"Developer", 
 
     "company": "acme", 
 
     "companydisplay": "def" 
 
     }, 
 
     { 
 
     "name": "Naresh", 
 
     "designation":"Developer", 
 
     "company": "acme", 
 
     "companydisplay": "xyz" 
 
     }]; 
 

 
    $scope.filtered_sample_data = function (search) { 
 
     var filtered = filterFilter($scope.sample_data, search); 
 
     
 
     var results = _(filtered) 
 
     .groupBy('company') 
 
     .map(function (g) { 
 
      g[0].initial = true; // the first item in each group 
 
      return g; 
 
     }) 
 
     .flatten() 
 
     .value(); 
 
     return results; 
 
    }; 
 
    });
body { 
 
    font-family:'Trebuchet MS', Verdana, sans-serif; 
 
    margin:20px 0px; 
 
    padding:0px; 
 
    text-align:center; 
 
} 
 
.dropdown-menu > .active > a, .dropdown-menu > .active > a:hover, .dropdown-menu > .active > a:focus { 
 
    cursor:pointer; 
 
} 
 
label { 
 
    cursor:default; 
 
    margin:0; 
 
} 
 
.form { 
 
    width:400px; 
 
    margin:0px auto; 
 
    text-align:left; 
 
    background:#F2F1F0; 
 
    border-top-left-radius: 10px 5px; 
 
    border-top-right-radius: 10px 5px; 
 
    border:1px solid #474641; 
 
} 
 
.formHeader { 
 
    background:#474641; 
 
    color:#ddd; 
 
    padding:4px; 
 
    font-weight:600; 
 
    border-top-left-radius: 10px 5px; 
 
    border-top-right-radius: 10px 5px; 
 
} 
 
.formBody { 
 
    padding:10px; 
 
} 
 
.data { 
 
    margin:0px auto; 
 
    text-align:left; 
 
} 
 
.dropdown-menu { 
 
    text-align:left; 
 
} 
 
table { 
 
    border-collapse: collapse; 
 
    width: 100%; 
 
} 
 
th{ 
 
    background-color: #29ABE2; 
 
    color: white; 
 
} 
 
tr> td { 
 
    text-align: left; 
 
} 
 
th, td { 
 
    padding: 15px; 
 

 
} 
 
tbody>tr:hover { 
 
    background-color: #0088cc; 
 
    color: white; 
 
} 
 

 
.headerSortUp { 
 
    background: url(http://tablesorter.com/themes/blue/bg.gif) no-repeat 99%; 
 
} 
 
.headerSortDown { 
 
    background: url(data:image/gif; 
 
    base64, R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjI8Bya2wnINUMopZAQA7) no-repeat 99%; 
 
} 
 
    
 
.suggestion-name { min-width: 100px; } 
 
.suggestion-designation { min-width: 100px; } 
 
.suggestion-company { min-width: 100px; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script> 
 
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/> 
 
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet"/> 
 
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-dropdown.js"></script> 
 
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script> 
 

 
    
 

 
<div ng-app="app"> 
 
    <div class='container-fluid' ng-controller="TypeaheadCtrl"> 
 
     <!-- <pre>Model: {{result | json}}</pre> 
 
     <input type="text" ng-model="result" typeahead="suggestion for suggestion in cities($viewValue)"> 
 
--> <pre>Model: {{monkey | json}}</pre> 
 

 
     <input type="text" ng-model="monkey" typeahead-template-url="columnTwo.html" typeahead="suggestion.name for suggestion in filtered_sample_data($viewValue) | filter: $viewValue"> 
 

 
    </div> 
 
    <!-- CACHE FILE: columnTwo.html --> 
 
    <script type="text/ng-template" id="columnTwo.html"> 
 
     <table class=""> 
 
      <thead ng-if="match.model.initial"> 
 
      <tr> 
 
       <th>Name</th> 
 
       <th>Designation</th> 
 
       <th>Company</th> 
 
      </tr> 
 
      </thead> 
 
     <tr> 
 
     <td class="suggestion-name"> 
 
     <div ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)"> 
 
      <a>{{ match.model.name }} </a> 
 
     </div> 
 
     </td> 
 
     <td class="suggestion-designation"> {{ match.model.designation }} </td> 
 
     <td class="suggestion-company"> {{ match.model.companydisplay }} </td> 
 
     </tr> 
 
     </table> 
 
    </script>

+0

Stai manca un chiusura virgolette doppie nella tua columnTwo.html ng-modello. Dovrebbe essere '

'. Questo fa apparire la griglia. –

+0

anche se messo così non funziona correttamente –

+0

Sì, dal momento che l'intero modello typeahead è fondamentalmente ng-ripetuto su ogni suggestion.name nei tuoi dati, non penso che tu possa includere la testa della tabella nel modello senza che si ripeta per ogni nome Ovviamente puoi rilasciare '{{match.model.designation}}' nel proprio '

' elemento dati e ottenere un effetto simile, ma senza le intestazioni delle colonne. –

risposta

9

Come ho commentato, dal momento che il modello viene ripetuta per ogni suggestion.name nel set di dati di esempio , includerà intestazioni di colonna sopra ciascuno dei nomi elencati.

AGGIORNAMENTO: Una soluzione giuria-brogli, come si trova nel this previous SO answer, è quello di iniettare di angolare filterFilter e, piuttosto che utilizzare $scope.sample_data come la vostra collezione di ripetere attraverso, invece di creare un gruppo di pre-filtrati in base al $ viewValue. Per raggruppare tutte le persone nel set di dati, ho aggiunto una proprietà aziendale a ciascuna (facendo qui una supposizione). È quindi possibile impostare una proprietà dell'indicatore (in questo caso initial = true) sul primo elemento nel set di dati filtrato.

E, infine, nel modello, oltre a cambiare il vostro valore di attributo typeahead-suggestion.name for suggestion in filtered_sample_data($viewValue) | filter: $viewValue">, potrai impostare un ng-if sulla testa tavolo per mostrare solo se `match.model.initial' è vero.

Questo funzionerà fintanto che ogni persona nel set di dati ha alcune proprietà generiche con lo stesso valore di tutte le altre persone nel set, e si raggruppa per tale proprietà.

[Si noti che il filtro utilizza concatenamento implicita di lodash, così ho aggiunto un tag script per lodash.js pure.]

@runTarm di credito per la soluzione.

var app = angular.module('app', ['ui.bootstrap']); 
 

 
    app.controller('TypeaheadCtrl', function ($scope, $http, limitToFilter, filterFilter) { 
 

 
    
 
    $scope.sample_data = [{ 
 
     "name": "Nelson", 
 
     "designation":"GM", 
 
     "company": "acme" 
 
     }, 
 
     { 
 
     "name": "suresh", 
 
     "designation":"Developer", 
 
     "company": "acme" 
 
     }, 
 
     { 
 
     "name": "Naresh", 
 
     "designation":"Developer", 
 
     "company": "acme" 
 
     }]; 
 

 
    $scope.filtered_sample_data = function (search) { 
 
     var filtered = filterFilter($scope.sample_data, search); 
 

 
     var results = _(filtered) 
 
     .groupBy('company') 
 
     .map(function (g) { 
 
      g[0].initial = true; // the first item in each group 
 
      return g; 
 
     }) 
 
     .flatten() 
 
     .value(); 
 
    
 
     return results; 
 

 
    }; 
 
    });
body { 
 
    font-family:'Trebuchet MS', Verdana, sans-serif; 
 
    margin:20px 0px; 
 
    padding:0px; 
 
    text-align:center; 
 
} 
 
.dropdown-menu > .active > a, .dropdown-menu > .active > a:hover, .dropdown-menu > .active > a:focus { 
 
    cursor:pointer; 
 
} 
 
label { 
 
    cursor:default; 
 
    margin:0; 
 
} 
 
.form { 
 
    width:400px; 
 
    margin:0px auto; 
 
    text-align:left; 
 
    background:#F2F1F0; 
 
    border-top-left-radius: 10px 5px; 
 
    border-top-right-radius: 10px 5px; 
 
    border:1px solid #474641; 
 
} 
 
.formHeader { 
 
    background:#474641; 
 
    color:#ddd; 
 
    padding:4px; 
 
    font-weight:600; 
 
    border-top-left-radius: 10px 5px; 
 
    border-top-right-radius: 10px 5px; 
 
} 
 
.formBody { 
 
    padding:10px; 
 
} 
 
.data { 
 
    margin:0px auto; 
 
    text-align:left; 
 
} 
 
.dropdown-menu { 
 
    text-align:left; 
 
} 
 
table, td, th {  
 
    border: 1px solid #ddd; 
 
    text-align: left; 
 
} 
 

 
table { 
 
    border-collapse: collapse; 
 
    width: 100%; 
 
} 
 

 
th, td { 
 
    padding: 15px; 
 
} 
 
.suggestion-name { min-width: 100px; } 
 
.suggestion-designation { min-width: 100px; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script> 
 
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/> 
 
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet"/> 
 
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-dropdown.js"></script> 
 
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script> 
 

 
    
 

 
<div ng-app="app"> 
 
    <div class='container-fluid' ng-controller="TypeaheadCtrl"> 
 
     <!-- <pre>Model: {{result | json}}</pre> 
 
     <input type="text" ng-model="result" typeahead="suggestion for suggestion in cities($viewValue)"> 
 
--> <pre>Model: {{monkey | json}}</pre> 
 

 
     <input type="text" ng-model="monkey" typeahead-template-url="columnTwo.html" typeahead="suggestion.name for suggestion in filtered_sample_data($viewValue) | filter: $viewValue"> 
 

 
    </div> 
 
    <!-- CACHE FILE: columnTwo.html --> 
 
    <script type="text/ng-template" id="columnTwo.html"> 
 
     <table class=""> 
 
      <thead ng-if="match.model.initial"> 
 
      <tr> 
 
       <th>Name</th> 
 
       <th>Designation</th> 
 
      </tr> 
 
      </thead> 
 
     <tr> 
 
     <td class="suggestion-name"> 
 
     <div ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)"> 
 
      <a>{{ match.model.name }} </a> 
 
     </div> 
 
     </td> 
 
     <td class="suggestion-designation"> {{ match.model.designation }} </td> 
 
     </tr> 
 
     </table> 
 
    </script> 
 

+0

questo va bene, ma quello di cui ho esattamente bisogno è già menzionato nella 2a immagine –

+0

con header ho bisogno di –

+0

@SureshB, sta funzionando ora. –

1

agGrid.initialiseAgGridWithAngular1(angular); 
 
function showGrid(val) 
 
\t \t { 
 
\t \t \t console.log(val.length) 
 
\t \t \t if(val.length <3){ 
 
    \t \t \t \t document.getElementById('myGrid').style.display='none' 
 
\t \t \t } 
 
\t \t \t else 
 
\t \t \t { 
 
\t \t \t \t \t \t console.log("hide count") 
 
\t \t \t \t document.getElementById('myGrid').style.display='block' 
 
\t \t \t } 
 
\t \t } 
 
var fileBrowserModule = angular.module('basic', ['agGrid']); 
 

 
fileBrowserModule.controller('basicController', function($scope) { 
 
\t 
 
\t $scope.gridheader = [ 
 
\t \t \t \t \t {headerName: "Make", field: "make"}, 
 
\t \t \t \t \t {headerName: "Model", field: "model"}, 
 
\t \t \t \t \t {headerName: "XModel", field: "model"}, 
 
\t \t \t \t \t {headerName: "Rate", field: "price"}, 
 
\t \t \t \t \t {headerName: "Price", field: "price"} 
 
\t \t \t \t ]; 
 
    $scope.rowData = [ 
 
\t \t \t \t \t {make: "Toyota", model: "Celica", price: 35000}, 
 
\t \t \t \t \t {make: "Ford", model: "Mondeo", price: 32000}, 
 
\t \t \t \t \t {make: "Porsche", model: "Boxter", price: 72000}, 
 
\t \t \t \t \t {make: "Audi", model: "Boxter", price: 92000}, 
 
\t \t \t \t \t {make: "Toyota", model: "Celica", price: 35000}, 
 
\t \t \t \t \t {make: "Ford", model: "Mondeo", price: 32000}, 
 
\t \t \t \t \t {make: "Porsche", model: "Boxter", price: 72000}, 
 
\t \t \t \t \t {make: "Audi", model: "Boxter", price: 92000} 
 
\t \t \t \t ]; 
 
\t 
 
\t 
 
    
 

 
    $scope.gridOptions = { 
 
     columnDefs: $scope.gridheader, 
 
     rowData: $scope.rowData, 
 
\t \t onSelectionChanged: onSelectionChanged, 
 
     rowSelection: 'single', 
 
     enableColResize: true, 
 
     enableSorting: true, 
 
     enableFilter: true, 
 
     groupHeaders: true, 
 
     rowHeight: 22, 
 
     onModelUpdated: onModelUpdated, 
 
     suppressRowClickSelection: false 
 
\t \t 
 

 
    }; 
 

 
    function onModelUpdated() { 
 
     var model = $scope.gridOptions.api.getModel(); 
 
     var totalRows = $scope.gridOptions.rowData.length; 
 
     var processedRows = model.getVirtualRowCount(); 
 
\t \t  $scope.rowCount = processedRows.toLocaleString() + '/' + totalRows.toLocaleString(); 
 
    } 
 
\t 
 
\t function onSelectionChanged() { 
 
    \t var selectedRows = $scope.gridOptions.api.getSelectedRows(); 
 
    var selectedRowsString = ''; 
 
    selectedRows.forEach(function(selectedRow, index) { 
 
     if (index!=0) { 
 
      selectedRowsString += ', '; 
 
     } 
 
     selectedRowsString += selectedRow.make; 
 
    }); 
 
\t $scope.gridOptions.quickFilterText = selectedRowsString; 
 
    document.querySelector('#selectedRows').innerHTML = selectedRowsString; 
 
\t document.getElementById('myGrid').style.display='none' 
 
} 
 

 
document.addEventListener('DOMContentLoaded', function() { 
 
    var gridDiv = document.querySelector('#myGrid'); 
 
    
 
}); 
 

 
    
 

 
});
<script src="https://www.ag-grid.com/dist/ag-grid.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> 
 

 
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css" rel="stylesheet"/> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 
<head lang="en"> 
 
    <meta charset="UTF-8"> 
 
    
 
</head> 
 

 
<body ng-app="basic"> 
 

 
    <div ng-controller="basicController" style="width: 800px;"> 
 
     <div style="padding: 4px"> 
 
      <div style="float: left;"> 
 
       <p>type audi or toyota</p><input type="text" ng-model="gridOptions.quickFilterText" onKeyPress="return showGrid(this.value)" placeholder="Type text to filter..."/> 
 
      </div> 
 
      <div style="padding: 4px;"> 
 
        <span id="selectedRows"> 
 
    </span> 
 
({{rowCount}}) 
 
      </div> 
 
      <div style="clear: both;"/> 
 
     </div> 
 
     <!--<grid-Wrapper get-header="gridheader" get-data="rowData" enable-Filter="{{true}}" enable-Sorting="{{true}}" enable-Col-Resize="{{true}}"></grid-Wrapper>--> 
 
     
 
     <div id="myGrid" style="width: 100%; height: 400px; display:none" 
 
      ag-grid="gridOptions" 
 
      class="ag-fresh ag-basic" > 
 
     </div> 
 
    </div> 
 

 
</body> 
 
</html>

Problemi correlati