Thursday, June 2, 2011

Re: Update data provider list in a celltable after a search

I think you're almost there. It looks like you're trying to use a
ListDataProvider, but you're also calling setRowCount() and
setRowData() which you don't need to do when using a ListDataProvider.

In terms of sorting, your ListHandler is configured to act on the same
list that the ListDataProvider uses, which is what I've found to work.
The trick comes when updating the list being displayed. You can't just
call ListDataProvider.setList() because there's no setList() on
ListHandler (I have no idea why not). Instead, you have to call
ListDataProvider.getList().clear;
ListDataProvider.getList().addAll(newData);

Finally, be sure to call CellTable.getColumnSortList().push(column)
when updating the data to reflect the initial sort order of the data.

I'm only just figuring all of this out myself, so if this doesn't work
or if anyone has other suggestions, please let me know.

-Brian

On May 15, 3:33 pm, Celinio <cel...@gmail.com> wrote:
> hey,
> i'm thinking that i might need to proceed differently since what i want is
> to display new data.
>
> http://code.google.com/webtoolkit/doc/latest/DevGuideUiCellWidgets.html
>
> Do i need to create a subclass of
> AsyncDataProvider<http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/googl...>and
> implement
> onRangeChanged(HasData)<http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/googl...>?
>
> Any ideas ?
>
> Thanks for helping.
>
>
>
>
>
>
>
> On Sat, May 14, 2011 at 11:31 PM, Celinio <cel...@gmail.com> wrote:
> > Hi,
> > I have this app where the user arrives to a page where at the top there is
> > a search panel with several textboxes (search criterias).
> > At the bottom of the page there is a celltable which displays the search
> > results.
> > The first time the user arrives to the page, the celltable is filled with
> > rows from an initial search. So let's say the initial search gives 14 rows.
> > Then the user performs a research. The celltable is then updated with the
> > search results. Let's say that returns 2 rows.
> > The problem is that if the user attempts to SORT the columns, then the
> > celltable displays 10 rows (PAGE_SIZE) and i can see that the rows come from
>
> > the initial search.
>
> > I use MVP so here is the code for the VIEW and the PRESENTER.
> > In the presenter, the method being called to perform the search is
> > onRechercheClicked(...).
>
> > As you can see in the PRESENTER, i use the demandeTable.setRowData(0,
> > demandes); method to add the list.
>
> > Does anyone have any idea ?
> > Thanks for helping.
>
> > Code for the view :
>
> >    1. package com.ft.v.gestion.presentation.client.mvp.view.impl;
> >    2.
> >    3. import java.util.ArrayList;
> >    4. import java.util.Comparator;
> >    5. import java.util.Date;
> >    6. import java.util.HashMap;
> >    7. import java.util.List;
> >    8. import java.util.Map;
> >    9.
> >    10. import com.ft.voltage.demande.model.DemandeBean;
> >    11. import com.ft.v.gestion.presentation.client.GwtApplication;
> >    12. import
> >    com.ft.v.gestion.presentation.client.mvp.presenter.ListPresenter;
> >    13. import com.ft.v.gestion.presentation.client.mvp.view.ListView;
> >    14. import com.ft.v.gestion.presentation.client.ui.RecherchePanel;
> >    15. import com.ft.v.gestion.presentation.client.ui.SimpleHasFeedback;
> >    16. import com.google.gwt.cell.client.ClickableTextCell;
> >    17. import com.google.gwt.cell.client.FieldUpdater;
> >    18. import com.google.gwt.core.client.GWT;
> >    19. import com.google.gwt.event.dom.client.ClickEvent;
> >    20. import com.google.gwt.event.dom.client.ClickHandler;
> >    21. import com.google.gwt.i18n.client.DateTimeFormat;
> >    22. import com.google.gwt.safehtml.shared.SafeHtml;
> >    23. import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
> >    24. import com.google.gwt.text.shared.AbstractSafeHtmlRenderer;
> >    25. import com.google.gwt.text.shared.SafeHtmlRenderer;
> >    26. import com.google.gwt.user.cellview.client.CellTable;
> >    27. import com.google.gwt.user.cellview.client.Column;
> >    28. import
> >    com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
> >    29. import com.google.gwt.user.cellview.client.SimplePager;
> >    30. import com.google.gwt.user.cellview.client.SimplePager.TextLocation
> >    ;
> >    31. import com.google.gwt.user.cellview.client.TextColumn;
> >    32. import com.google.gwt.user.client.ui.Composite;
> >    33. import com.google.gwt.user.client.ui.FlowPanel;
> >    34. import com.google.gwt.user.client.ui.HTML;
> >    35. import com.google.gwt.user.client.ui.ScrollPanel;
> >    36. import com.google.gwt.user.client.ui.Widget;
> >    37. import com.google.gwt.view.client.ListDataProvider;
> >    38. import com.google.gwt.view.client.Range;
> >    39. import com.google.gwt.view.client.RangeChangeEvent;
> >    40. import com.google.gwt.view.client.RangeChangeEvent.Handler;
> >    41.
> >    42. public class DemandesListViewImpl extends Composite implementsListView
> >    <DemandeBean> {
> >    43.
> >    44.         private RecherchePanel recherchePanel = new RecherchePanel(
> >    );
> >    45.
> >    46.
> >    47.         private final CellTable<DemandeBean> demandeTable;
> >    48.         private final SimplePager pager;
> >    49.         private final static int PAGE_SIZE = 10;
> >    50.         private List<DemandeBean> demandes;
> >    51.         private SimpleHasFeedback feedback;
> >    52.
> >    53.         private Boolean afficherCelltable = false;
> >    54.
> >    55.
> >    56.         private ListPresenter<DemandeBean> presenter;
> >    57.
> >    58.         public DemandesListViewImpl() {
> >    59.
> >    60.                 recherchePanel.boutonRechercher.addClickHandler(newClickHandler
> >    ()
> >    61.                 {
> >    62.
> >    63.                         public void onClick(ClickEvent event)
> >    64.                         {
> >    65.                                 //Window.alert("blabla " +
> >    rp.tb6.getText());
> >    66.                                 String critere_Media =recherchePanel.
> >    tb6.getText();
> >    67.                                 String critere_Urgence =recherchePanel.
> >    tb7.getText();
> >    68.
> >    69.                                 Map<String, Object> criteres = newHashMap
> >    <String, Object>();
> >    70.                                 criteres.put("critereMedia",
> >    critere_Media);
> >    71.                                 criteres.put("critereUrgence",
> >    critere_Urgence);
> >    72.
> >    73.                                 if (presenter != null) {
> >    74.                                         GWT.log("Presenter n'est
> >    pas nul");
> >    75.                                         presenter.
> >    onRechercheClicked(criteres);
> >    76.                                 }
> >    77.                         }
> >    78.                  });
> >    79.
> >    80.                 GWT.log("Entree dans DemandesListViewImpl()");
> >    81.
> >    82.                 feedback = new SimpleHasFeedback();
> >    83.                 demandeTable = new CellTable<DemandeBean>();
> >    84.                 demandeTable.getElement().setId("demandeliste");
> >    85.                 demandeTable.setPageSize(PAGE_SIZE);
> >    86.                 demandeTable.setRowCount(0, true);
> >    87.
> >    88.                 demandeTable.addRangeChangeHandler(new Handler() {
> >    89.
> >    90.                         public void onRangeChange(RangeChangeEvent
> >    event) {
> >    91.                                 GWT.log("Dans  onRangeChange");
> >    92.                                 Range range = demandeTable.
> >    getVisibleRange();
> >    93.                                 int start = range.getStart();
> >    94.                                 int length = range.getLength();
> >    95.                                 List<DemandeBean> toSet = newArrayList
> >    <DemandeBean>(length);
> >    96.                                 GWT.log("addRangeChangeHandler :
> >    taille demandes vaut : " + demandes.size());
> >    97.                                 for (int i = start; i < start +length
> >    && i < demandes.size(); i++)
> >    98.                                         toSet.add(demandes.get(i));
> >    99.                                 demandeTable.setRowData(start,
> >    toSet);
> >    100.                         }
> >    101.                 });
> >    102.
> >    103.                 // Create a Pager to control the table.
> >    104.                 SimplePager.Resources pagerResources = GWT
> >    105.                                 .create(SimplePager.Resources.
> >    class);
> >    106.                 pager = new SimplePager(TextLocation.CENTER,
> >    pagerResources, false, 0,
> >    107.                                 true);
> >    108.                 pager.setDisplay(demandeTable);
> >    109.
> >    110.                 // renderer for nameColumn
> >    111.                 SafeHtmlRenderer<String> nameColumnRenderer = newAbstractSafeHtmlRenderer
> >    <String>() {
> >    112.
> >    113.                         public SafeHtml render(String object) {
> >    114.                                 // FIXME voir si il est possible
> >    de supprimer ce code HTML
> >    115.                                 SafeHtmlBuilder builder = newSafeHtmlBuilder
> >    ();
> >    116.                                 builder.appendHtmlConstant("<a>");
> >    117.                                 builder.appendEscaped(object);
> >    118.                                 builder.appendHtmlConstant("</a>")
> >    ;
> >    119.                                 return builder.toSafeHtml();
> >    120.                         }
> >    121.                 };
> >    122.
> >    123.
> >    124.
> >    125.                 initWidget(getDisplay());
> >    126.         }
> >    127.
> >    128.         private Widget getDisplay() {
> >    129.
> >    130.                 GWT.log("appel de getDisplay()" );
> >    131.
> >    132.                 // main panel is content panel
> >    133.
> >    134.                 // content panel configuration
> >    135.                 FlowPanel content = new FlowPanel();
> >    136.                 content.getElement().setId("content");
> >    137.                 content.add(new HTML("<center><h2>"
> >    138.                                 + GwtApplication.constantes.
> >    corbeilleDemandes_title() + "</h2></center>"));
> >    139.
> >    140.
> >    141.                 content.add(recherchePanel);
> >    142.                 content.add(new HTML("<h4>"     + GwtApplication.
> >    constantes.marketPage_result() + "</h4>"));
> >    143.                 content.add(feedback);
> >    144.                 ScrollPanel sp = new ScrollPanel();
> >    145.                 sp.setSize("800px", "200px");
> >    146.
> >    147.                 sp.add(demandeTable);
> >    148.                 content.add(sp);
> >    149.
> >    150.                 content.add(pager);
> >    151.                 content.setWidth("100%");
> >    152.
> >    153.                 return content;
> >    154.         }
> >    155.
> >    156.         public void
>
> ...
>
> read more »

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment