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 (<[email protected]>)
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 <[email protected]>
> 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 (<[email protected]>)
> escribió:
> >
> >> This problem has been solved already with beads.
> >>
> >> Check out DataProviderChangeNotifier EasyDataProviderChangeNotifier.
> >>
> >>> On Sep 21, 2020, at 6:40 PM, Carlos Rovira <[email protected]>
> >> 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

Reply via email to