Search code examples
gridgxt

Gxt Rpc Grid called to client and used as local grid


I have an ArrayList in my server I want to display it in a grid at client side. I am using RPC Mechanism for this purpose. The RPC call was successful but while am adding pagination it did not work. If have not done this in a proper way please guide me to do this correctly.

I just took the ArrayList to client and then added to grid. I thought that this is causing problems .

Here is my code:

    ArrayList valls=new ArrayList();
    public ContentPanel mainPanel1 = new ContentPanel();
    public PagingToolBar toolBar = new PagingToolBar(10);  
    public ContentPanel cpc=new ContentPanel();

    public ContentPanel mainPanel = new ContentPanel(); 
    public ContentPanel cp = new ContentPanel();
    public ListStore<BeanModelType> clientList=new ListStore<BeanModelType>();

    public ListStore<BeanModelType>  createGrid()
    {

    System.out.print("METHOD DDDDDDDDD");
    final FeedServiceAsync feedService =Registry.get(RSSReaderConstants.FEED_SERVICE);

    feedService.createNewFeed(new AsyncCallback<Feed>() {

        @Override
        public void onFailure(Throwable caught) 
        {
            // TODO Auto-generated method stub
            Info.display("RSSReader", "Unable to create a new feed");
            System.out.print("ERRORRRRRR");
        }
        @Override
        public void onSuccess(Feed result)
        {   
           ArrayList valls=result.getVal();     
           PagingModelMemoryProxy proxy = new PagingModelMemoryProxy(TestData.getClients(result.getVal()));  
           PagingLoader loader = new BasePagingLoader(proxy);  
           loader.setRemoteSort(true);  

               /*    

               final PagingToolBar toolBar = new PagingToolBar(5);  
               toolBar.bind(loader);  
               loader.load(0, 5);  

               */
               clientList.add(TestData.getClients(valls)); 

               /*
                * if we remove the above code only shows the  pagination not the content value 
                * 
                * Actual code shoiuld be like this 
                * 
                * 
                *clientList= new ListStore<BeanModelType>(loader);
                * 
                * returns clientList;
                * 
                * 
                * but int his method its not working sirrrr aM SORRY TO SAY THIS
                * 
                * 
                */

               clientList = new ListStore<BeanModelType>(loader); 
               toolBar.bind(loader);  
               loader.load(0, 10);  
               loader.setRemoteSort(true);

        }
    });

return clientList;

}
 /*
==============================================================================
code for grid
=====================================================================================*/
 /*
         * 
         * Grid Starts
         * 
         */ 
               List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

                    ColumnConfig column = new ColumnConfig();    
                    column.setId("name");    
                    column.setHeader("CLIENT");    
                    column.setWidth(200);    
                    configs.add(column); 
                    column = new ColumnConfig("name1", "CAMPAIGN", 150);  
                    column.setAlignment(HorizontalAlignment.LEFT);  
                    configs.add(column); 

                     column = new ColumnConfig("name2", "SITE", 100);  
                     column.setAlignment(HorizontalAlignment.LEFT);  
                     configs.add(column); 

                     column = new ColumnConfig("name3", "ADUNIT", 100);  
                     column.setAlignment(HorizontalAlignment.LEFT);  
                     configs.add(column); 

                     column = new ColumnConfig("name4", "START", 100);  
                     column.setAlignment(HorizontalAlignment.LEFT);  
                     configs.add(column); 



                    ColumnModel cm = new ColumnModel(configs);  
                    Grid<BeanModelType> grid = new Grid<BeanModelType>(createGrid(), cm);   
                    grid.setStyleAttribute("borderTop", "none");   
                    grid.setAutoExpandColumn("name"); 
                    grid.setAutoExpandColumn("name1");   
                    grid.setAutoExpandColumn("name2");   
                    grid.setAutoExpandColumn("name3");   
                    grid.setAutoExpandColumn("name4");   
                    grid.setBorders(true); 
                    grid.setStripeRows(true); 
                    //grid.getView().setAutoFill(true);
                    //grid.setAutoWidth(true);

                    cp.setBodyBorder(false);   
                    cp.setHeading("Employee List");    
                    cp.setButtonAlign(HorizontalAlignment.CENTER);
                    cp.setSize(1440,609);   
                    cp.setFrame(true);
                    cp.setAnimCollapse(false);
                    cp.setLayout(new FillLayout(Orientation.VERTICAL));
                    cp.setBottomComponent(toolBar);
                    cp.add(grid);
                    cp.setSize("", "370");

                    mainPanel.add(cp);


            /* 
             * 
             *  End Of Grid
             * 
             *
             * 
             * 
             */ 

Solution

  • You cant do that. feedService.createNewFeed is Async process. What you had return on createGrid method is an empty clientList. reconfigure the grid inside onSuccess method

    public void onSuccess(Feed result){
    .... 
    clientList = new ListStore<BeanModelType>(loader); 
    toolBar.bind(loader);  
    loader.setRemoteSort(true);
    grid.reconfigure(clientList, grid.getColumnModel());
    }