Filter IDs by list of IDs in code

i have a datagrid with severals columns including an id column. 

in an external Filter methode i get a list of ID's now i want to set a Grid filter based on the id's returned by this methode to only show the rows with the id's that are in the list that was retuned by the external Filter.

this must happen in code so that when the external filter is set the grid show the filtered data and the user is still able to remove the filter from the datagrid if needed.

i did found the reference to 

this.GridObj?.FilterByColumn(
           "columnename",
            "filterOption",
            "filterValue");

is this the right way to start and how can i make this possible

5 Replies

RS Renjith Singh Rajendran Syncfusion Team March 30, 2020 09:03 AM UTC

Hi Andreas, 

Thanks for contacting Syncfusion support. 

Yes, it is recommended to use the FilterByColumn method of Grid to programmatically perform filtering in Grid. We suggest you to refer the below documentation in which we have used the FilterByColumn method to perform filtering when changing the value in DropDownList(for an example). 
 


And also you can perform multi value filtering using the FilterByColumn method of Grid. Please refer the below code to perform multi value filtering in Grid using FilterByColumn method. 

 
@code{ 
   public List<int> FilterValue = new List<int>() { 1001, 1002, 1005 }; 
    public void onclick() 
    { 
        GridInstance.FilterByColumn("OrderID","equal", FilterValue); 
    } 
} 


Kindly refer the above documentation and please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



AN Andreas April 1, 2020 05:12 PM UTC

i have added this to my code:

        this.GridObj?.ClearFiltering();
        if (Service.Filter.SelectedGroup != null)
        {
            var classificationIds = Service.Classifications
                .Where(e => e.ClassificationGroupId == Service.Filter.SelectedGroup.ClassificationGroupId)
                .Select(e => e.ClassificationId).ToList();
            this.GridObj?.FilterByColumn(
                nameof(Transaction.ClassificationId),
                "equal",
                classificationIds);
        }
        this.GridObj?.Refresh();


now when this code part is run i get the following script errors on the page:

Cannot read property 'toString' of undefined
TypeError: Cannot read property 'toString' of undefined
    at t.setFormatForFlColumn (https://localhost:5000/_content/Syncfusion.Blazor/scripts/grids-ec5227.min.js:1:457484)
    at t.applyColumnFormat (https://localhost:5000/_content/Syncfusion.Blazor/scripts/grids-ec5227.min.js:1:448791)
    at t.filterByColumn (https://localhost:5000/_content/Syncfusion.Blazor/scripts/grids-ec5227.min.js:1:448118)
    at r.filterByColumn (https://localhost:5000/_content/Syncfusion.Blazor/scripts/grids-ec5227.min.js:1:282585)
    at https://localhost:5000/_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js:1:164159
    at u (https://localhost:5000/_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js:1:6710)
    at Generator._invoke (https://localhost:5000/_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js:1:6463)
    at Generator.forEach.e.<computed> [as next] (https://localhost:5000/_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js:1:7067)
    at r (https://localhost:5000/_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js:1:3019)
    at s (https://localhost:5000/_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js:1:3230)


Grid Column config looks like this:
                        <GridColumn Field="@nameof(Transaction.ClassificationId)"
                                    HeaderText="@nameof(Transaction.ClassificationId)"
                                    Format="d"
                                    EditType="EditType.NumericEdit" />


the Transaction.ClassificationId is of type long


RS Renjith Singh Rajendran Syncfusion Team April 2, 2020 08:35 AM UTC

Hi Andreas, 

Thanks for your update. 

We suggest you to ensure to set proper number formatting values for the Format property for the number valued columns to overcome the problem you are facing. Please refer the below documentation and the code example to overcome the  problem you are facing. 
 
 
        <GridColumn Field="@nameof(Order.OrderID)" 
                    Format="N" 
                    EditType="EditType.NumericEdit" /> 


Please use the above suggested solution in your application and if you are still facing any difficulties, then kindly get back to us with your complete Grid code to proceed further.  

Regards, 
Renjith Singh Rajendran. 



AN Andreas April 2, 2020 07:08 PM UTC

this seem to work thank you


RS Renjith Singh Rajendran Syncfusion Team April 3, 2020 04:33 AM UTC

Hi Andreas, 

Thanks for your update. 

We are glad to hear that our suggestion helped you in achieving your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon