1. #1
    Sencha User
    Join Date
    Oct 2008
    Posts
    3
    Vote Rating
    0
    everhow@163.com is on a distinguished road

      0  

    Default Unanswered: How can I use HttpProxy to Paing grid with gxt 3.0

    Unanswered: How can I use HttpProxy to Paing grid with gxt 3.0


    How can I use HttpProxy to Paing grid, any idea?

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,639
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    Start with the ideas in the paging grid example (which uses a grid, paging toolbar, and binds them to a ListStore and PagingLoader), and then wire the loader into an HttpProxy. The advanced combobox example shows how to use ScriptTagProxy, which has an API very similar to HttpProxy, but loads its data in a different way.


    http://sencha.com/examples-dev/#ExamplePlace:paginggrid
    http://sencha.com/examples-dev/#ExamplePlace:advancedcombobox


    The basic idea when using these tools is that the Store and Loader should be used by your own application code and widgets, and the Loader should itself know about the DataReader and DataProxy, to see how it will load the data. At each level, these pieces should be interchangable - a Loader can work with any DataProxy (and possibly a DataReader) that can pull in the right kind of data for it, and then the PagingToolbar just needs to talk to the right kind of Loader.

  3. #3
    Sencha User
    Join Date
    Jan 2011
    Location
    Lima, Peru
    Posts
    43
    Answers
    5
    Vote Rating
    4
    poseidonjm is on a distinguished road

      1  

    Default


    I extend HttpProxy and I added two helper methods like requestfactory
    Code:
    public interface MyAutoBeanFactory extends AutoBeanFactory {
    
         AutoBean<FilterPagingLoadConfig> loadConfig();
            
         AutoBean<SortInfo> getSortInfo();
            
         AutoBean<FilterConfig> getFilterConfig();
    }
    The class
    Code:
    public class MyHttpProxy<C> extends HttpProxy<C> {
    
        public MyHttpProxy(RequestBuilder builder) {
            super(builder);
        }
        
        protected List<SortInfo> createRequestSortInfo(MyAutoBeanFactory factory, List<? extends SortInfo> original) {
            List<SortInfo> sortInfo = new ArrayList<SortInfo>();
            
            for (int i = 0; i < original.size(); i++) {
              SortInfo originalSortInfo = original.get(i);
              SortInfo reqSortInfo = factory.getSortInfo().as();
              reqSortInfo.setSortDir(originalSortInfo.getSortDir());
              reqSortInfo.setSortField(originalSortInfo.getSortField());
              sortInfo.add(reqSortInfo);
            }
            
            return sortInfo;
          }
          
          
          protected List<FilterConfig> createRequestFilterConfig(MyAutoBeanFactory factory, List<? extends FilterConfig> original) {
            List<FilterConfig> sortInfo = new ArrayList<FilterConfig>();
            
            for (int i = 0; i < original.size(); i++) {
              FilterConfig originalSortInfo = original.get(i);
              FilterConfig reqSortInfo = factory.getFilterConfig().as();
              
              reqSortInfo.setComparison(originalSortInfo.getComparison());
              reqSortInfo.setField(originalSortInfo.getField());
              reqSortInfo.setType(originalSortInfo.getType());
              reqSortInfo.setValue(originalSortInfo.getValue());
              
              sortInfo.add(reqSortInfo);
            }
            
            return sortInfo;
          }
    
    
    }
    Example

    Code:
    public interface UserProxy {    String getFirst();
        void setFirst(String first);
        String getLast();
        void setLast(String last);
        String getLogin();
        void setLogin(String login);
        Long getId();
        void setId(Long id);
    }
    Code:
    public interface UserListProxy { 
       List<UserProxy> getData();
        int getTotalCount();
    }
    Code:
    public class UserJsonReader extends JsonReader<PagingLoadResult<UserProxy>, UserListProxy> {    
        public UserJsonReader(AutoBeanFactory factory,
                Class<UserListProxy> rootBeanType) {
            super(factory, rootBeanType);
        }
        
        @Override
        protected PagingLoadResult<UserProxy> createReturnData(Object loadConfig, UserListProxy incomingData) {
            FilterPagingLoadConfig pagingLoadConfig = (FilterPagingLoadConfig)loadConfig;
            
          return new PagingLoadResultBean<UserProxy>(incomingData.getData(), incomingData.getTotalCount(), pagingLoadConfig.getOffset());
        }
    
    
    }
    Code:
    public interface AppAutoBeanFactory extends MyAutoBeanFactory { 
       AutoBean<UserListProxy> users();   
    }
    Code:
    final AppAutoBeanFactory factory = GWT.create(AppAutoBeanFactory.class);         
            UserJsonReader reader = new UserJsonReader(factory, UserListProxy.class);
         
            String path = "users/users.php";
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, path);
            MyHttpProxy<FilterPagingLoadConfig> proxy = new MyHttpProxy<FilterPagingLoadConfig>(builder){
                @Override
                public void load(FilterPagingLoadConfig loadConfig,
                        Callback<String, Throwable> callback) {
                    
                    List<SortInfo> sortInfo = createRequestSortInfo(factory, loadConfig.getSortInfo());
                    
                    List<FilterConfig> filterConfig = createRequestFilterConfig(factory, loadConfig.getFilters());
                    
                    loadConfig.setSortInfo(sortInfo);
                    loadConfig.setFilters(filterConfig);
                                    
                    super.load(loadConfig, callback);
                }
            };
            //proxy.setWriter(new UrlEncodingWriter<FilterPagingLoadConfig>(factory, FilterPagingLoadConfig.class));
            proxy.setWriter(new JsonWriter<FilterPagingLoadConfig>(factory, FilterPagingLoadConfig.class));
            
            loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<UserProxy>>(proxy, reader){
                @Override
                protected FilterPagingLoadConfig newLoadConfig() {
                    return new FilterPagingLoadConfigBean();
                }
            };
            
            loader.setRemoteSort(true);
            loader.useLoadConfig(factory.loadConfig().as());
                    
            UserProxyProperties props = GWT.create(UserProxyProperties.class);
            
            store = new ListStore<UserProxy>(props.id());
            loader.addLoadHandler(new LoadResultListStoreBinding<FilterPagingLoadConfig, UserProxy, PagingLoadResult<UserProxy>>(store));
    I pasted only the relevant code.
    The helper methods of MyHttpProxy is used because AutoBeans cannot send List
    http://stackoverflow.com/questions/1...n-autobean-gwt

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar