Excel filtering

Hi,

Could you help me how to filter the column value according to selected value.

I have 

id          Alphabets     
 1.             Aa Bb AA
2.              Cc dd DD

Alphabets column have filter .
What I need is when selecting dd then it should show like this

id          Alphabets     
2.            dd 

Thank you and I await,
Willima Hill


7 Replies

GL Gowri Loganathan Syncfusion Team March 2, 2020 12:16 PM UTC

 
Hi Wilma, 
 
Thanks for using Syncfusion Products  
 
Query # :  How to filter the column value according to selected value. 
 
We are quite unclear about your query. 
 
Please share us the below details which will be very helpful for us to proceed further. 
 
  1. Confirm whether you use EJ2 Grid or TreeGrid.
  2. When you use excel filtering in TreeGrid, while perform filter operation in the checkbox list complete column data are shown. In this case how can you select the specific letters (eg: dd) only from (eg: CC dd DD). If you use any custom filter or you change the default operator to “contains”, kindly share us the complete code snippet.
  3. Also Kindly explain your requirement in detail.
 
Regards, 
Gowri V L. 
 



WH Wilma Hill March 3, 2020 04:09 AM UTC

Hi Gowry,

Thanks for the reply

this is my html file 
<ejs-treegrid #treegrid [(dataSouce)]="dataSource"    [editSettings]="editSettings" [filterSettings]='filterOptions'>
    <e-columns>
            <e-column field='id' headerText='Student ID' width='120' textAlign='Right'>e-column>
            <e-column field='name' headerText='Student Name' width='150'>e-column>
            <e-column [allowEditing]=true field='passSubjects' headerText='Pass Subject' width='120'  textAlign='Right' [filter]="excelFilter">
                <ng-template let-data>
                  <span *ngFor=let passSub of data.passSubject>
                      {{passSub.code}}
                  span>
                ng-template>
            e-column>
              <e-column [allowEditing]=true field='failSubjects' headerText='Fail Subject' width='120'  textAlign='Right' [filter]="excelFilter">
                <ng-template let-data>
                  <span *ngFor=let failSub of data.passSubject>
                      {{failSub.code}}
                  span>
                ng-template>
            e-column>
        e-columns>
ejs-treegrid>


this is .ts file

 dataSource:Object[]=[];

  excelFilter:IFilter;
 
  @ViewChild('treegrid')
    public treeGridObj: TreeGridComponent;

    public editSettings: EditSettingsModel = {
    allowEditing: true,
    allowAdding: true,
    allowDeleting: true,
    mode: "Cell",
    showConfirmDialog: true
  };
    public filterOptions: FilterSettingsModel = {
    type: "Menu",
    ignoreAccent: true,
    showFilterBarStatus: true,
    mode: "Immediate"
  };

    ngOnInit(): void {
     this.getTableData();
      this.excelFilter={
        type:"Excel",
      }
    }

    ngAfterViewInit(): void {
       this.treeGridObj.created.subscribe((e) => {
      this.getTableData();
    });
    }
    getTableData(){
       this.dataSource=studentData;
    }
}


const studentData=[
  {
    id:001,
    name:"abc",
    passSubjects:
    [
      {id:1,
      name:"english",
      code:'ENG',
      },
       {id:5,
      name:"math",
      code:'MAT',
      },
       {id:6,
      name:"science",
      code:'SCI',
      },
    ],
    failSubjects:[
       {id:2,
      name:"economic",
      code:'ECO',
      },
       {id:3,
      name:"principle of management",
      code:'POM',
      },
    ]
  },
   {
    id:002,
    name:"abc",
    passSubjects:
    [ {id:1,
      name:"english",
      code:'ENG',
      },
        {id:2,
      name:"economic",
      code:'ECO',
      },
       {id:3,
      name:"principle of management",
      code:'POM',
      },
       {id:6,
      name:"science",
      code:'SCI',
      },
    ],
    failSubjects:[
        {id:5,
      name:"math",
      code:'MAT',
      },
    ]
  },
   {
    id:003,
    name:"abc",
    passSubjects:
    [
      {id:1,
      name:"english",
      code:'ENG',
      },
       {id:5,
      name:"math",
      code:'MAT',
      },
       {id:6,
      name:"science",
      code:'SCI',
      },
       {id:2,
      name:"economic",
      code:'ECO',
      },
    ],
    failSubjects:[
       {id:3,
      name:"principle of management",
      code:'POM',
      },
    ]
  },
]


