ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

SelectAll ChildRow with in group

Open susharma-equinix opened this issue 11 years ago • 15 comments

Hi All,

Is there an option to select all child rows with in the grouped column actual

Please check the highlighted area in the image, When ever user clicks there all the child rows under that should be selected.

Let me know if this can actually be an enhancement it would be a wonderful feature to the grid where user can group the columns and select child rows i.e. selectAll under each column and perform desired operations.

susharma-equinix avatar Jul 02 '15 05:07 susharma-equinix

Am doing something similar using this : $scope.gridOptions1.onRegisterApi = function (gridApi) { $scope.gridApi = gridApi; $scope.gridApi.selection.on.rowSelectionChanged($scope, function (row) {

        if(row.internalRow==true && row.isSelected==true){
            var childRows   = row.treeNode.children;
            for (var j = 0, length = childRows.length; j < length; j++) {
                var rowEntity   = childRows[j].row.entity;
                $scope.gridApi.selection.selectRow(rowEntity);
            }
        }

        if(row.internalRow==true && row.isSelected==false){
            var childRows   = row.treeNode.children;
            for (var j = 0, length = childRows.length; j < length; j++) {
                var rowEntity   = childRows[j].row.entity;
                $scope.gridApi.selection.unSelectRow(rowEntity);
            }
        }

    });
}

susharma-equinix avatar Jul 02 '15 07:07 susharma-equinix

I have also achieved this by using the below functions :

$scope.gridOptions1.onRegisterApi = function (gridApi) { $scope.gridApi = gridApi; $scope.gridApi.selection.on.rowSelectionChanged($scope, function (row) { if(row.internalRow==true && row.isSelected==true){ var childRows = row.treeNode.children; for (var j = 0, length = childRows.length; j < length; j++) { selectAllChildren($scope.gridApi,childRows[j]); } }

        if(row.internalRow==true && row.isSelected==false){
            var childRows   = row.treeNode.children;
            for (var j = 0, length = childRows.length; j < length; j++) {
                unSelectAllChildren($scope.gridApi,childRows[j]);
            }
        }

    });
}

function selectAllChildren(gridApi,rowEntity){
    if(rowEntity.children.length==0){
        gridApi.selection.selectRow(rowEntity.row.entity);
    }else{
        var childrens = rowEntity.children;
        for (var j = 0, length = childrens.length; j < length; j++) {
            selectAllChildren(gridApi,childrens[j]);
        }
    }
}

function unSelectAllChildren(gridApi,rowEntity){
    if(rowEntity.children.length==0){
        gridApi.selection.unSelectRow(rowEntity.row.entity);
    }else{
        var childrens = rowEntity.children;
        for (var j = 0, length = childrens.length; j < length; j++) {
            unSelectAllChildren(gridApi,childrens[j]);
        }
    }
}

susharma-equinix avatar Jul 10 '15 07:07 susharma-equinix

+1 on having this feature enabled. Was there a specific reason this feature was disabled?

"Group header rows cannot be edited, and if using the selection feature, cannot be selected. "

lst88 avatar Aug 04 '15 12:08 lst88

+1

patriciocordova avatar Mar 17 '16 02:03 patriciocordova

+1

doctorsender avatar Mar 22 '16 15:03 doctorsender

+1

monster910 avatar Jun 29 '16 14:06 monster910

+1

yadimon avatar Aug 02 '16 17:08 yadimon

+1

AjayanandLad avatar Sep 09 '16 09:09 AjayanandLad

+1

alexey-vasyunin avatar Nov 01 '16 08:11 alexey-vasyunin

+1

veica avatar Dec 10 '16 20:12 veica

How can I select gropu level and travers all children?

kamal-bhatt avatar Dec 16 '16 15:12 kamal-bhatt

+1 why not merged to master?

renfengmei avatar Jan 11 '17 04:01 renfengmei

+1

jawaharlalt avatar Mar 10 '17 06:03 jawaharlalt

Hey, guys, I tried listed above code and it won't working. Seems UI-grid API has changed. So I have achieved this with the next code: onRegisterApi: function (gridApi) { $scope.gridApi = gridApi;

            $scope.gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows) {
                rows.forEach(childRow => $scope.proceedParentSelection(childRow));
            });

            $scope.gridApi.selection.on.rowSelectionChanged($scope, function (row) {
                $scope.proceedParentSelection(row);
            });

            $scope.proceedParentSelection = function(childRow) {
                let parentRow = childRow.treeNode.parentRow;
                parentRow.isSelected = parentRow.treeNode.children.every(child => child.row.isSelected)
            }
        }

`

Kononchuk-B avatar Aug 17 '17 10:08 Kononchuk-B

I don't recommend to use gridApi.selection.unSelectRow or gridApi.selection.selectRow, because they will call toggleRowSelection(), which will also raise rowSelectionChanged(), so I prefered to use GridRow.prototype.setSelected(boolean) to select or un select row

WuYouyan avatar Jan 12 '21 11:01 WuYouyan