FlexGridFilter - sourceCollectionChanged doesn't triggers on edit

Posted by: rasika.sinha on 8 March 2018, 8:44 pm EST

  • Posted 8 March 2018, 8:44 pm EST

    Hi Team,

    I have implemented filtering in my editable flex grid via FlexGridFilter class. Everything works fine till I edit a cell after filtering any data in the same column.

    The sourceCollectionChanged event doesn’t triggers and nor do the changes reflect under collectionView.itemsEdited.

    I can see the changes in my grid once I clear the filtering and they reflect inside collectionView.sourceCollection.

    Can you please help me with what I am doing wrong or share an example?

    
    this.gridFilter = new wijmo.grid.filter.FlexGridFilter(this.grid);
    this.gridFilter.filterColumns = this.Options.columnFilter.columns;
    if (this.Options.columnFilter.filterDefinition && this.Options.columnFilter.filterDefinition.length > 0) {
    this.gridFilter.filterDefinition = this.Options.columnFilter.filterDefinition;
                }
    
    

    Thank you,

    Rasika.

  • Posted 11 March 2018, 5:28 pm EST

    Your understanding is correct, sourceCollectionChanged event does not trigger after update/edit , It gets fired when the reference of the sourceCollection changes.

    If you want to handle event when updates are done to CollectionView then use the collectionChanged event.

    You can Edited items exposed through the itemsEdited property only after you set collectionView.trackChanges=true;

    Please refer to following fiddle example:-

    http://jsfiddle.net/mtcme22y/

  • Posted 13 March 2018, 9:13 pm EST

    Hi Abhishek, you are right, I am tracking add/edit of grid via collectionChanged event and it works perfectly fine.

    But if I apply filter in a column and edit the value of the same column then the collectionChanged event triggers but the collectionView.itemsEdited.length remains 0.

    If I point the differences between my code and your example then the only difference is that the data is coming from API and there’s a lag.

    Can you point out what might be the probable cause?

  • Posted 14 March 2018, 9:17 pm EST

    Hi,

    Sorry but we are unable to replicate the issue at our end.

    Here in the following fiddle data is coming through a mock api using a fetch request.

    http://jsfiddle.net/uju2mq5c/

    Here are my implementation steps

    1). Bind a collection view to grid.

    2). Set trackChanges to true and added event listeners for collectionChanged event

    3). Changed the collection view’s source collection via a fetch request.

    4). Applied filter on grid and edited cell afterwards

    We are able to get the edited items view itemsEdited property of collectionView.

    Please let us know if there are any additional steps to replicate the show or modify the above fiddle to replicate the problem.

  • Posted 19 March 2018, 5:49 pm EST

    Hi Abhishek,

    I found a work around to achieve my requirement even though the itemsEdited property of collectionView is not reflecting any changes, the changes are there in the collectionView.sourceCollection.

    Is there any difference between the Grid.sourceCollection and CollectionView.sourceCollection. Do we have any property which holds the original data which was binded to the grid. For example in your example the data which was supplied by changeSourceAjax.

    Thank you,

    Rasika.

  • Posted 20 March 2018, 8:24 pm EST

    That’s great to know your problem’s solved.

    Here is the difference between the two:-

    collectionView.sourceCollection contains the original data(unchanged) which was used to construct the collection view.

    collectionView.items contains items in the view after filtering/sorting

    grid.itemsSource holds original data(array/collection view) which is used by the grid

    grid.collectionView points to the CollectionView which is used by the grid.All filtering/sorting is applied on this

  • Posted 23 March 2018, 1:07 am EST

    This means collectionView.sourceCollection contains the original data which remains unchanged even after adding/editing the grid. But in your example, when I am editing the grid, the changes get reflected in collectionView.sourceCollection (supposed to be unchanged). Due to which i am not able to get the original data which was binded to the grid before editing. Where can I find the original data after peforming grid edits? And is there a way to discard all changes in the grid?

  • Posted 25 March 2018, 10:07 pm EST

    Sorry for the confusion , but by unchanged I am referring to unfiltered/unsorted.

    Any edits/updates made to objects in data will be reflected.

    If you would like to get the original data then , you make a deep clone of data array before assigning it to grid.

    
    //refer to following code snippet
    
    //let the original data is in arr1, arr1=[{},{},{},{}];
    
    //make a deep copy of arr1
    
    var copyArr=[];
    
    arr1.forEach((item)=>{
    
    copyArr.push(Object.assign({},item));
    
    });
    
    //use copy data for grid source
    var cv=new wijmo.collections.CollectionView(copyArr);
    
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels