How do I retrieve all data from a data source?

I have a datasource in SmartGWT. How to extract data from it? I tried using the method fetchData()

, but then in the criteria I need to add the ie value

Criteria cr = new Criteria();
cr.addCriteria("Name", "Name_Value");

      

To execute selectall on DataSource, what should I do?

Here is the code:

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DragDataAction;
import com.smartgwt.client.widgets.TransferImgButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.VStack;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.tree.TreeGridField;

public class TreeDragNodesSample implements EntryPoint {
TreeGrid grid1 = new TreeGrid();
TreeGrid grid2 = new TreeGrid();
String name=null;
    public void onModuleLoad() {
Tree test = new Tree();

        grid1.setDragDataAction(DragDataAction.COPY);
        grid1.setAutoFetchData(true);
        grid1.setDataSource(EmployeeXmlDS.getInstance());
        grid1.setWidth(200);
        grid1.setHeight(200);
        grid1.setShowEdges(true);
        grid1.setBorder("0px");
        grid1.setBodyStyleName("normal");
        grid1.setShowHeader(false);
        grid1.setLeaveScrollbarGap(false);
        grid1.setEmptyMessage("<br>Drag & drop parts here");
        grid1.setManyItemsImage("cubes_all.png");
        grid1.setAppImgDir("icons/16/");
        grid1.setNodeIcon("cube.png");
        grid1.setFolderIcon("person.png");
        grid1.setCanReorderRecords(true);
        grid1.setCanAcceptDroppedRecords(true);
        grid1.setCanDragRecordsOut(true);
        grid1.setCanAcceptDrop(true);
        grid1.setCanDrop(true);
        TreeGridField tname = new TreeGridField("Name");
        TreeGridField child = new TreeGridField("ChildID");
        TreeGridField reps = new TreeGridField("ReportsTo");
        grid1.setFields(tname);

        grid2.setLeft(250);
        grid2.setAutoFetchData(true);
        grid2.setDataSource(EmployeeXmlDSDrop.getInstance());
        grid2.setWidth(200);
        grid2.setHeight(200);
        grid2.setShowEdges(true);
        grid2.setBorder("0px");
        grid2.setBodyStyleName("normal");
        grid2.setShowHeader(false);
        grid2.setLeaveScrollbarGap(false);
        grid2.setEmptyMessage("<br>Drag & drop parts here");
        grid2.setManyItemsImage("cubes_all.png");
        grid2.setAppImgDir("icons/16/");
        grid2.setNodeIcon("cube.png");
        grid2.setFolderIcon("person.png");
        grid2.setCanReorderRecords(true);
        grid2.setCanAcceptDroppedRecords(true);
        grid2.setCanDragRecordsOut(true);
        grid2.setCanAcceptDrop(true);
        grid2.setCanDrop(true);
        TreeGridField tname2 = new TreeGridField("Name");
        TreeGridField child2 = new TreeGridField("ChildID");
        TreeGridField reps2 = new TreeGridField("ReportsTo");
        grid2.setFields(tname2);

        VStack moveControls = new VStack(10);
        moveControls.setWidth(32);
        moveControls.setHeight(74);
        moveControls.setLayoutAlign(Alignment.CENTER);

        TransferImgButton rightArrow = new TransferImgButton(TransferImgButton.RIGHT, new ClickHandler() {

            public void onClick(ClickEvent event) {
                grid2.transferSelectedData(grid1);
            }
        });
        moveControls.addMember(rightArrow);

        TransferImgButton leftArrow = new TransferImgButton(TransferImgButton.LEFT, new ClickHandler() {

            public void onClick(ClickEvent event) {
                grid1.transferSelectedData(grid2);
            }
        });
        moveControls.addMember(leftArrow);

        HStack grids = new HStack(10);
        grids.setHeight(160);
        grids.addMember(grid1);
        grids.addMember(moveControls);
        grids.addMember(grid2);
        grids.draw();
    }
}

      

+3


source to share


1 answer


You are not performing a select operation on the DataSource. You would rather do it on your database bound object, for example. linked to ListGrid. Assuming the data has been set and loaded into the ListGrid listGrid, you simply call

listGrid.getRecords();

      

which returns a [] record with all criteria visible or matched against a recordset. Another option, for database-bound ListGrids, is to use a ResultSet object. This is useful when you want to find specific records in your data, but since you want all records, I would suggest you use the getAllRecords method. See API for details

Update. Based on the code extraction, I can now see that you are using TreeGrid instead of ListGrid. Thus, you have to use the method:



TreeGrid.getTree().getAllNodes();

      

This will give you all the tree nodes that were loaded, no matter if they are open or closed. ListGrid.getRecords () will only return open nodes. Note that the TreeGrid by default loads its data on demand. Therefore, if you want to get all the nodes of the tree, you need to disable this function and preload all the data. This can of course cause speed problems. To do this, follow these steps:

TreeGrid.setLoadDataOnDemand(Boolean.FALSE);

      

+1


source







All Articles