SfDataGrid Filtering

Hi 

I have a SfDataGrid and depending on a button click i load 2 different DataTables.

I have Auto Generate columns to off and create the columns on each click

I am struggling to get the filtering working.

Both tables load and search correctly

I have converted both data tables to Dynamic objects as required.

see code snipits below 

private void GenerateColumsForTubes(bool animal) //remove all columns and add as required
        {
            tubePurDataView.Columns.Clear();
            tubePurDataView.AutoGenerateColumns = false;
            if (animal)
            {
               
                tubePurDataView.Columns.Add(new GridTextColumn() { NullDisplayText = "", MappingName = "Tag" });
                tubePurDataView.Columns.Add(new GridDateTimeColumn() { NullDisplayText = "", AllowNull = true, MappingName = "DOB" });
                tubePurDataView.Columns.Add(new GridTextColumn() { MappingName = "Breed" });
                tubePurDataView.Columns.Add(new GridDateTimeColumn() { NullDisplayText = "", AllowNull = true, MappingName = "Date Moved In" });
                tubePurDataView.Columns.Add(new GridDateTimeColumn() { NullDisplayText = "", AllowNull = true, MappingName = "Calving Date1" });
                tubePurDataView.Columns.Add(new GridDateTimeColumn() { NullDisplayText = "", AllowNull = true, MappingName = "Calving Date2" });
                tubePurDataView.Columns.Add(new GridDateTimeColumn() { NullDisplayText = "", AllowNull = true, MappingName = "Calving Date2" });
               
            }
            else
            {               
                tubePurDataView.Columns.Add(new GridTextColumn() { NullDisplayText = "",  MappingName = "id" });
                tubePurDataView.Columns.Add(new GridDateTimeColumn() { NullDisplayText = "", AllowNull = true, MappingName = "dateOfPurchase" });
                tubePurDataView.Columns.Add(new GridTextColumn() { MappingName = "TubeName" });
                tubePurDataView.Columns.Add(new GridTextColumn() { MappingName = "NoOfTubes" });
                tubePurDataView.Columns.Add(new GridTextColumn() { NullDisplayText = "", MappingName = "supplier" });
            }
            tubePurDataView.AllowFiltering = true;
        }

private void tubeSearchTB_TextChanged(object sender, EventArgs e)  //search method
        {
            this.tubePurDataView.SearchController.Search(tubeSearchTB.Text);
        }

private ObservableCollection<ExpandoObject> setExpandoDtTubes(DataTable dt) // Convert and return the dynamic collection
        {
            var collection =dt;
            var dynamicCollection = new ObservableCollection<ExpandoObject>();
            foreach (System.Data.DataRow row in collection.Rows)
            {
                ExpandoObject expandoObject = new ExpandoObject();
                dynamicCollection.Add(expandoObject);
                foreach (DataColumn column in collection.Columns)
                {
                    var dictionary = ((IDictionary<string, object>)(expandoObject));
                    dictionary[column.ColumnName] = row[column];
                }
            }

           return dynamicCollection;        

        }

public ObservableCollection<ExpandoObject> tubePur 
        {
            get; set;
        }

private void LoadData() //loading data and passing to dynamicGenerator above 
 {
        
  if(dt1.Rows.Count>0)
        {
                GenerateColumsForTubes(false); // passing true loads other table 
                tubePur = setExpandoDtTubes(dt1);
                tubePurDataView.DataSource = tubePur;
                showingTubes = true;                 
         } 
 }

I have this implementation on a diffeernt form that has only one table but same set up and it seems to work perfectly ? 

Help 



3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team June 14, 2021 11:51 AM UTC

Hi Peter, 

Thanks for contacting Syncfusion support. 

We are unclear with the scenario you are reporting. We have prepared a sample with two different DataTable and the code snippets you have provided in your update. But unfortunately, we are unable to find any issue in filtering. Both search filtering and UI filtering using Filter icon in the header are working properly. The sample we have used to check this is available in the following link for you reference.  


Please have a look at this sample and let us know if we have missed any customization you have done in your application. Otherwise try to reproduce the reported issue in this sample and revert to us with the modified sample. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution at earlier. 

Regards, 
Mohanram A. 


Marked as answer

PE Peter June 14, 2021 12:25 PM UTC

Hi Mohanram 

The sample works correctly. 

In my application the filter by Icon or UI is working (I had not checked this previous)

Filter by search is not working tho !!! The search is working as it highlights correctly but does not filter the data? 

 



MA Mohanram Anbukkarasu Syncfusion Team June 15, 2021 12:09 PM UTC

Hi Peter, 

Thanks for the update.  

As we mentioned in our previous update, filter by search is also working properly in the sample we have provided. So please try to reproduce the reported issue in this sample and revert to us with the modified sample as we requested in our previous update. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution at earlier.  

Regards,  
Mohanram A. 


Loader.
Up arrow icon