Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SelectRecord in treeGrid when fetch operation occurs

    Hi,

    Client code:
    Code:
    public class KcpListTreeGrid extends TreeGrid {
    ...
    setSelectionAppearance(SelectionAppearance.CHECKBOX);		
    setShowSelectedStyle(false);
    setShowPartialSelection(true);
    setCascadeSelection(true);
    
    TreeGridField full_codField = new TreeGridField("full_cod");
    TreeGridField fullnameField = new TreeGridField("fullname");
    TreeGridField priznakField = new TreeGridField("priznak");
    
    setFields(full_codField, fullnameField, priznakField);
    
    addDataArrivedHandler(new DataArrivedHandler() {
    			
    	@Override
    	public void onDataArrived(DataArrivedEvent event) {
    		ListGridRecord[] records = getRecords();
    		for (ListGridRecord listGridRecord : records) {
    			if (listGridRecord.getAttribute("priznak").equals("1")) {
    				selectRecord(listGridRecord);						
    			}
    		}				
    	}
    });
    }
    Code:
    public class AccessToKcp extends HLayout implements EntryPoint {
    ...
    private LifeRayGroupListGrid liferayGroupList;
    liferayGroupList.addCellClickHandler(new CellClickHandler() {
    			
    	@Override
    	public void onCellClick(CellClickEvent event) {
    		Criteria crit = new Criteria();
    		groupId = event.getRecord().getAttributeAsInt("id");
    		crit.addCriteria("groupId", groupId);
    		kcpListTree.setFetchOperation("fetchKCP");
    		kcpListTree.fetchData(crit);
    	}
    });
    }
    When kcpListTree.fetchData(crit) occurs firstly addDataArrivedHandler doesn't fired. But when user make liferayGroupList.addCellClickHandler secondly addDataArrivedHandler fired and selectRecord(listGridRecord) occurs. How can do it when fetchData() calls firstly?

    #2
    DataArrived fires in both circumstances, but if you're having trouble, fetchData() allows a callback argument that is called when data has arrived as well.

    Comment


      #3
      Did you mean that?
      Code:
      kcpListTree.fetchData(crit, new DSCallback() {
      					
      	@Override
      	public void execute(DSResponse response, Object rawData, DSRequest request) {
      		ListGridRecord[] records = kcpListTree.getRecords();
      		for (ListGridRecord listGridRecord : records) {
      			if (listGridRecord.getAttribute("priznak").equals("1")) {
      				kcpListTree.selectRecord(listGridRecord);						
      			}
      		}	
      		
      	}
      });
      It also doesn't fired.

      Comment


        #4
        Does it not work because of setLoadDataOnDemand(false)?

        Comment


          #5
          It definitely does fire in general (just add it to a sample to see this). It would not fire if the server returned an error (dsResponse status set negative), or if you did something like call setData() after calling fetchData() and before the fetch completes.

          Comment


            #6
            You're right! It definitely does fire. But it can not enter in if condition
            Code:
            if (listGridRecord.getAttribute("priznak").equals("1")) {
            	kcpListTree.selectRecord(listGridRecord);
            	SC.say("I am here!");
            }
            //SC.say("I am there");
            I got it. Hot to call this method when user click on "plus" icon?

            Comment


              #7
              How do you think is addLeafClickHandler() is good workaround because I set setLoadDataOnDemand(false)?

              Comment


                #8
                It doesn't work with addFolderClickHandler
                Code:
                addFolderClickHandler(new FolderClickHandler() {
                			
                	@Override
                	public void onFolderClick(FolderClickEvent event) {
                		ListGridRecord[] records = getRecords();
                		for (ListGridRecord listGridRecord : records) {
                			if (listGridRecord.getAttribute("priznak").equals("1")) {
                				selectRecord(listGridRecord);						
                			}
                		}	
                		
                	}
                });
                What I did wrong?

                Comment


                  #9
                  RPC response
                  Code:
                  {
                  	obj_base:211325, 
                  	lev:4, 
                  	par_obj_base:211315, 
                  	priznak:"1", 
                  	fullname:"Количество направленных постановлений о взыскании в принудительном порядке", 
                  	full_cod:"Q803109"
                  },
                  When fetchData() first calls DataSource sends this => (priznak:"1"), but it don't go into if condition (if (listGridRecord.getAttribute("priznak").equals("1")))

                  Why?

                  Comment


                    #10
                    To find a record by it's ID, use treeGrid.getTree().find() (or findById()).

                    Comment


                      #11
                      Thank you! This changes resolved my issue.
                      Code:
                      kcpListTree.fetchData(crit, new DSCallback() {
                      					
                      	@Override
                      	public void execute(DSResponse response, Object rawData, DSRequest request) {
                      		ListGridRecord[] records = kcpListTree.getData().getAllNodes();						
                      		for (ListGridRecord listGridRecord : records) {
                      			if (listGridRecord.getAttribute("priznak").equals("1")) {							
                      				kcpListTree.selectRecord(listGridRecord);								
                      			}							
                      		}						
                      	}
                      });

                      Comment

                      Working...
                      X