You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Carlos Rovira <ca...@apache.org> on 2020/12/21 21:36:46 UTC

Re: [Discuss] ArraySelectionModel sorting

Hi @Harbs,

about this problem. I got the time to go over it with some kind of success,
but was very time consuming.

The main problem is that Jewel ArraySelectionModel (and the rest of Basic
models) since all have this check:

public function set dataProvider(value:Object):void
{
if (value == _dataProvider) return;

when we update some info in one of the collection objects, this prevents
the collection to be refreshed.

I solved the notification problem we talked in this thread making
DataGridSort extends EasyDataProviderChangeNotifier as you suggested.
So, now collection.refresh() is working right and the code seems more
compliant with the rest of royale instead of the "sortChanged" I was using.
So we use COLLECTION_CHANGE (from collection.refresh()).

I also updated the notifier to use interfaces since our example uses
ArrayListView instead of ArrayList.

All collections I checked, including Basic and Jewel, had the previous
check. I solved creating in Jewel a method without the check:

public function setDataProvider__NoCheck(value:Object):void
{

that method is the same but with no "if (value == _dataProvider) return;"

So my question is: Do you think there's a better solution for this?

I committed an example with this working in the actual state in Tour De
Jewel in the following commit:

tour-de-jewel: add update example to datagrid from collection. check that
sorting columns refresh the grid.
Commit:ee70b51bcbfb53e7cd2e4bfacc3e7bf8897e8bc5 [ee70b51bc]Parents:
8835228669




Can you take a look to see if there's a better way to solve this?

Thanks in advance.

Carlos


El jue, 24 sept 2020 a las 23:23, Harbs (<ha...@gmail.com>) escribió:

> The data provider notifier listens to collectionChanged. There should be
> no need for additional sort-specific events.
>
> Look at DataProviderChangeNotifier.
>
> If you can’t figure it out, I can help you on Tuesday. I’m not available
> until then.
>
> > On Sep 24, 2020, at 11:30 PM, Carlos Rovira <ca...@apache.org>
> wrote:
> >
> > Hi Harbs,
> >
> > I think we are not listening for the "collectionChanged" event in
> DataGrid
> > beads (DataGridView).
> > Maybe I could add it (the same as I did with "sortedChanged", also the
> > other event could be a better name since it is more global and we can use
> > for filtering, and more).
> > But in doing that, I think I would need to still have a similar change to
> > ArraySelectionModel where we have a method that doesn't check if the
> > dataProvider is the same, since it will be in fact the same, but we need
> to
> > trigger the view refresh to show the sorting
> >
> > Hope I was able to explain it right.
> >
> > If you have time, you can revert my commit locally and try to do what you
> > have in mind and if that works commit the revert and the change. If not
> > I'll try it as I have time. I have many things on my plate now and also
> to
> > ApacheCon talks to prepare.
> >
> > thanks
> >
> >
> >
> > El jue., 24 sept. 2020 a las 18:42, Harbs (<ha...@gmail.com>)
> > escribió:
> >
> >> There must be something more subtle here.
> >>
> >> Without looking into your issue too deeply, I think the problem is that
> >> you’re not actually triggering an event.
> >>
> >> The dataProvider setter in ArraySelectionModel will not actually do
> >> anything unless you’re really changing the dataProvider.
> >>
> >> The solution would be to trigger a collectionChanged event in your
> >> collection when the array is sorted. You can do that by either setting
> >> collection.source = collection.source.slice() or a better solution (IMO)
> >> would be to simply: collection.dispatchEvent(new
> >> Event(“collectionChanged”));
> >>
> >> HTH,
> >> Harbs
> >>
> >>> On Sep 24, 2020, at 6:23 PM, Carlos Rovira <ca...@apache.org>
> >> wrote:
> >>>
> >>> Hi Harbs,
> >>>
> >>> I reverted locally my changes and tried this:
> >>>
> >>> <j:DataGrid localId="dg2" width="100%" height="100%"
> >>> dataProvider="{new ArrayListView(productModel.productList)}"
> >>> change="lb2.html = describeItem(event.target.selectedItem)">
> >>> <j:beads>
> >>> <j:DataGridColumnLabelsChange/>
> >>> <j:DataGridSort/>
> >>> <js:EasyDataProviderChangeNotifier/>
> >>> </j:beads>
> >>> <j:columns>
> >>> <j:DataGridColumn label="Title" dataField="title"/>
> >>> <j:DataGridColumn label="Sales" dataField="sales"/>
> >>> </j:columns>
> >>> </j:DataGrid>
> >>>
> >>>
> >>> In DataGridSort I changed final lines to this:
> >>>
> >>> // This way we can't refresh the columns since the dataProvider is the
> >> same
> >>> dg.model.dispatchEvent(new Event("dataProviderChanged"));
> >>> header.model.dispatchEvent(new Event("dataProviderChanged"));
> >>>
> >>> // dg.dataProvider = null;
> >>> // dg.dataProvider = collection;
> >>>
> >>> But this is not working.
> >>>
> >>> I think the use case is not the same since the notifier is checking for
> >> the
> >>> same object:
> >>>
> >>> if(object[propertyName] == dataProvider)
> >>> return;
> >>>
> >>> the problem I had is that the dataprovider is the same, but the order
> >> not,
> >>> so we need to "redraw" but without reassing again the provider and
> >> avoiding
> >>> to remove cells and recreate (what in the end has some more problems
> like
> >>> loosing selection and reset the scrolling).
> >>>
> >>> Maybe I'm using wrong? or what I'm exposing is ok?
> >>>
> >>> thanks
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> El mar., 22 sept. 2020 a las 9:53, Harbs (<ha...@gmail.com>)
> >> escribió:
> >>>
> >>>> This problem has been solved already with beads.
> >>>>
> >>>> Check out DataProviderChangeNotifier EasyDataProviderChangeNotifier.
> >>>>
> >>>>> On Sep 21, 2020, at 6:40 PM, Carlos Rovira <ca...@apache.org>
> >>>> wrote:
> >>>>>
> >>>>> Hi,
> >>>>>
> >>>>> I solved the problem with sorting in DataGrid (or List).
> >>>>>
> >>>>> The problem was: a sorted dataProvider is the same object,so making
> >>>>> "dataProvider = sortedDP" was stopped at the start of the method
> since
> >> as
> >>>>> usual we check if dataprovider is the same and in that case we
> return.
> >>>>>
> >>>>> The workaround was to do
> >>>>>
> >>>>> dataProvider = null;
> >>>>> dataProvider = oldDP;
> >>>>>
> >>>>> This had 2 problems:
> >>>>> 1.- if selection was in place, the selection was lost
> >>>>> 2.- if some scrolling was in place, the scrolling was lost.
> >>>>>
> >>>>> So my solution, was create a new "sortChanged" event
> >>>>>
> >>>>> 1.- in DataGridSort we dispatch the "sortChanged" instead of
> >>>>> "dataProviderChanged" (in fact that's what really happened, right?).
> >>>>> 2.- DataGridView now listen for "sortChanged" too (additionally to
> >>>>> "dataProviderChanged"), and we have a new handler that just propagate
> >> to
> >>>>> make each list to call "list.model.sortChangedHandler(dp);"
> >>>>> 3.- the shared model, ArraySelectionModel, decouple dataProvider
> setter
> >>>> to
> >>>>> extract the main functionality to "setDataProvider" and add
> >>>>> "sortChangeHandler" that avoid to check if dataProvider is the same
> as
> >>>>> before, so this time the refresh happen.
> >>>>>
> >>>>> The solution made the selection and the scrolling be persisted (if
> >> any),
> >>>> so
> >>>>> for now this solved the problems and seems (at least) to be a step
> >>>> forward.
> >>>>>
> >>>>> So my question: Do you think this solution is ok?
> >>>>> If so, maybe the event name should change to something that describes
> >>>>> things "wider", since this could be a "sort" a "filtering",....
> >>>>>
> >>>>> --
> >>>>> Carlos Rovira
> >>>>> http://about.me/carlosrovira
> >>>>
> >>>>
> >>>
> >>> --
> >>> Carlos Rovira
> >>> http://about.me/carlosrovira
> >>
> >>
> >
> > --
> > Carlos Rovira
> > http://about.me/carlosrovira
>
>