2015-10-07 34 views
0

我需要在我的UI網格中僅顯示一個Date Collection對象作爲數據源。如何將日期集合設置爲AngularJs UI網格中的數據源?

在這種情況下,我需要在ColumnDefs下定義field嗎?此外,我需要包括一列到delete那個特定的行,在這種情況下Delete the current Date object

我該如何做到這一點?下面是我的代碼

editor.mySeasonBreaks = {    
     data: "editor.mySeasons", 
     columnDefs: 

     [{ field: "????", visible: true, displayName: "Season Break" }, 
     { 
      name: 'delete', 
      displayName: "", 
      cellTemplate: "<button ng-click="editor.delete(row.entity)" />" 
     }] 
    }; 

在上面的代碼,editor.mySeasons只是一個日期陣列對象。

在此先感謝

回答

1

您可以創建一個對象數組與日期和定義根據需要列。這樣你可以獲得更多的控制權並且易於調整/擴展。

現在爲您的行刪除我創建a Plunkr這就是展示一個可能的解決方案。

正如你建議,你需要添加一個cellTemplate引用您的刪除功能

cellTemplate: "<button ng-click=\"grid.appScope.delete(row)\">DELETE ROW</button>" 

要訪問該功能,你需要把它添加到您的gridDefinition和療法屬性被稱爲appScopeProvider

可能設置將是

appScopeProvider: { 
    delete : function(row) { 
    editor.mySeasons.forEach(function(entry, index){ 
     if(entry.myDate === row.entity.myDate) { 
     editor.mySeasons.splice(index, 1); 
     } 
    }); 
    }, 
} 
1

這是不推薦的方案,但你可以使用這樣的事情:

$scope.myData=['2015-22-07', '2017-10-08', '2020-17-02']; 
$scope.gridOptions = { 
    data: 'myData', 
    columnDefs: [ 
    { 
     displayName: 'Date Array', 
     cellTemplate: '<div class="ngCellText ng-class="col.colIndex()">{{row.entity}}</div>' 
    } 
    ] 
}; 

您可以測試它here

存在排序問題,可能還有其他問題。

這是更好海事組織日期的數組轉換爲對象的數組:

var res = []; 
myData.forEach(function(el){ 
    res.push({date: el}); 
}); 

然後指定列像往常一樣:

{ field: 'date', visible: true, displayName: 'Season Break' } 
相關問題