Results 1 to 6 of 6

Thread: how to get the child for the gxt3 TreeGrid

  1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    27
    Answers
    1

    Default how to get the child for the gxt3 TreeGrid

    how to get the child from the server.
    and the data is json data.
    but i can't get the child
    i guess the it like the Tree


    private TreeLoader<JsonData> createTreeLoader(){
    JsonGridAutoBeanFactory factory = GWT.create(JsonGridAutoBeanFactory.class);
    DataRecordJsonReader reader = new DataRecordJsonReader(factory, JSonDataRecordResult.class);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, URL_OF_ROLE_LIST);
    HttpProxy<JsonData> jsonProxy = new HttpProxy<JsonData>(requestBuilder){
    @Override
    public void load(JsonData loadConfig, Callback<String, Throwable> callback) {
    // if(null!=loadConfig&&null!=loadConfig.getId())


    }


    @Override
    protected String generateUrl(JsonData loadConfig) {
    return (null!=loadConfig&&null!=loadConfig.getId())?"id=".concat(loadConfig.getId().toString()):"";
    }
    };


    jsonProxy.setWriter(new UrlEncodingWriter<JsonData>(factory, JsonData.class));
    final TreeLoader<JsonData> loader = new TreeLoader<JsonData>(jsonProxy, reader) {
    @Override
    protected JsonData newLoadConfig() {


    return super.newLoadConfig(); //To change body of overridden methods use File | Settings | File Templates.
    }


    @Override
    public boolean hasChildren(JsonData parent) {


    return parent.getParent();
    }
    };


    loader.addLoadHandler(new ChildTreeStoreBinding<JsonData>(store));


    return loader;
    }

  2. #2
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737
    Answers
    109

    Default

    Are you asking how to give an item to the server and have it return the children of that item? Isn't that entirely dependent on how your server code is written?

    If you just want to know how to ask the TreeGrid for the parent of an item, that's pretty easy - ask the TreeGrid for its TreeStore, and ask the store for the parent of the item using the getParent method.

  3. #3
    Sencha User
    Join Date
    Dec 2012
    Posts
    27
    Answers
    1

    Default

    yes,my means is that i want to get the child ,but the loader only connect the url one time.
    i guess it should like the Tree when the parent node expanded then connected the url and send the parameter of the parent node id(in database the id is the child root)
    i don't want to write the ajax method to get the data and like the give examples:


    service.getFolderChildren(loadConfig, callback);(http://www.sencha.com/examples/#Exam...:asynctreegrid)
    use the loader or store some method can do ?


    at the same time i ask a question about the desktop .when i have many shortcuts( more than 15) add them on the desktop, and it show on the desktop as line ,but some can't show,how to do let the shortcuts Automatic Branch

  4. #4
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737
    Answers
    109

    Default

    The async tree grid example is requesting each time something expands because that is what it is configured to do. Without seeing your code, I can't say what you are doing that prevents it from doing this.

    Please provide some code samples to make it clearer what you are already doing and what you are asking.

  5. #5
    Sencha User
    Join Date
    Dec 2012
    Posts
    27
    Answers
    1

    Default

    public class AsyncTreeGridExample implements IsWidget, EntryPoint {
    private final String URL_OF_PERMISSION_CLIENT = Const.SERVER + "permission!listClient.do";
    interface TreeBundle extends ClientBundle {
    ImageResource plus();
    ImageResource minus();
    ImageResource folder();
    ImageResource folderOpen();
    }


    public interface FileModelProperties extends PropertyAccess<JsonData> {
    @Editor.Path("id")
    ModelKeyProvider<JsonData> key();


    ValueProvider<JsonData, String> id();


    ValueProvider<JsonData, String> name();


    ValueProvider<JsonData, String> parent();
    }
    interface JsonData {
    public String getId();


    public String getName();


    public String getParent();


    }
    @Override
    public void onModuleLoad() {
    RootPanel.get().add(this);
    }


    @Override
    public Widget asWidget() {
    IdentityValueProvider<JsonData> identity = new IdentityValueProvider<JsonData>();
    final CheckBoxSelectionModel<JsonData> sm = new CheckBoxSelectionModel<JsonData>(identity){
    @Override
    public boolean isSelectAllChecked() {
    return super.isSelectAllChecked(); //To change body of overridden methods use File | Settings | File Templates.
    }
    };
    sm.addSelectionChangedHandler(new SelectionChangedEvent.SelectionChangedHandler<JsonData>() {
    @Override
    public void onSelectionChanged(SelectionChangedEvent<JsonData> jsonDataSelectionChangedEvent) {
    sm.getSelectedItems();
    }
    }) ;
    sm.addSelectionHandler(new SelectionHandler<JsonData>() {
    @Override
    public void onSelection(SelectionEvent<JsonData> jsonDataSelectionEvent) {
    sm.getSelectedItems();
    }
    });
    TreeStore<JsonData> store=createStore();
    final JsonTreeAutoBeanFactory factory = GWT.create(JsonTreeAutoBeanFactory.class);
    DataRecordJsonReader reader = new DataRecordJsonReader(factory, JSonDataRecordResult.class);


    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, URL_OF_PERMISSION_CLIENT);
    HttpProxy<JsonData> jsonProxy = new HttpProxy<JsonData>(requestBuilder) {


    };
    jsonProxy.setWriter(new UrlEncodingWriter<JsonData>(factory, JsonData.class));
    final TreeLoader<JsonData> loader = new TreeLoader<JsonData>(jsonProxy, reader) {
    @Override
    public boolean hasChildren(JsonData parent) {


    return (null != parent.getParent() && "true".equals(parent.getParent()));
    }
    };
    loader.addLoadHandler(new ChildTreeStoreBinding<JsonData>(store));










    FileModelProperties props = GWT.create(FileModelProperties.class);


    ColumnConfig<JsonData, String> id = new ColumnConfig<JsonData, String>(props.id(), 50, "ID");
    ColumnConfig<JsonData, String> name = new ColumnConfig<JsonData, String>(props.name(), 400, "name");






    List<ColumnConfig<JsonData, ?>> l = new ArrayList<ColumnConfig<JsonData, ?>>();
    l.add(sm.getColumn()) ;


    l.add(id);
    l.add(name);


    ColumnModel<JsonData> cm = new ColumnModel<JsonData>(l);






    FramedPanel cp = new FramedPanel() {
    @Override
    protected void onAfterFirstAttach() {
    super.onAfterFirstAttach();
    loader.load();
    }
    };
    cp.setHeadingText("Async TreeGrid");
    cp.setButtonAlign(BoxLayoutPack.CENTER);
    cp.setPixelSize(600, 300);
    // cp.addStyleName("margin-10");


    TreeGrid<JsonData> tree = new TreeGrid<JsonData>(store, cm, l.get(1));
    tree.setBorders(true);
    tree.setTreeLoader(loader);
    tree.getView().setTrackMouseOver(false);
    tree.getView().setAutoExpandColumn(name);
    tree.setSelectionModel(sm);
    // tree.getStyle().setJointCloseIcon(bundle.plus());
    // tree.getStyle().setJointOpenIcon(bundle.minus());
    // tree.getStyle().setNodeCloseIcon(bundle.folder());
    // tree.getStyle().setNodeOpenIcon(bundle.folderOpen());
    cp.setWidget(tree);


    return cp;
    }
    public interface JsonTreeAutoBeanFactory extends AutoBeanFactory {
    AutoBean<JSonDataRecordResult> items();
    }
    interface JSonDataRecordResult {
    public List<JsonData> getRecords();
    }
    class DataRecordJsonReader extends JsonReader<List<JsonData>, JSonDataRecordResult> {
    public DataRecordJsonReader(AutoBeanFactory factory, Class<JSonDataRecordResult> rootBeanType) {
    super(factory, rootBeanType);
    }
    @Override
    protected List<JsonData> createReturnData(Object loadConfig, JSonDataRecordResult records) {
    List<JsonData> r = records.getRecords();
    return r;
    }


    }
    public TreeStore<JsonData> createStore() {


    TreeStore<JsonData> store = new TreeStore<JsonData>(new ModelKeyProvider<JsonData>() {
    @Override
    public String getKey(JsonData item) {
    return item.getId().toString();
    }
    });
    return store;


    }

  6. #6
    Sencha User
    Join Date
    Dec 2012
    Posts
    27
    Answers
    1

    Default

    thanks for you answer today i resolve the TreeGrid and the desktop add the shortcut problems.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •