reusing datasource

hi all,

i want to reuse my datasource created/ do refreshing of listgrid. is it possible?
i looked at datasource.removeData(RECORD); but it doesn’t seems to work.

i did something like: (each time i want to refresh the data)

        dataSource.removeData(record);
    for(int i = 0; i < 365; i++){
    	record = new ListGridRecord();
		record.setAttribute("date", result[i][0]);
		record.setAttribute("opensource", result[i][1]);
		record.setAttribute("trial", result[i][2]);
		record.setAttribute("sales", result[i][3]);
		record.setAttribute("ostrial", result[i][4]);
		record.setAttribute("trialsale", result[i][5]);
		record.setAttribute("ossale", result[i][6]);
		dataSource.addData(record);
    }

may i know what should be the correct way of doing refreshing?

i actually looked at the reuse pattern example. and they are using two datasources and they are getting the information from localhost. However, i am getting from the server and i want to use only one datasources.

Thank you!

Help!

can someone advise me?

If it’s a grid with a DataSource, just call invalidateCache() to initiate a new fetch.

i’m using a listgrid..

because i am fetching a new sets of data… how will invalidatecache help?

if you can tell me more, it will be great.
thanks for your help

after i attempt to use the invalidcache method to refresh my ListGrid with new data.

a popup window said Datasource:isc_OID_29: attempt to use Datasource … without the SmartClient Server option (sorry for the broken statement as i can’t copy and paste).

it also tell me to download the edition with SmartClient Server trace Stack.

what is this and what should i do ?

Read the docs for fetchData(), it explains what’s going on.

If you’re getting that message, your DataSource was not capable of fetch in the first place, so you must have populated your grid by other means? Posting very partial information like this makes it impossible to help, try posting complete code next time.

I’m guessing this is related to using clientonly on the data source but it has me stuck as well. Since I haven’t been able to find any supported way to use GwtRpc. I’ve been following the examples posted here using the manual RPC call and creating the ListGridRecords from the returned data and using addData to add the to the data source. This works fine one time, after that any changes to the fetch parameters just causes more data to be appended to the grid. The docs tell you to use the data object of the grid to clear the grid but that isn’t exposed by SmartGWT. Selecting all records and using removedSelected doesn’t do anything.
I even tried using a new datastore each time I needed to load the grid but that didn’t work either. No matter what I try it just adds more records to the grid instead of replacing them.

I really wish there was a supported and documented way to use GWT/RPC. This was promised “soon” back in December but I can’t find it. I understand the the LGPL can’t give developers the power of the GPL components but I can’t even recommend my client consider buying the licenses without being able to put together enough of a prototype using the LGPL components to show development value and scalability.

i have the same experience. how can i replace the data instead of adding to it?

how can i reuse the datasource? is there an example to follow? can someone advise me.

REFRESHING LISTGRID please advise me on this !!

hi all,

i still cannot refresh my listgrid. The closest i got is to add the data on the existing record. ( ie the record gets longer )
i tried many ways including invalidatecache, fetchdata, etc. I am using gwt-rpc to fetch data from the server. can someone please advise me.

below are my code in details:

entrypoint:

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.rednels.ofcgwt.client.ChartWidget;
import com.rednels.ofcgwt.client.model.ChartData;
import com.rednels.ofcgwt.client.model.axis.XAxis;
import com.rednels.ofcgwt.client.model.axis.YAxis;
import com.rednels.ofcgwt.client.model.elements.BarChart;
import com.rednels.ofcgwt.client.model.elements.BarChart.BarStyle;
import com.smartgwt.client.data.DSCallback;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.types.SortArrow;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;
import com.smartgwt.client.widgets.tree.events.LeafClickEvent;
import com.smartgwt.client.widgets.tree.events.LeafClickHandler;
public class MySQLConn implements EntryPoint,AsyncCallback<Object> {
private int value = 1;
private GridRecord record;
private MyDataSource monthly_2009;
private MyDataSource monthly_2008;
private MyDataSource monthly_2007;
private ListGrid companyGrid= new ListGrid();
private MySQLConnServiceAsync callProvider;
private TabSet tabset;

public void onModuleLoad() {
	long start = System.currentTimeMillis();
	monthly_2009 = new MyDataSource();
	monthly_2009.setClientOnly(true);

	companyGrid.setAlternateRecordStyles(true);
	companyGrid.setShowAllRecords(false);
	companyGrid.setHeight100();
	companyGrid.setWidth100();
	companyGrid.setDataSource(monthly_2009);
	companyGrid.setAutoFetchData(true);
	companyGrid.setCanDragResize(true);
	companyGrid.setEmptyMessage("<b>No Data is Selected</b>"); 
	rpcInit();
	getData10(1);
	long end = System.currentTimeMillis();
	System.out.println("Completed in +"+(end-start)+"ms");
 }

private void displayData(DataContainer[] displayData) {
	 
     HLayout layout = new HLayout();
     layout.setLayoutMargin(15);
     layout.setMembersMargin(20);
     layout.setHeight100();
     layout.setWidth100();
     VLayout right_vlayout = new VLayout();
     right_vlayout.setHeight100();

     tabset = new TabSet();
     tabset.setTabBarThickness(24);
     tabset.setWidth100();
     tabset.setHeight100();
     
     Tab tb = new Tab();
     HLayout hlayout = new HLayout();
     hlayout.addMember(companyGrid);
     tb.setTitle("Record");
     tb.setPane(hlayout);
     tb.setCanClose(true);
     
     tabset.addTab(tb);
     right_vlayout.addMember(tabset);
     
     VLayout left_vlayout = new VLayout();
     left_vlayout.setMembersMargin(20);
     left_vlayout.setHeight100();
     left_vlayout.setWidth(185);
     left_vlayout.setShowResizeBar(true);
     
     TreeGrid sideNav = new TreeGrid();
     sideNav.setAnimateFolderTime(100);
     sideNav.setAnimateFolders(true);
     sideNav.setAnimateFolderSpeed(1000);
     sideNav.setNodeIcon("application_view_list.png");
     sideNav.setShowConnectors(true);
     sideNav.setShowSortArrow(SortArrow.CORNER);
     sideNav.setShowAllRecords(true);
     sideNav.setLoadDataOnDemand(false);
     sideNav.setCanSort(false);
     
     TreeGridField field_sideNav = new TreeGridField();
     field_sideNav.setCanFilter(true);
     field_sideNav.setName("name");

     sideNav.setFields(field_sideNav);
     
     String idSuffix = "";
     ExplorerTreeNode[] showcaseData = ShowcaseData.getData(idSuffix);
     
     Tree tree_sideNav = new Tree();
     tree_sideNav.setModelType(TreeModelType.PARENT);
     tree_sideNav.setNameProperty("name");
     tree_sideNav.setOpenProperty("isOpen");
     tree_sideNav.setIdField("nodeID");
     tree_sideNav.setParentIdField("parentNodeID");
     tree_sideNav.setRootValue("root" + idSuffix);
     tree_sideNav.setShowRoot(true);
     tree_sideNav.setData(showcaseData);

     sideNav.setData(tree_sideNav);
     sideNav.addLeafClickHandler(new LeafClickHandler() {
         public void onLeafClick(LeafClickEvent event) {
             TreeNode node = event.getLeaf();
             showSample(node);
         }
     });
    		
     VLayout left_child_vlayout1 = new VLayout();
     left_child_vlayout1.addMember(logo);
     left_child_vlayout1.addMember(sideNav);
     left_child_vlayout1.setShowResizeBar(true);

     VLayout left_child_vlayout2 = new VLayout();
     left_child_vlayout2.addMember(addBarCharts());
     left_vlayout.addMember(left_child_vlayout1);
     left_vlayout.addMember(left_child_vlayout2);
     layout.addMember(left_vlayout);
     layout.addMember(right_vlayout);
     layout.draw();
 }

private void getData() {
	if(value == 1) companyGrid.setDataSource(monthly_2009);
	else if(value == 2 ) companyGrid.setDataSource(monthly_2008);
	else if(value == 3 ) companyGrid.setDataSource(monthly_2007);
	
	   AsyncCallback<String[][]> callback = new AsyncCallback<String[][]>(){

	public void onFailure(Throwable ex) {
		RootPanel.get().add(new HTML(ex.toString()));
	   }
	   public void onSuccess(String[][] result) {
		   System.out.println("Success!");
	    for(int i = 0; i < 365; i++){
	    	GridRecord record = new GridRecord();
			record.setAttribute("date", result[i][0]);
			record.setAttribute("opensource", result[i][1]);
			record.setAttribute("trial", result[i][2]);
			record.setAttribute("sales", result[i][3]);
			record.setAttribute("ostrial", result[i][4]);
			record.setAttribute("trialsale", result[i][5]);
			record.setAttribute("ossale", result[i][6]);
			
			if(value == 1) monthly_2009.addData(record);
			else if(value == 2 ) monthly_2008.addData(record);
			else if(value == 3 ) monthly_2007.addData(record);

	    }
		System.out.println("Success_out!");
		System.out.println(" this value :" + value);
	    changeDataSource();

	   }
	  };
	  callProvider.getData1(value, callback);
}
 
private void changeDataSource(){
	companyGrid.fetchData(); 
}
private void rpcInit() {
     callProvider = (MySQLConnServiceAsync) GWT.create(MySQLConnService.class);
     ServiceDefTarget target = (ServiceDefTarget) callProvider;
     String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnService";
     target.setServiceEntryPoint(moduleRelativeURL);
}
 
private void getData10(final int value) {
	   

	   AsyncCallback<String[][]> callback = new AsyncCallback<String[][]>(){
	   
	   public void onFailure(Throwable ex) {
		RootPanel.get().add(new HTML(ex.toString()));
	   }
	   public void onSuccess(String[][] result) {
		   
	    for(int i = 0; i < 365; i++){
	    	GridRecord record = new GridRecord();
			record.setAttribute("date", result[i][0]);
			record.setAttribute("opensource", result[i][1]);
			record.setAttribute("trial", result[i][2]);
			record.setAttribute("sales", result[i][3]);
			record.setAttribute("ostrial", result[i][4]);
			record.setAttribute("trialsale", result[i][5]);
			record.setAttribute("ossale", result[i][6]);

			monthly_2009.addData(record);
	    }
	    

	    DataContainer[] displayData = null;
		 displayData(displayData);
	   }
	  };
	  callProvider.getData1(value, callback);
	}

public void onFailure(Throwable caught) {
	// TODO Auto-generated method stub
	
}

public void onSuccess(Object result) {
	// TODO Auto-generated method stub
	
}
}

