Apply filter to sfKanban control

I'm having difficulty getting the sfKanban control to refresh when a filter is applied to a CollectionView.   Binding works and displays all the records, and filter
works but only on the initial binding.  When a command is called, the DoFilter function is called, but there is no effect on the view in the Kanban board.

Any suggestions?


example:

class CarViewModel : INotifyPropertyChanged
{
            public CarViewModel ( )
             {
                 MyCarCollection = new ObservableCollection<Car>();

                 PopulateCollection( );

                 _inventoryView = CollectionViewSource.GetDefaultView( MyCarCollection );

                // the code here works

                                 this.FilterString = "2008";
                 _inventoryView.Filter = YearFilter;
                               
              }

      //  CollectionViews
      //

      private ICollectionView _inventoryView;
     
      public ICollectionView InventoryView
      {
           get { return _inventoryView; }
      }
    


            private string _filterstring;
           
            public string FilterString
           {
                    get { return _filterstring; }
                    set { _filterstring = value;
                            OnPropertyChanged("Filter");
                           _inventoryView.Refresh();
           }

       private bool YearFilter( object item )
      {
            Car x = item as Car;
            return x.Year.Contains(filterstring);
      }

      public void ApplyFilter()
     {
       // the code here doesn't work, even though it is triggered
       MessageBox.Show ("filter is being applied");

       this.Filterstring = "2008";
       _inventoryView = YearFilter;

     }

}


6 Replies

RA Rachel A Syncfusion Team October 17, 2017 10:19 AM UTC

Hi Milan, 
Thanks for contacting Syncfusion support. 
We have prepared the sample to update the collection view dynamically based on the filter. Please find the sample in the below location. 
If you still face the problem, please revert to us with the sample reproducing the issue which would be helpful to provide you a solution. 
Regards, 
Rachel. A 



MD Milan Danrel October 17, 2017 05:02 PM UTC

Thank you for the sample Rachel, it's not very different from my approach.

However I'm trying to avoid code-behind, so my example has a button bound to an ICommand, which then executes the ApplyFilter( ) function in the viewmodel.
In your example, similar to what you have a button_click even handler to null out the ItemSource before applying the filter. I could have also implement it this
way but I'd like to use the commanding approach.

What I was hoping to achieve is that the filter would be set (on the CollectionView ) in the viewmodel, and this would then notify the Kanban control to update itself.

Perhaps I'm using Property notifications incorrectly and should be using COllection notifications, but the collection isn't really changing, only the collectionview.

See attached example.

thanks


Attachment: WpfFilteringExample_ebdc6870.zip


RA Rachel A Syncfusion Team October 18, 2017 01:39 PM UTC

Hi Milan, 

Thanks for the update. 

We have modified the sample based on your requirement. Please find the sample in the below location. 

Rachel.A 



RA Rachel A Syncfusion Team October 18, 2017 01:41 PM UTC

Hi Milan, 

Thanks for the update. 

We have modified the sample based on your requirement. Please find the sample in the below location. 

Rachel.A 



MD Milan Danrel October 19, 2017 06:01 AM UTC

Thanks Rachel.  Your solution works.  However I found that if the filter was cleared, then your code would no longer update the Kanban control,
because the ItemSource was nulled out.  The solution I found is something like shown below, a slight variation to yours

public void ExecFilter( object param ){

    SfKanban myKanbanObj = param as SfKanban;

    myKanbanObj.ItemSource = null;

   _inventoryView.Filter += YearFilter;

    OnPropertyChanged("Filter");

    myKanbanObj.ItemSource = _inventoryView;   // now the filter can be reapplied after clearing

}


public void ClearFilter( )

{

    _inventoryView.Filter = null;

    OnPropertyChange("Filter");

}





RA Rachel A Syncfusion Team October 19, 2017 10:23 AM UTC

Hi Milan, 

Thanks for the update. 

Please let us know if you have any queries. 

Regards, 
Rachel. A 


Loader.
Up arrow icon