您可以隨時更改標題文本。聽起來像你可以把手錶的計數值,並做類似如下:
$scope.$watch('yourCountValue', function(newVal){
$scope.gridOptions.columnDefs[0].displayName = 'Users(' + newVal + ')';
$scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
})
代碼可能會有所不同,在你的情況。例如,您可以觀看$ scope.data更改,並使用$ scope.data.length來連接displayName。您可能有選擇標題和索引將是1而不是0,等等。
更新回答:你忘記注入ui.grid和uiGridConstants?
var app = angular.module('myApp', ['ui.grid']);
app.controller('appCtrl', ['$scope', 'uiGridConstants', function($scope, uiGridConstants) {
$scope.gridOptions = {
columnDefs: [
{field: 'field1', displayName: 'User 1'},
{field: 'field2', displayName: 'User 2'},
],
data: [
{ field1: "user 1", field2: "bar"},
{ field1: "user 2", field2: "bar"},
{ field1: "user 3", field2: "bar"}
],
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
}
};
//put the watch here
/...
}]);
你能舉一個更詳細的例子嗎? –
我有用戶,名字,Latname,地址具有標題名稱欄的ui網格。在用戶標題列中,我需要用戶(用戶數)和用戶的標題名稱中的用戶數。我有這個動態的計數值。我怎樣才能顯示標題名稱用戶 –
我添加了一個圖像,它會幫助你更好地理解。 –