Shital
Shital

Reputation: 77

Ui grid check if any row selected?

I have a ui-grid and a button, When i click on button it should first check if at-least one row is selected and show alert on if not. I tried

gridApi.selection.getSelectedRows() 

but its returning nothing, and I am not able to put any if-else check. (i don't want to use noUnselect) Can anybody help..?

Upvotes: 1

Views: 1839

Answers (2)

console.log(gridApi.selection.getSelectedRows().length);

it gives no.of rows selected..

if(gridApi.selection.getSelectedRows().length ==0)

no row is selected...

Upvotes: 0

rob2universe
rob2universe

Reputation: 7583

Try to place your code inside onRegisterApi:

$scope.gridOptions = {
              [...]
                onRegisterApi : function (gridApi) {
                    $scope.gridApi = gridApi;
                    $log.debug(gridApi.selection.getSelectedRows() );
                    $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
                 $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
                    $log.debug(gridApi.selection.getSelectedRows() );
                }
            };

Upvotes: 1

Related Questions