如何在页面加载时 Select UI Grid 中的一行?
How to Select a row in UIGrid on page loading?
我想在页面加载时在 UI 网格中 select 一行。我试过这段代码,但出现错误;
TypeError: newRawData.forEach 不是函数
$scope.deviceGrid = {
data:'deviceDetails',
enableRowSelection: true,
enableRowHeaderSelection: false,
enableSelectAll: false,
multiSelect: false,
noUnselect: true,
minRowsToShow :10,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.grid.modifyRows($scope.deviceGrid.data);
$scope.gridApi.selection.selectRow($scope.deviceGrid.data[0]);
gridApi.selection.on.rowSelectionChanged($scope, function (row) {
var msg = 'row selected ' + row.isSelected;
console.log(row.entity.devHardwareId);
$scope.devHardwareId= row.entity.devHardwareId;
});
}};
他们是另一种方法吗?
你有两个选择:
1) 设置数据到网格后使用$timeout
$timeout(function() {
if($scope.gridApi.selection.selectRow){
$scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
}
});
2) 在从 gridApi 呈现的行上使用
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.core.on.rowsRendered($scope, function () {
gridApi.selection.selectRow($scope.gridOptions.data[0]);
});
我想在页面加载时在 UI 网格中 select 一行。我试过这段代码,但出现错误;
TypeError: newRawData.forEach 不是函数
$scope.deviceGrid = {
data:'deviceDetails',
enableRowSelection: true,
enableRowHeaderSelection: false,
enableSelectAll: false,
multiSelect: false,
noUnselect: true,
minRowsToShow :10,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.grid.modifyRows($scope.deviceGrid.data);
$scope.gridApi.selection.selectRow($scope.deviceGrid.data[0]);
gridApi.selection.on.rowSelectionChanged($scope, function (row) {
var msg = 'row selected ' + row.isSelected;
console.log(row.entity.devHardwareId);
$scope.devHardwareId= row.entity.devHardwareId;
});
}};
他们是另一种方法吗?
你有两个选择:
1) 设置数据到网格后使用$timeout
$timeout(function() {
if($scope.gridApi.selection.selectRow){
$scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
}
});
2) 在从 gridApi 呈现的行上使用
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.core.on.rowsRendered($scope, function () {
gridApi.selection.selectRow($scope.gridOptions.data[0]);
});