Get expand and checkbox with multiple column in ng-grid

213 Views Asked by At

I want to create a grid which shows expand/collapse and checkbox with multiple column.

For this I create a sample which expand at first level and show check box with next level.

My sample is - plunker

$scope.customExpand = function (row, gridId) {
            // find which grid (in case more than one on page)
            var selectedGrid;
            if (gridId === $scope.gridOptions.gridId) {
                selectedGrid = $scope.gridOptions.ngGrid;
            }



            // first collapse all others

           /* angular.forEach(selectedGrid.rowFactory.aggCache, function (aggRow, key) {
                if (aggRow.isAggRow && aggRow.collapsed === false) {
                    aggRow.toggleExpand();
                }
            });*/
            // then scroll to row for this group
            var rowNum = 0;
            angular.forEach(selectedGrid.rowFactory.aggCache, function (aggRow, key) {
                if (aggRow.label == row.label) {
                    rowNum = key;
                }
            });

            selectedGrid.$viewport.scrollTop(rowNum * selectedGrid.config.rowHeight);
            // then expand the row
            row.toggleExpand();
        }

  $scope.gridData = [];
  $scope.aggregateLots = function(row) {
    var lots = 0;
    angular.forEach(row.children, function(subrow) {
      lots += subrow.entity.lots;
    });
    return lots;
  }

  $scope.gridOptions = {
    aggregateTemplate: "<div ng-click=\"debugger;customExpand(row,gridId)\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">\r" +
      "\n" +

      "<div class='ngCell col3 col3t'><div class='ngCellText col3 col3t'>{{row.children[0].entity.cname}}</div></div>\r\n" +
      "<div class='ngCell col4 col4t'><div class='ngCellText col4 col4t'>{{row.children[0].entity.maturity | date:\'dd-MMM-yy\' }}</div></div>\r\n" +
      "<div class='ngCell col5 col5t'><div class='ngCellText col5 col5t'>{{row.children[0].entity.bs}}</div></div>\r\n" +
      "<div class='ngCell col6 col6t'><div class='ngCellText col6 col6t'>{{row.children[0].entity.price}}</div></div>\r\n" +
      "<div class='ngCell col7 col7t'><div class='ngCellText col7 col7t'>{{row.totalChildren()}}</div></div>\r\n" +
      "<div class='ngCell col8 col8t'><div class='ngCellText col8 col8t'>{{aggregateLots(row)}}</div></div>\r\n" +
      "\n" +
      "    <div class=\"{{row.aggClass()}}\"></div>\r" +
      "\n" +
      "</div>\r" +
      "\n",
    data: 'griddata',
    showFilter: false,
    width: '572px',
    showGroupPanel: false,
    groups: ['groupCol'],
    enableRowSelection: false,
    multiSelect: true,
    selectWithCheckboxOnly: true,
    showSelectionCheckbox: true,
    checkboxCellTemplate: '<div class="ngSelectionCell" ng-class="Header"><input tabindex="-1" class="ngSelectionCheckbox" class="Header" type="checkbox" ng-checked="row.selected" /></div>',

    columnDefs: [{
      field: 'groupCol',
      visible: false
    }, {
      field: 'cname',
      displayName: 'Contract',
      width: '150px'
    }, {
      field: 'maturity',
      displayName: 'Maturity',
      width: '112px',
      cellFilter: 'date:\'dd-MMM-yy\''
    }, {
      field: 'bs',
      displayName: 'B/S',
      width: '50px'
    }, {
      field: 'price',
      displayName: 'Price',
      width: '100px'
    }, {
      field: 'identid',
      displayName: 'Trades',
      width: '100px'
    }, {
      field: 'lots',
      displayName: 'Lots',
      width: '60px'
    }]

  };


  _.each(tradelist, function(trade) {
    trade.groupCol = trade.cname ;
  });
  $scope.griddata = _.sortBy(tradelist, function(row) {
    return row.groupCol;
  });

Now my requirement is

  • Show checkbow with First level
  • On second level expand also show with it to expand at third level.
  • show checkbox with third level.

For example -

enter image description here

And all this I want to create only with ng-grid, not with ui-grid or any other.

0

There are 0 best solutions below