简体   繁体   English

使用 Ag-Grid 过滤 1 个单元格中的 2 个数据

[英]filter 2 data in 1 cell with Ag-Grid

I'm displaying 2 data in 1 cell with Ag-Grid and i want to create a filter for every data.我使用 Ag-Grid 在 1 个单元格中显示 2 个数据,我想为每个数据创建一个过滤器。 The filtering used to work with one data but now i doesn't anymore.过滤过去只处理一个数据,但现在我不再使用了。 here is a screenshot of my Grid: Interface这是我的网格的屏幕截图:界面

I want to display the 2 headers below each other and add filter to each header.我想在彼此下方显示 2 个标题并向每个 header 添加过滤器。 Here is my code how i used the simple filtering in app-component.ts :这是我如何在app-component.ts中使用简单过滤的代码:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Grid, GridApi } from 'ag-grid-community';
import { AgGridAngular } from 'ag-grid-angular';
import { DealsService } from './services/deals.service';
import * as moment from 'moment';
import {DateCellRendererComponent} from 'src/app/date-cell-renderer/date-cell-renderer.component'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'app';
gridOptions = {
rowHeight :90,
headerHeight:60
}
columnDefs = [
{headerName: "Block \n Deal", cellRenderer: function(params){ return params.data.BLOCKID + '<br/>' + params.data.DEALID },width:150, resizable:true, filter: 'agNumberColumnFilter'} ,
{headerName: 'Class \n Type', cellRenderer: function(params){ return params.data.DEALCLASS + '<br/>' + params.data.DEALTYPE },width:150, resizable:true, filter: true} ,
{headerName: 'Trade \n Start',cellRendererFramework: DateCellRendererComponent ,width:150, resizable:true, filter: 'agDateColumnFilter' } ,
{headerName: 'Folder \n Cpty', cellRenderer: function(params){ return params.data.FOLDERSHORTNAME + '<br/>' + params.data.CPTYSHORTNAME },width:150, resizable:true, filter: true} ,
{headerName: 'ShortName \n Name', cellRenderer: function(params){ return params.data.INSTRSHORTNAME + '<br/>' + params.data.INSTRNAME },width:150, resizable:true, filter: true, } ,

{headerName: 'Quantity \n Settl.Amt',cellRenderer: function(params){ return params.data.QUANTITY + '<br/>' + params.data.SETTLEAMT },width:150, resizable:true, filter: 'agNumberColumnFilter'} ,
{headerName: 'Rate \n Fees', cellRenderer: function(params){ return params.data.FLOATINGRATESSHORTNAME + '<br/>' + params.data.RENTSPREADFIXEDRATE },width:150, resizable:true, filter: true} ,
{headerName: 'Category \n Status',cellRenderer: function(params){ return params.data.DEALCAT + '<br/>' + params.data.WORKFLOWSTATE },width:150, resizable:true, filter: true} ,
{headerName: 'End', field : 'ENDDATE',valueFormatter : this.dateFormatter,width:140, resizable:true, filter : 'agDateColumnFilter'}




];

rowData : any;

constructor(private service:DealsService) {



}
dateFormatter(params){
return moment(params.value).format('DD/MM/YYYY');
}


ngOnInit() {
this.service.getDealsList().subscribe(data => {
this.rowData = data;
}); }

}

and here is my app-component.html :这是我的app-component.html

<ag-grid-angular class="ag-theme-balham" ng-grid="gridOptions"
style="width: 1350px; height: 630px;"
class="ag-theme-alpine"
[rowData]="rowData"
[columnDefs]="columnDefs"
[gridOptions]="gridOptions"
[animateRows]="true"
[paginationPageSize]="10"
[pagination]="true"
>
</ag-grid-angular>

I'm really thankful for your help.我真的很感谢你的帮助。

Hmmm that's not possible with the ag-grid filters I guess (I'm not 100% sure).嗯,我猜使用 ag-grid 过滤器是不可能的(我不是 100% 确定)。 I think that it only might be possible using the custom filter component我认为只有使用custom filter component才有可能

https://www.ag-grid.com/javascript-grid-filter-component/ https://www.ag-grid.com/javascript-grid-filter-component/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM