Ag-grid-在Angular 7中设置层次结构和总计

时间:2019-03-02 19:47:48

标签: c# angular ag-grid

我在angular 7应用程序中将数据绑定到ag-grid,并且在创建层次结构时遇到问题。我目前需要显示按策略和基金分组的列表。如果我做对了,请告诉我。我正在寻找实现以下格式。每个分组之后都应有一个空格,以使数据清晰。我正在寻求实现,如下面的屏幕截图所示。从屏幕快照中可以看到,经理策略和基金可以重复。两种策略之间的间隔用于显示总数。

Emv将包含Emv字段的总和,而Percent将包含GroupPercent字段的总和

enter image description here

ViewModel

  public class FirmWideAllocationsViewModel
    {
        public List<string> Hierarchy
        { get; set; }
        private decimal _groupPercent;
        public int FirmID { get; set; }
        public string FirmName { get; set; }
        public int? ManagerStrategyID { get; set; }
        public int? ManagerFundID { get; set; }
        public int ManagerAccountClassID{ get; set; }
        public int? ManagerFundOrClassID { get; set; }
        public string ManagerFundName { get; set; }
        public string ManagerAccountingClassName { get; set; }
        public string ManagerStrategyName { get; set; }
        public int? ProductID { get; set; }
        public string ProductName { get; set; }
        public int? Quantity { get; set; }
        public decimal? Nav { get; set; }
        public DateTime EvalDate { get; set; }
        public int? DefaultStrategyID { get; set; }
        public string DEFAULT_STRATEGY_NAME { get; set; }
        public decimal Usd_Emv { get; set; }
        //needed for kendo aggregates
        public decimal UsdEmv => Usd_Emv;
        public decimal Emv { get; set; }
        public decimal Weight { get; set; }
        [NotMapped]
        public decimal Percent { get; set; } // manual calc
        [NotMapped]
        public decimal Sort
        {
            get
            {
                return ProductName == "Other"
                    ? decimal.MaxValue
                    : Usd_Emv;
            }
        }
        [NotMapped]
        public decimal GroupPercent
        {
            get { return _groupPercent; }
            set { _groupPercent = value; }
        }

    }

控制器

public class AllocationsController : ApiControllerBase
{
    [HttpGet]
    [Route("api/Allocations/{id}")]
    public IHttpActionResult Details(int id, DateTime date)
    {

        var viewModel = GetAllocationsViewModel(id, date);
        if (viewModel == null) return NotFound(); 
        return Ok(viewModel);
    }


      private AllocationsViewModel GetAllocationsViewModel(int id, DateTime date)
    {

        var ms = GetStrategy(id);

        DateTime d = new DateTime(date.Year, date.Month, 1).AddMonths(1).AddDays(-1);
        if (ms.FIRM_ID != null)
        {

            var allocationsGrouped = Mapper.Map<List<FIRMWIDE_MANAGER_ALLOCATION>, List<FirmWideAllocationsViewModel>>(GetAllocationsGrouped(EntityType.Firm, firm.ID, d).ToList());
            foreach (var ag in allocationsGrouped)
            {
                ag.Hierarchy = new List<string>
                {ag.ManagerStrategyName, ag.ManagerFundName};
            }


            var vm = new AllocationsViewModel
            {
                ManagerAllocations = allocationsGrouped
            };

            return vm;
        }

        }

Ag-grid列定义

setGridOptions() {
        this.GridOptions = {
            columnDefs: this.getColumns(),
            rowData: this.AllocationDetails,
            enableFilter: true,
            treeData: true,
            enableColResize: true,
            animateRows: true,
            groupDefaultExpanded: 1,
            enableSorting: true,
            suppressCellSelection: true,
            getDataPath: function (data) {
                return data.Hierarchy;
            },
            onGridReady: e => {
                if (!e || !e.api) {
                    return;
                }
                e.api.sizeColumnsToFit();
                this.setDefaultSortOrder();
            },
            getRowStyle: (params) => {
                if (params.node.level === 0) {
                    return { 'background-color': '#FCE7D7' };
                }
            },

            autoGroupColumnDef: {

                headerName: 'Manager Strategy', width: 300
            },
        };
    }


    private getColumns(): Array<any> {
        const self = this;
        const definition = [
            { headerName: 'Date', field: 'EvalDate', hide: true },
            { headerName: 'Firm ID', field: 'FirmID', hide: true },
            { headerName: 'Manager Strategy ID', field: 'FirmName', hide: true },
            { headerName: 'Firm', field: 'ManagerStrategyID', hide: true },
            { headerName: 'Manager Strategy', field: 'ManagerStrategyName' },
            { headerName: 'Fund ID', field: 'ManagerFundID', hide: true },
            { headerName: 'Fund', field: 'ManagerFundName' },
            { headerName: 'Portfolio', field: 'ProductName' },
            { headerName: 'As Of', field: 'EvalDate',   cellRenderer: (data) => {
                return data.value ? (new Date(data.value)).toLocaleDateString() : '';
             } },
            { headerName: 'EMV (USD)', field: 'UsdEmv',  valueFormatter: currencyFormatter },
            { headerName: 'Percent', field: 'GroupPercent' },

        ];

UI

  <div class="panel panel-default">

        <div *ngIf="AllocationDetails && AllocationDetails.ManagerAllocations" class="panel-body" style="width:100%">
                <div [style.height.px]="GridHeight()" [style.width.%]="100" style="float: left;">
                        <ag-grid-angular #agGrid class="ag-theme-balham" [gridOptions]="GridOptions" style="width: 100%; height: 100%"
                            [columnDefs]="ColumnDefs" [rowData]="AllocationDetails.ManagerAllocations"  rowHeight="30" headerHeight="30" rowSelection="single">
                        </ag-grid-angular>
                    </div>

        </div>
    </div>

JSON

[[{"ProductId":2844,"ProductName":"*DO NOT USE* City Plan LLC","ProductType":"Strategic Partnerships"},{"ProductId":2840,"ProductName":"*DO NOT USE* Baha'i Separate Managed Account","ProductType":"Strategic Partnerships"},{"ProductId":2851,"ProductName":"Test Special Opportunities Evergreen Fund Ltd.","ProductType":"Strategic Partnerships"},{"ProductId":2852,"ProductName":"Test Spafid Multi-Strategy Fund","ProductType":"Strategic Partnerships"}],[{"ProductId":2745,"ProductName":"Test Special Opportunities Fund III Master LP","ProductType":"Commingled Fund"},{"ProductId":2854,"ProductName":"Test Select Opportunities II Ltd.","ProductType":"Commingled Fund"},{"ProductId":2746,"ProductName":"Test Structured Income Fund I Ltd.","ProductType":"Commingled Fund"},{"ProductId":2749,"ProductName":"Test Structured Income Fund II Ltd.","ProductType":"Commingled Fund"},{"ProductId":2778,"ProductName":"Test Structured Income Fund II-A Ltd.","ProductType":"Commingled Fund"},{"ProductId":2794,"ProductName":"Test Hedge Fund Opportunities II Ltd. Continuing","ProductType":"Commingled Fund"}],[{"ProductId":2828,"ProductName":"ICBC Quantitative HengSheng Choice Pooled Fund.","ProductType":"Sub-Advisory "},{"ProductId":2853,"ProductName":"HEC SPV II Cayman LP","ProductType":"Sub-Advisory "},{"ProductId":2800,"ProductName":"TP ETP Offshore LP","ProductType":"Sub-Advisory "},{"ProductId":2829,"ProductName":"ICBC Quantitative Xincheng Choice Pooled Fund Trust.","ProductType":"Sub-Advisory "},{"ProductId":1841,"ProductName":"Brightgate Absolute Return FIL","ProductType":"Sub-Advisory "}],[{"ProductId":2827,"ProductName":"Test Alternative Income Strategy.","ProductType":"Liquid Alternatives"},{"ProductId":1603,"ProductName":"Test Alternative Core Fund","ProductType":"Liquid Alternatives"}]]

0 个答案:

没有答案