lidorsystems / integralui-web-angular

IntegralUI Web - Advanced UI Components for Angular 9
https://www.lidorsystems.com/products/web/studio/
Other
10 stars 8 forks source link

'selectionChanged' event is not triggered as expected when remove selected items from data source directly. #10

Closed mm-ryo closed 4 years ago

mm-ryo commented 4 years ago

Steps:

  1. bind a data source to Treeview or load data from backend service. this.treeview.loadData(......)
  2. make a call to select items this.treeview.selectItems([items to be selected]);
  3. remove the selected items from the data source.
    var arrary_data = this.treeView.getFullList(); update this arrary by slice() splice() or

        const fullList = this.treeView.getFullList();
        const entity = fullList.find(x => x.id=== 1);
    
        if (!entity) {
          return;
        }
    
        entity.hasChildren = false;
        entity.items = [];
  4. make a call to update the layout this.treeview.updateLayout();

expected: the selection changed event should be fired. actual: Treeview didn't fire selection changed event

Lidor-Systems commented 4 years ago

The slice method can remove objects from an array, but doesn't change the original array.

Nevertheless, the list returned from the getFullList method is a linear list of all items in tree hierarchy. It is created whenever TreeView layout is updated. This is different then the data source that is applied to the TreeView, either through items property or using the loadData method. So any changes to this list is ignored, it will not affect the original list. Using it you can only change the object properties. Changes to an object from this list are also reflected back to the data source, because it is the same object.

Mainly the getFullList method is useful when you want to cycle though all tree items (using linear list instead of going through a tree hierarchy is better for performance) and change item objects or use it in some other way.

If you remove a selected item from a data source, this also will not trigger the selectionChanged event, because there is no tracking on objects from a data source.

As a solution, you can use the removeItem method. This should trigger the selectionChanged event, if the item was selected. However, upon checking the code, in current version there is a bug that prevents selectionChanged event to fire in this case.

We have located the problem and now it is fixed. So, in future in order for this event to fire, you need to use the removeItem method. The fix will be included in coming update on 17 Dec 2019.

If you are a customer and you need a fixed version sooner, please let us know at support@lidorsystems.com.

mm-ryo commented 4 years ago

The slice method can remove objects from an array, but doesn't change the original array.

Nevertheless, the list returned from the getFullList method is a linear list of all items in tree hierarchy. It is created whenever TreeView layout is updated. This is different then the data source that is applied to the TreeView, either through items property or using the loadData method. So any changes to this list is ignored, it will not affect the original list. Using it you can only change the object properties. Changes to an object from this list are also reflected back to the data source, because it is the same object.

Mainly the getFullList method is useful when you want to cycle though all tree items (using linear list instead of going through a tree hierarchy is better for performance) and change item objects or use it in some other way.

If you remove a selected item from a data source, this also will not trigger the selectionChanged event, because there is no tracking on objects from a data source.

As a solution, you can use the removeItem method. This should trigger the selectionChanged event, if the item was selected. However, upon checking the code, in current version there is a bug that prevents selectionChanged event to fire in this case.

We have located the problem and now it is fixed. So, in future in order for this event to fire, you need to use the removeItem method. The fix will be included in coming update on 17 Dec 2019.

If you are a customer and you need a fixed version sooner, please let us know at support@lidorsystems.com.

thanks for your reply. Yes, we have the purchased license, but the solution is not what we want actually. And what I want is when I call "updateLayout" function, Could you first have a check for selected items whether they are still in the data source? if not then raise the 'selectionChanged' event. I have updated steps 3 and put a piece of sample codes there, please take a look at it again. thanks.

Lidor-Systems commented 4 years ago

In your code, removing the child items from the data source will also remove them from the TreeView when it is updated, via call to updateLayout method.

Yes, we can add a code that will check if current selection were somehow changed from outside, by removing a set of items (like in your code). If this is true, then the selectionChanged event will be fired, when layout is updated.

We will make sure this is included in coming update.