Excel filter on an editable foreign key on TreeGrid

I have managed to get my editable foreign in my TreeGrid displaying, editing and exporting correctly. 
I have a requirement to put an Excel filter on this column. Currently, all I get is the foreign key ID. How do replace it with the equivelant description for the foreign key. Example replacing a CountryID with CountryName

1 Reply 1 reply marked as answer

GL Gowri Loganathan Syncfusion Team August 24, 2020 02:21 PM UTC

Hi Sean Chee,

Thanks for contacting Syncfusion Forum.

Query: Excel filter on an editable foreign key on TreeGrid.

We have achieved your requirement using actionBegin event of TreeGrid . In the sample we have assigned the customData to the excel filter popup when requestType is “filterbeforeopen” and when requestType is “filtering” we have changed its corresponding ID of customData for filtering operation.

Code

@(Html.EJS().TreeGrid("TreeGrid")                                                
.AllowFiltering() 
.FilterSettings(filter => filter.Type(Syncfusion.EJ2.TreeGrid.FilterType.Excel))                                                                                                    
   .ActionBegin("begin")                                                                                                       
<script> 
    var jsonData = @Html.Raw(Json.Encode(ViewBag.DropData)) 
    function begin(args) { 
        var customData = [] 
        if (args.requestType === "filterbeforeopen" && args.columnName === "EmployeeID") { 
            for (var i = 0; i < jsonData.length; i++) { 
                
                customData.push({ EmployeeID: jsonData[i].EmployeeName });  //to show the employeename in excel filter display 
            } 
            args.filterModel.options.dataSource = customData; 
            } 
        } 
        if (args.requestType === "filtering") { 
            for (var i = 0; i < jsonData.length; i++) { 
                if (args.columns[0].value == jsonData[i].EmployeeName) { 
                    args.columns[0].value = jsonData[i].EmployeeID;  
                } 
            } 
        } 
} 

</script>

 
Output 
 
 
 
Please revert us if you need more assistance. We will be happy to assist you. 
 
Regards, 
Gowri V L 
 
 


Marked as answer
Loader.
Up arrow icon