How can I get values of chekcboxes if I use cellrenderer function with ag grid?

841 views Asked by At

Due to can not use angular ng-model for checkboxes in cellrenderer function, I can not get their values. So I changed my code

return `<input  type='checkbox' ${params.value.disable ? 'disabled' : ''} ${params.value.state ? 'checked' : ''} />`;

But I want to get values of them when I press the GET button. How can I get their values?

Note: I used someone plunker with my changes to save time: https://plnkr.co/edit/YjVlFYaOJJxS0mOIR6nu?p=preview

1

There are 1 answers

2
ElasticCode On

Your render function have an issue there is no value for params.value.disable and params.value.state if you need to assign the data value to the checked attribute change it to params.value as below

return `<input  type='checkbox' ${params.value.disable ? 'disabled' : ''} ${params.value ? 'checked' : ''} />`;

You can get a list of selected rows using $scope.gridOptions.api.getSelectedRows().

And if you can iterate through all the rowNodes in the grid and and get its values use $scope.gridOptions.api.forEachNode(function(rowNode, index) { });

$scope.getValues= function(){

    var selectedRows = $scope.gridOptions.api.getSelectedRows();
    selectedRows.forEach(function(selectedRow, index) {

        alert(JSON.stringify(selectedRow));
    });


    $scope.gridOptions.api.forEachNode( function(rowNode, index) {
      alert(JSON.stringify(rowNode.data));
    });

}

For more details check Grid API