2014-03-12 70 views
0

嗨,大家好我有一對夫婦約NG-電網的問題, 這是我網格選項NG-電網完成操作

$scope.gridOptions= { 
    data:'data', 
    selectedItems:sel, 
    multiSelect:false, 
    columnDefs: [{ field: 'field1', displayName: 'field1',cellTemplate: template, cellClass:'cellToolTip'}, 
     {field:'field2', cellTemplate: template, visible:false}, 
     { field:'field3', displayName:'field3', cellTemplate: template, cellClass:'cellToolTip' }, 
     { field: 'field4', displayName: 'field4',cellTemplate: templatetest} , 
     { field: 'dataInserimento', displayName: 'Data richiesta',cellTemplate: template, cellClass:'cellToolTip'} , 
     { displayName: 'field5', cellTemplate:'<div ><button ng-diasbled="pdfenabled" ng-click="reportpdf()"><i class="glyphicon glyphicon-file"></i></button></div>', cellClass:'gridCell' }] 
    } 
} 

和兩個可能的電池模板是這些

var template = '<div class="ngCellText" ng-class="col.colIndex()"><a id="gridField" ng-cell-text>{{row.getProperty(col.field)}}</a></div>'; 
var templatetest = '<div ng-disabled="enabled" class="ngCellText" ng-class="col.colIndex()"><a id="gridField" ng-cell-text>{{row.getProperty(col.field)}}</a></div>' 

數據數組類似於一個

[{field1:'something', 
    field2:'something', 
    field3:'something', 
    field4:[{otherstuff:'something',morestuff:'something'}], 
    field5:'something'} 
    {field1:'something', 
    field2:'something', 
    field3:'something', 
    field4:[{otherstuff:'something',morestuff:'something'}], 
    field5:'something'} 
    {field1:'something', 
    field2:'something', 
    field3:'something', 
    field4:[{otherstuff:'something',morestuff:'something'}], 
    field5:'something'} 
    }] 

東西,所以第一個問題是:如何我可以顯示field4字段中的元素不像數組嗎?是否有可能只獲得一個或兩個值?
第二個問題,有可能使用另一個單元格綁定的單元格字段屬性? 例如

if(field3==false){ 
    $scope.enabled=true; 
} 
+0

你想顯示'field4'中的元素嗎? –

回答

0

寫你的模板是這樣的:

var templatetest = '<div ng-disabled="enabled" class="ngCellText" ng-class="col.colIndex()" ng-bind="row.getProperty(col.field)[0].otherstuff"></div>'; 

看這個Plunker

甚至更​​好,你可以使用過濾器:

app.filter('somefilter', function() { 
    return function(x) { 
    return x[0].otherstuff + '/' + x[0].morestuff; 
    }; 
}); 
結合

與此模板:

var templatetest = '<div ng-disabled="enabled" class="ngCellText" ng-class="col.colIndex()" ng-bind="row.getProperty(col.field)|somefilter"></div>'; 

看這個Plunker

或(這包括回答你的第二個問題)使用row.entity查找完整rowdata:

var templatetest = '<div ng-disabled="enabled" class="ngCellText" ng-class="col.colIndex()"> <a href="#">{{row.entity.field4[0].otherstuff+"/"+row.entity.field3}}</a></div>'; 

下面是最終Plunker

希望你能繼續與此。