Filter checkboxes

Hi,

I have a data source Users with the following columns

Id
UserName
CountryId

I have a separate data source Countries with the following columns

Id
CountryName

I need to show a grid with users with columns 
UserName
Country

And for the country column I need a custom filter with checkboxes to be able to select multiple countries to filter by their Id.

How can I do this?

Thank you,
Andrii

9 Replies

RS Rajapandiyan Settu Syncfusion Team April 3, 2020 12:57 PM UTC

Hi Andrii, 

Greetings from syncfusion support. 

Query : I need a custom filter with checkboxes to be able to select multiple countries to filter by their Id. How can I do this? 
 
We have validated your requirement and suggest you to use the ForeignKey feature which meets your requirement. We have prepared a sample, the Grid with foreignKey and checkbox filter feature.  

To bind a foreign key column in the grid’s column we have to set foreignKeyValue, ForeignKeyField and dataSource to that column. Refer the below documentation for more information. 


By default, filtering the foreignKeyColumn using checkbox filter is based on the foreignKeyField. Refer the below sample for more information. 

 
Please get back to us if you need further assistance on this. 
 
Regards, 
Rajapandiyan S.


AK Andrii Kaplanovskyi April 6, 2020 02:58 PM UTC

Dear Rajapandiyan,

Thank you for your help. The problem is in my case I use custom data provider for my grid:

<ejs-grid
ref="grid"
:dataSource="users"
:dataStateChange='(state) => onDataStateChange(state)'
...
width="300"
>
<e-columns>
<e-column
field="Id"
ForeignKeyField="Id"
foreignKeyValue="CountryName"
:dataSource="contries"
></e-column>
</e-columns>
</ejs-grid>

And every time I try to click on a filter button for the Country, onDataStateChange method is called and the request to server is sent, while I expected  those countries to be retrieved from the data source specified for the Country column (dataSource="countries") 



AK Andrii Kaplanovskyi April 6, 2020 04:23 PM UTC

Also, Rajapandiyan,

I try to follow your example, when I click on the Countries filter menu box, the popout is displayed, but instead of the list of countries I see a "loading..." icon is spinning.
I can't see any error messages, any requests, just never ending "loading..." sign. Am I doing something wrong, and how can I see what is going on, what wen wrong?

Thank you,
Andrii




MS Manivel Sellamuthu Syncfusion Team April 9, 2020 02:13 PM UTC

Hi Andrii,  
 
Currently we are facing some difficulties to achieve your requirement at sample level. So we need some time for this and will provide the sample on or before Apr 14th 2020. 
 
Until then we appreciate your patience. 
 
Regards, 
Manivel 



RS Rajapandiyan Settu Syncfusion Team April 14, 2020 01:09 PM UTC

Hi Andrii, 
 
Thanks for your patience. 
 
Query : And every time I try to click on a filter button for the Country, onDataStateChange method is called and the request to server is sent, while I expected  those countries to be retrieved from the data source specified for the Country column (dataSource="countries")  
 
As per your requirement we have created a grid with custom binding and foreign key column. While using custom binding grid we need to bind the result value only instead of result and count value in the dataStateChange event when on filtering with requestType as filterchoicerequest. Please refer the below code example and documentation for more information. 
 
 
<template> 
    <div id="app"> 
        <ejs-grid ref="grid" :dataSource='data' :allowFiltering='true'  :allowPaging='true' :filterSettings='filterOptions' :pageSettings='pageOptions' 
         :allowSorting='true' :allowGrouping='true' :dataStateChange='dataStateChange'> 
            <e-columns> 
                <e-column field= "OrderID" headerText="Order ID" width="130" textAlign='Right' ></e-column> 
                 <e-column field= "EmployeeID" headerText="Employee ID" foreignKeyValue="Extension" :dataSource="colData" width="150"></e-column> 
            </e-columns> 
        </ejs-grid> 
    </div> 
</template> 
<script lang="js"> 
import Vue from "vue"; 
import { GridPlugin, DataStateChangeEventArgs,Edit,Filter, Sorts,Toolbar, Sort, Group, Page, ForeignKey, DataResult } from "@syncfusion/ej2-vue-grids"; 
import { Ajax } from '@syncfusion/ej2-base'; 
import { data } from './datasource'; 
import { OrderService } from "./OrderService.ts"; 
import { EmployeeService } from "./EmployeeService.ts"; 
 
Vue.use(GridPlugin); 
 
export default Vue.extend ({  
  name: "app", 
  data() { 
    return { 
      data: {}, 
      colData:[{EmployeeID:1,Extension:23}, 
      {EmployeeID:2,Extension:34}, 
      {EmployeeID:3,Extension:12}, 
      {EmployeeID:4,Extension:37}, 
      {EmployeeID:5,Extension:342}], 
      filterOptions: { 
           type: 'Excel' 
        }, 
      pageOptions: { pageSize: 10, pageCount: 4 }, 
      orderService: new OrderService(), 
      data1: OrderService, 
    }; 
  }, 
  mounted() { 
    let state = { skip: 0, take: 10 }; 
    this.dataStateChange(state); 
  }, 
  provide: { 
    grid: [Page,Filter, Edit, Toolbar, ForeignKey] 
  }, 
  methods: { 
dataStateChange: function (state) { 
       if (state.action && (state.action.requestType === "filterchoicerequest" || state.action.requestType ==="filtersearchbegin")) { 
      this.orderService.execute(state).then((e) => { 
        state.dataSource(e.result); // bind the result value to the grid 
      }); 
    } else { 
       this.orderService.execute(state).then(( gridData ) => this.data = gridData ); 
    } 
    } 
  } 
}) 
</script> 
 
 
 
 
If you still face any problem please share the below details which will be helpful to validate further on this. 
  1. Share the full grid code.
  2. Share any video demonstration of the reported problem.
  3. If possible share the issue reproduced sample with us.
 
Regards, 
Rajapandiyan S 



AK Andrii Kaplanovskyi April 15, 2020 02:44 PM UTC

Dear Rajapandiyan,

Thank you very much for your example, but my question is still not answered. In the example you sent me, when I try to display a filter with checkboxes for EmployeeId, dataStateChange method is executed:

dataStateChange: function (state) { 
       if (state.action && (state.action.requestType === "filterchoicerequest" || state.action.requestType ==="filtersearchbegin")) { 
      this.orderService.execute(state).then((e) => { //This line will still send a request to server side, asking to return ALL records we have (we have 15 000)
        state.dataSource(e.result); //Then this line assigns all these 15 000 records returned to my client side grid, showing them all!
      }); 

I do not understand why I need to send a request to server to return ALL records, while all I need is the list of employees, which I already have on my client side, stored in colData Property:

<e-column field= "EmployeeID" headerText="Employee ID" foreignKeyValue="Extension" :dataSource="colData" width="150"></e-column> 

export default Vue.extend ({  
  name: "app", 
  data() { 
    return { 
      data: {}, 
      
colData:
[{EmployeeID:1,Extension:23},
 ...

Thank you,
Andrii
 



AK Andrii Kaplanovskyi April 15, 2020 04:16 PM UTC

Dear Rajapandiyan, 

To be more clear, in the example you provided what I want is:

dataStateChange: function (state) { 
       if (state.action && (state.action.requestType === "filterchoicerequest" || state.action.requestType ==="filtersearchbegin")) { 
       //instead of sending a request to server to return all records:
      //this.orderService.execute(state).then((e) => { 
      //  state.dataSource(e.result); // bind the result value to the grid 
      //});
      //I want values for the EmployeeID column filter to be taken from colData, as they are already on client  
    } else { 
       this.orderService.execute(state).then(( gridData ) => this.data = gridData ); 
    } 

Is it possible?

Regards,
Andrii


RS Rajapandiyan Settu Syncfusion Team April 21, 2020 03:23 AM UTC

Hi Andrii,   
  
Currently we are validating your requirement at source level. Since we need some time for this and will update the further details on or before Apr 22nd 2020.  
  
Until then we appreciate your patience.  
  
Regards,  
Rajapandiyan S 



RS Rajapandiyan Settu Syncfusion Team April 21, 2020 04:57 PM UTC

Hi Andrii, 
  
Thanks for your patience. 
  
Query : To be more clear, in the example /instead of sending a request to server to return all records: /I want values for the EmployeeID column filter to be taken from colData, as they are already on client Is it possible? 
  
No. because filtering foreignKey column is depends on the both Grid and foreignKey column’s dataSource.  
 
We would like to share the details about working flow of foreign key column filtering. By default clicking filtering icon shows all the available distinct values of grid dataSource in the filter’s check list. To do that, in the source side we get all the records of the grid and bound it to the filter check list.  
 
If it is foreignKey column, in the source side, it fetches all the records of the grid datasource and get the distinct records of foreignKeyField (EmployeeID).  Now the foreignKeyField is replaced with the foreignKeyValue (Extension) which is bound in the filter check list.  
 
So we need the grid DataSource to filter the foreignKeyField. Please get back to us if you need further assistance on this. 
  
Regards, 
Rajapandiyan S

Loader.
Up arrow icon