MyDataSource:

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class MyDataSource extends DataSource {
	
	private String highest_opensource;
	private String highest_trial;
	private String highest_sales;
	private String highest_ostrial;
	private String highest_trialsale;
	private String highest_ossale;
	
	public MyDataSource(){
		DataSourceTextField date = new DataSourceTextField("date", "Date");
		DataSourceFloatField opensource = new DataSourceFloatField("opensource", "Open Source");
		DataSourceFloatField trial = new DataSourceFloatField("trial", "Trial");
		DataSourceFloatField sales = new DataSourceFloatField("sales", "Sales");
		DataSourceDateField ostrial = new DataSourceDateField("ostrial", "OS-Trial");
		DataSourceTextField trialsale = new DataSourceTextField("trialsale", "Trial-Sale");
		DataSourceTextField ossale = new DataSourceTextField("ossale", "OS-Sale");
		setFields(date, opensource, trial, sales, ostrial, trialsale, ossale);
	}
	 public void count(String opensource, String trial, String sales, String ostrial, String trialsale, String ossale){
		 int lastchar_opensource = 0;
		if(opensource!=null ) lastchar_opensource = opensource.length()-1;
		 int lastchar_trial = 0;
		if(trial!=null)  lastchar_trial =   trial.length()-1;
		 int lastchar_sales = 0;
		if(sales!=null)  lastchar_sales =   sales.length()-1;
		 int lastchar_ostrial= 0;
		if(ostrial!=null)  lastchar_ostrial =   ostrial.length()-1;
		 int lastchar_trialsale= 0;
		if(trialsale!=null)  lastchar_trialsale =   trialsale.length()-1;
		 int lastchar_ossale= 0;
		if(ossale!=null)  lastchar_ossale =   ossale.length()-1;
		 
		 if(highest_opensource!= null){
			   if(opensource!=null ){
				  if(opensource.charAt(lastchar_opensource)!='%'){
					   if(Double.parseDouble(highest_opensource)< Double.parseDouble(opensource))
						   highest_opensource = opensource;
				   }
				  else {
					  opensource = opensource.substring(0, lastchar_opensource);
					  if(Double.parseDouble(highest_opensource)< Double.parseDouble(opensource)){
						   highest_opensource = opensource;
				   		}
			   		}
			   }
		   }
		   else highest_opensource = opensource;
		   
		   if(highest_trial!= null){
			   if(trial!=null){
				   if(trial.charAt(lastchar_trial)!='%'){
					   if(Double.parseDouble(highest_trial)< Double.parseDouble(trial))
						   highest_trial = trial;
				   		}
				   else {
					   	  trial = trial.substring(0, lastchar_trial);
					   	  if(Double.parseDouble(highest_trial)< Double.parseDouble(trial)){
							   highest_trial = trial;
					   		}
				   	}
			   }
		   	}  
		   else highest_trial = trial;
		   
		   if(highest_sales!= null){
			   if(sales!=null){
				   if(sales.charAt(lastchar_sales)!='%'){
					   if(Double.parseDouble(highest_sales)< Double.parseDouble(sales)){
						   highest_sales = sales;
					   }
				   }
				   else {
					   	  sales = sales.substring(0, lastchar_sales);
					   	  if(Double.parseDouble(highest_sales)< Double.parseDouble(sales)){
							   highest_sales = sales;
						   }
				   	}
		   		}
		   }
		   else highest_sales = sales;
		   
		   if(highest_ostrial!= null){
			   if(ostrial!=null){
				   if(ostrial.charAt(lastchar_ostrial)!='%'){
					   if(Double.parseDouble(highest_ostrial)< Double.parseDouble(ostrial)){
						   highest_ostrial = ostrial;
					   }
				   }
				   else {
					   ostrial = ostrial.substring(0, lastchar_ostrial);
						   if(Double.parseDouble(highest_ostrial)< Double.parseDouble(ostrial))
							   highest_ostrial = ostrial;
				   	}
		   		}
		   }
		   else highest_ostrial = ostrial;
		   
		   if(highest_trialsale!= null){
			   if(trialsale!=null){
				   if(trialsale.charAt(lastchar_trialsale)!='%'){
					   if(Double.parseDouble(highest_trialsale)< Double.parseDouble(trialsale)){
						   highest_trialsale = trialsale;
					   }
				   }
				   else {
					   trialsale = trialsale.substring(0, lastchar_trialsale);
					   if(Double.parseDouble(highest_trialsale)< Double.parseDouble(trialsale))
						   highest_trialsale = trialsale;
				   	}
			   }
		   }
		   else highest_trialsale = trialsale;
		   
		   if(highest_ossale!= null){
			   if(ossale!=null){
				   if(ossale.charAt(lastchar_ossale)!='%'){
					   if(Double.parseDouble(highest_ossale)< Double.parseDouble(ossale)){
						   highest_ossale = ossale;
					   }
				   }
				   else {
					   ossale = ossale.substring(0, lastchar_ossale);
					   if(Double.parseDouble(highest_ossale)< Double.parseDouble(ossale))
						   highest_ossale = ossale;
				   	}
			   }
		   }
		   else highest_ossale = ossale; 
	 	}

	   public String getHighest_opensource(){
		   return highest_opensource;
	   }
	   
	   public String getHighest_trial(){
		   return highest_trial;
	   }
	   
	   public String getHighest_sales(){
		   return highest_sales;
	   }
	   
	   public String getHighest_ostrial(){
		   return highest_ostrial;
	   }
	   
	   public String getHighest_trialsale(){
		   return highest_trialsale;
	   }
	   
	   public String getHighest_ossale(){
		   return highest_ossale;
	   }
}

GridRecord:

import com.smartgwt.client.widgets.grid.ListGridRecord;

public class GridRecord extends ListGridRecord{

		public GridRecord(){
			
		}
	   public GridRecord(String date, String opensource, String trial, String sales, String ostrial, String trialsale, String ossale) {

	        setDate(date);
	        setOpenSource(opensource);
	        setTrial(trial);
	        setSales(sales);
	        setOstrial(ostrial);
	        setTrialsale(trialsale);
	        setOssale(ossale);
	    }
	   
	    public void setDate(String date) {
	        setAttribute("date", date);
	    }
	   
	    public void setOpenSource(String opensource) {
	        setAttribute("opensource", opensource);
	    }

	    public void setTrial(String trial) {
	        setAttribute("trial", trial);
	    }
	    
	    public void setSales(String sales) {
	        setAttribute("sales", sales);
	    }
	    
	    public void setOssale(String ossale) {
	        setAttribute("ossale", ossale);
	    }

		public void setTrialsale(String trialsale){
	        setAttribute("trialsale", trialsale);
	    }

		public void setOstrial(String ostrial){
	        setAttribute("ostrial", ostrial);
	    }

	    public String getDate() {
	        return getAttributeAsString("date");
	    }
	    public String getOpensource() {
	        return getAttributeAsString("opensource");
	    }

	    public String getTrial() {
	        return getAttributeAsString("trial");
	    }

	    public String getSales() {
	        return getAttributeAsString("sales");
	    }

	    public String getOssale() {
	        return getAttributeAsString("ossale");
	    }

	    public String getTrialsale() {
	        return getAttributeAsString("trialsale");
	    }

	    public String getOstrial() {
	        return getAttributeAsString("ostrial");
	    }



}

If you are using the approach of a client-only DataSource populated by GWT-RPC then you use setTestData() to change the dataset in use by the DataSource and then call invalidateCache() on any grids that need to get new data.

thank you isomorphic!

it works perfectly.