Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    filtering TreeGrid and changing properties in a DataSource-Record

    The following code is available...

    Code:
    SelectionChangedHandler statesChangeHandler = new SelectionChangedHandler() {
                public void onSelectionChanged(SelectionEvent event) {
                    if(!noChange) {
                        ListGridRecord record = event.getRecord();
                        Boolean value = event.getState();
                        record.setAttribute("state", value);
                        record.setAttribute("changed", true);
                        mlTreeGrid.updateData(record);
                        }
                    }
                }
            };
    ......
            mlTreeGrid = new TreeGrid();
    ......
            mlTreeGrid.addSelectionChangedHandler(statesChangeHandler);
    So if I filter TreeGrid and select a record, the record properties "state" and "changed" do not change in the DataSource.
    How do I make changes to DataSource records?

    SmartClient Version SNAPSHOT_v12.1d_2019-12-11

    #2
    updateData(), whether called on a TreeGrid that has a DataSource or directly on a DataSource, is the correct way to update DataSource records. You will see a request in the RPC tab of the Developer Console and can see whether it succeeds or fails. If you don't see this, perhaps your TreeGrid doesn't have a DataSource.

    Note that your code is subtly wrong: you need to make a copy of the record, then pass that to updateData(). Otherwise you have already changed the record in the TreeGrid's cache, and it will be changed regardless of whether the DataSource operation succeeds.

    Comment


      #3
      Your remark that the entry changes in the TreeGrid cache is only half true. The problem is the entry received in the statesChangeHandler code
      Code:
      ListGridRecord record = event.getRecord();
      it is a copy of the record from the DataSource.
      and if I change the properties in this record, the copy of the record in the DataSource remains intact. I checked this in the developer console adding a line to my code
      Code:
      Record [] records = mlTreeGrid.getDataSource().getCacheData();
      For this reason, I used the updateData () function in the DataSource from TreeGrid.
      Code:
      mlTreeGrid.getDataSource().updateData(record);
      She synced the recordings and everything was just fine. I haven't filtered TreeGrid yet. But filtering led to a catastrophic error that I noticed only today. After filtering, updateData () resulted in the loss of child nodes in the tree.
      This can be seen in the screenshots below.

      Non-filtered tree
      Click image for larger version  Name:	shot1.jpg Views:	0 Size:	29.3 KB ID:	261015

      filter tree
      Click image for larger version  Name:	shot2.jpg Views:	0 Size:	20.8 KB ID:	261016

      filter tree after changing properties and executing mlTreeGrid.getDataSource().updateData(record);

      Click image for larger version  Name:	shot3.jpg Views:	0 Size:	19.8 KB ID:	261017
      remove the filter in the tree and see the following
      Click image for larger version  Name:	shot4.jpg Views:	0 Size:	26.1 KB ID:	261018

      We see that 2 child nodes in class2 have disappeared irrevocably.

      So I had a problem...
      How do I change properties in a DataSource record if I only have a copy of the record from the DataSource in the onSelectionChanged function?
      Last edited by Hirn; 6 Feb 2020, 05:12.

      Comment


        #4
        Using TreeGrid.updateData() or DataSource.updateData() does not normally result in loss of nodes, as can be readily seen with minor modifications to our samples.

        We don't know how you broke your tree, but we can't troubleshoot screenshots. If you think there's actually a framework bug here, we need a minimal, ready-to-run test case showing the problem.

        We would also recommend another read of the Tree DataBinding overview.

        Comment


          #5
          Using TreeGrid.updateData() or DataSource.updateData() does not normally result in loss of nodes,
          If you work with a non-filtered tree, I fully agree with you. But when the tree is filtered then the DataSource.updateData () results in the loss of nodes.

          I will try to make a short workable example today where this error is displayed.

          Comment


            #6
            No, filtered or not filtered, this does not happen if you simply modify Showcase examples.

            Comment

            Working...
            X