1. 程式人生 > 其它 >angular ui-grid selectRow 設定選中

angular ui-grid selectRow 設定選中

設定選中:$scope.gridApi.selection.selectRow(rowEntity);

取消選中:$scope.gridApi.selection.unSelectRow(rowEntity);

獲取選中行:$scope.gridApi.selection.getSelectedRows();

選中所有行:$scope.gridApi.selection.selectAllRows();

取消選中的所有行:$scope.gridApi.selection.clearSelectedRows();

標頭檔案裡需要加上$timeout

(function () {
angular.module('app').controller('app.hrm.views.salary.salaryDifferentMonthPaymentStatement.selectApplyEmployees', [
'$scope', '$uibModalInstance', '$timeout', 'abp.services.app.salary',
function ($scope, $uibModalInstance,$timeout, salaryService) {

}

載入的方法:

function init(url) {
salaryService.getAll({ id: id}).then(function (result) {
vm.gridOptions.totalItems = result.data.totalCount;
vm.gridOptions.data = result.data.items;

angular.forEach(vm.gridOptions.data, function (v, k) {
if (v.isChecked) {
$timeout(function () {
$scope.gridApi.selection.selectRow(v);
}, 1000);
}
else {
$timeout(function () {
$scope.gridApi.selection.unSelectRow(v);
}, 1000);
}
});

}).finally(function () {
vm.loading = false;
});

}