Requirements:
  1. Display column with code of pass subject and fail subject .
  2. While filtering the column should contain name of subject for user to select.
  3. When choose name then its should display its respective code only and other if column contain then not showing.
  4. Multiple filtering can be done .


Regards
Wilma Hill.




GL Gowri Loganathan Syncfusion Team March 4, 2020 09:00 AM UTC

Hi Wilma, 

Thanks for the details. 

Query # :  How to filter the column value according to selected value. 
 
  
While analyzing your code snippets we could see that you have used multiple array of objects for the fieldName (passSubjects and failSubjects). Using ngFor we can display the multiple array of objects in the same cell but we are unable to perform the data operations. In TreeGrid , we don’t have support for performing data operations when we use multiple array of objects in the same cell. 
  
Kindly get back to us, if you need further assistance from us. 

Regards, 
Gowri V L 



WH Wilma Hill March 5, 2020 09:37 AM UTC

Hi Gowry,
Thank for the information

I like to know when using checkbox filter how to know which values are selected and i need to store the selected values in array.

checkbox filter UI has following option

1.select All
2. A
3 B
4.C
5. Blank

Problem:
when selected A,B  I get the desired output [A,B] but when selecting A,B,C then the selected value is undefined so I cannot save them in array . 

Note:value A,B,C are dynamic .I am using  Treegrid .

I need to store the user selected value of filter UI in array .



GL Gowri Loganathan Syncfusion Team March 6, 2020 11:12 AM UTC

Hi Wilma, 
 
Thanks for the update. 
 
Query :How to get the user selected values in filter check box 
 
We have analysed your query at our end and we have achieved your requiremnet using actionBegin event of TreeGrid. In this event when requestType is “filtering” we get the user selected values from the arguments and stored it in the array and also we have emptied the selected value array while perform clear filtering using actionComplete event. 
 
Code snippet 
 
Component.html file 
<ejs-treegrid #treegrid [dataSource]='data' (actionBegin)="actionBegin($event)" (actionComplete)="actionComplete($event)" allowFiltering='true' [filterSettings]='filterSettings'> 
. . . . . . 
 
Component.ts file 
 
. . . . . . .  
export class AppComponent 
{ 
    public selectedValue: Object[] = []; 
    public data: Object[] = []; 
. . . .  . . .  
    } 
. . . . . .  
actionBegin(e:any)    //triggers when perform filtering 
{ 
    if (e.requestType === 'filtering') 
    { 
        for (let i: number = 0; i < e.columns.length; i++) { 
            this.selectedValue.push(e.columns[i].properties.value);  //store the selected values from filter checkbox here 
        } 
        console.log(this.selectedValue); 
 
    } 
} 
actionComplete(e:any) 
{ 
 
    if (e.requestType === 'refresh' && !this.treegrid.filterModule.filteredResult.length) 
    { 
        this.selectedValue =[];   //empty the selected values when clear filter 
        console.log(this.selectedValue);   
 
    } 
 
} 
. . . . . . .  
 
 
Please refer the below sample 
 
 
Kindly get back to us, if you need more assistance on this 
 
Regards, 
Gowri V L. 



WH Wilma Hill March 11, 2020 06:11 AM UTC

Hi Gowry,
Thank I would like to ask if there any way to give field name defined in ts file in e-column.

What I need is :
in ts                                   in html
fieldName=[a,b,c];             
In treeGrid Component. While filtering option enable it should have available value a,b,c



MP Manivannan Padmanaban Syncfusion Team March 12, 2020 07:06 AM UTC

Hi Wilma, 

Thanks for the update. 

We don’t have the support to use array value as field name.  

Regards, 
Manivannan Padmanaban.  


Loader.
Up arrow icon