PDA

View Full Version : Grid not displaying Data



jamone
10 Jan 2012, 10:27 AM
I am retreiving data from a database and wish to display in a grid. The grid renders with the correct number of rows for the data bein g returned, but does not display any data. I have verified that the results presented to the Grid are correct, just no display of any data.

I have checked I do not believe the text is white.

Data Model:


import java.io.Serializable;
import java.util.Date;

import com.extjs.gxt.ui.client.data.BaseModel;

public class SearchInfo extends BaseModel implements Serializable {
private static final long serialVersionUID = 1L;

private String company;
private Date createdDate;
private String customerNum;
private String customerId;
private Date invoiceDate;
private String invoiceLine;
private String invoiceNum;
private String jobNum;
private String lotNum;
private Date modifiedDate;
private Boolean open;
private String partNum;
private String poNum;
private String poLine;
private String sourceLot;
private Boolean stlCertificate;
private Boolean supplierData;
private String vendorId;
private String vendorNum;
private String version;
private Boolean voided;
private String character01;
private String character02;
private String character03;
private String character04;
private String character05;
private String character06;
private String character07;
private String character08;
private String character09;
private String character10;

/**
* Class constructor
**/
public SearchInfo() {

}

public SearchInfo(String cN, Date cd, String custNum, String cId, Date invD, String invNum,
String invLine, String jN, String lN, Date modD, Boolean op, String pN, String poN,
String pL, String sL, Boolean stlCert, Boolean sData, String vId, String vNo, String ver,
Boolean vded, String char01, String char02, String char03, String char04, String char05,
String char06, String char07, String char08, String char09, String char10) {
set("cN", company);
set("cd", createdDate);
set("custNum", customerNum);
set("cId", customerId);
set("invD", invoiceDate);
set("invNum", invoiceNum);
set("inv:ine", invoiceLine);
set("jN", jobNum);
set("lN", lotNum);
set("modD", modifiedDate);
set("op", open);
set("pN", partNum);
set("poN", poNum);
set("pL", poLine);
set("sL", sourceLot);
set("stlCert", stlCertificate);
set("sData", supplierData);
set("vId", vendorId);
set("vNo", vendorNum);
set("ver", version);
set("vded", voided);
set("char01", character01);
set("char02", character02);
set("char03", character03);
set("char04", character04);
set("char05", character05);
set("char06", character06);
set("char07", character07);
set("char08", character08);
set("char09", character09);
set("char10", character10);
}

public String getCompany() {
return company;
}

public void setCompany(String company) {
this.company = company;
}

public Date getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}

public String getCustomerNumber() {
return customerNum;
}

public void setCustomerNumber(String customerNumber) {
this.customerNum = customerNumber;
}

public String getCustomerID() {
return customerId;
}

public void setCustomerID(String customerID) {
this.customerId = customerID;
}

public Date getInvoiceDate() {
return this.invoiceDate;
}

public void setInvoiceDate(Date invDate) {
this.invoiceDate = invDate;
}

public String getInvoiceLine() {
return this.invoiceLine;
}

public void setInvoiceLine(String invLine) {
this.invoiceLine = invLine;
}

public String getInvoiceNumber() {
return invoiceNum;
}

public void setInvoiceNumber(String invoiceNum) {
this.invoiceNum = invoiceNum;
}

public String getJobNumber() {
return jobNum;
}

public void setJobNumber(String jNum) {
this.jobNum = jNum;
}

public String getLotNumber() {
return lotNum;
}

public void setLotNumber(String lotNum) {
this.lotNum = lotNum;
}

public Date getModifiedDate() {
return modifiedDate;
}

public void setModifiedDate(Date modDate) {
this.modifiedDate = modDate;
}

public Boolean getOpen() {
return open;
}

public void setOpen(Boolean ope) {
this.open = ope;
}

public String getPartNumber() {
return partNum;
}

public void setPartNumber(String partNum) {
this.partNum = partNum;
}

public String getPONumber() {
return poNum;
}

public void setPONumber(String poNum) {
this.poNum = poNum;
}

public String getPOLine() {
return poLine;
}

public void setPOLine(String poLine) {
this.poLine = poLine;
}

public String getSourceLot() {
return sourceLot;
}

public void setSourceLot(String srcLot) {
this.sourceLot = srcLot;
}

public Boolean getSTLCertificate() {
return stlCertificate;
}

public void setSTLCertfificate(Boolean stlCert) {
this.stlCertificate = stlCert;
}

public Boolean getSupplierData() {
return supplierData;
}

public void setSupplierData(Boolean suppData) {
this.supplierData = suppData;
}

public String getVendorID() {
return vendorId;
}

public void setVendorID(String vendorId) {
this.vendorId = vendorId;
}

public String getVendorNumber() {
return vendorNum;
}

public void setVendorNumber(String vendorNum) {
this.vendorNum = vendorNum;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public Boolean getVoided() {
return voided;
}

public void setVoided(Boolean voided) {
this.voided = voided;
}

public String getCharacter01() {
return character01;
}

public void setCharacter01(String character) {
this.character01 = character;
}

public String getCharacter02() {
return character02;
}

public void setCharacter02(String character) {
this.character02 = character;
}

public String getCharacter03() {
return character03;
}

public void setCharacter03(String character) {
this.character03 = character;
}

public String getCharacter04() {
return character04;
}

public void setCharacter04(String character) {
this.character04 = character;
}

public String getCharacter05() {
return character05;
}

public void setCharacter05(String character) {
this.character05 = character;
}

public String getCharacter06() {
return character06;
}

public void setCharacter06(String character) {
this.character06 = character;
}

public String getCharacter07() {
return character07;
}

public void setCharacter07(String character) {
this.character07 = character;
}

public String getCharacter08() {
return character08;
}

public void setCharacter08(String character) {
this.character08 = character;
}

public String getCharacter09() {
return character09;
}

public void setCharacter09(String character) {
this.character09 = character;
}

public String getCharacter10() {
return character10;
}

public void setCharacter10(String character) {
this.character10 = character;
}

public String xmlString() {
return (getCharacter01() == null ? "" : getCharacter01()) + (getCharacter02() == null ? "" : getCharacter02()) + (getCharacter03() == null ? "" : getCharacter03())
+ (getCharacter04() == null ? "" : getCharacter04()) + (getCharacter05() == null ? "" : getCharacter05()) + (getCharacter06() == null ? "" : getCharacter06())
+ (getCharacter07() == null ? "" : getCharacter07()) + (getCharacter08() == null ? "" : getCharacter08()) + (getCharacter09() == null ? "" : getCharacter09())
+ (getCharacter10() == null ? "" : getCharacter10());
}
}

The code to build the Grid:


import java.util.ArrayList;
import java.util.List;

import com.foo.DataMgmt.client.event.AppEvents;
import com.foo.DataMgmt.client.mvc.model.SearchInfo;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.BoxComponent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.i18n.client.DateTimeFormat;

public class ResultsListGrid extends LayoutContainer {
Button cancel;

public ResultsListGrid(List<SearchInfo> results) {
setLayout(new FitLayout());
createResultsListGrid(results);
createButtons();
}

private void createResultsListGrid(List<SearchInfo> results) {

GridCellRenderer<SearchInfo> buttonRenderer = new GridCellRenderer<SearchInfo>() {

private boolean init = false;

@Override
public Object render(final SearchInfo model, String property,
ColumnData config, final int rowIndex, final int colIndex,
final ListStore<SearchInfo> store, Grid<SearchInfo> grid) {
if (!init) {
init = true;
grid.addListener(Events.ColumnResize, new Listener<GridEvent<SearchInfo>>() {

@Override
public void handleEvent(GridEvent<SearchInfo> be) {
for (int i = 0; i < be.getGrid().getStore().getCount(); i++) {
if (be.getGrid().getView().getWidget(i, be.getColIndex()) != null
&& be.getGrid().getView().getWidget(i, be.getColIndex()) instanceof BoxComponent) {
((BoxComponent) be.getGrid().getView().getWidget(i, be.getColIndex())).setWidth(be.getWidth() - 10);
}
}
}
});
}

Button b = new Button("Details" , new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
MessageBox.info("XML", model.xmlString(), null);
}
});

b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10);
b.setToolTip("Click for Certificate Details");
return b;
}
};

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig();
column.setId("company");
column.setHeader("Company");
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("createdDate");
column.setHeader("Created Date");
column.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("customerNum");
column.setHeader("Customer Number");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("customerId");
column.setHeader("Customer ID");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("invoiceDate");
column.setHeader("Invoice Date");
column.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("invoiceLine");
column.setHeader("Invoice Line");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("invoiceNum");
column.setHeader("Invoice Number");
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("jobNum");
column.setHeader("Job Number");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("lotNum");
column.setHeader("Lot Number");
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("modifiedDate");
column.setHeader("Modified Date");
column.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("open");
column.setHeader("Open Certificate");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("partNum");
column.setHeader("Part Number");
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("poNum");
column.setHeader("PO Number");
column.setHidden(false);
configs.add(column);

column = new ColumnConfig();
column.setId("poLine");
column.setHeader("PO Line");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("sourceLot");
column.setHeader("Source Lot");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("stlCertificate");
column.setHeader("STL Certificate");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("supplierData");
column.setHeader("Supplier Data");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("vendorId");
column.setHeader("Vendor ID");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("vendorNum");
column.setHeader("Vendor Number");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("version");
column.setHeader("Version");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("voided");
column.setHeader("Void Certificate");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character01");
column.setHeader("character01");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character02");
column.setHeader("character02");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character03");
column.setHeader("character03");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character04");
column.setHeader("character04");
column.setHidden(true);
column.setRenderer(buttonRenderer);
configs.add(column);

column = new ColumnConfig();
column.setId("character05");
column.setHeader("character05");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character06");
column.setHeader("character06");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character07");
column.setHeader("character07");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character08");
column.setHeader("character08");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character09");
column.setHeader("character09");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("character10");
column.setHeader("character10");
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("details");
column.setHeader("Details");
column.setHidden(false);
column.setRenderer(buttonRenderer);
configs.add(column);

final ListStore<SearchInfo> store = new ListStore<SearchInfo>();

store.add(results);

ColumnModel cm = new ColumnModel(configs);

ContentPanel cp = new ContentPanel();
cp.setBodyBorder(true);
cp.setHeading("CoC Item Search Results");
cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setSize(800, 300);
cp.setLayout(new FitLayout());

Grid<SearchInfo> grid = new Grid<SearchInfo>(store, cm);
grid.setStyleAttribute("borderTop", "none");
grid.setBorders(true);
grid.getView().setForceFit(true);
cp.add(grid);
cp.layout();
add(cp);
}

private void createButtons() {
cancel = new Button("Cancel");
cancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent be) {
Dispatcher.forwardEvent(AppEvents.CancelList);
}
});

add(cancel);
}
}


30603

Attached is how the grid is rendered. Can anyone spot where I may have gone wrong?

Thanks in advance.

Cheers

Ersmarker
10 Jan 2012, 12:37 PM
In the first column you set "company" as id.
But you never do set("company",value) in your SearchInfo model. So all values in the column is null.

jamone
10 Jan 2012, 10:43 PM
Thanks for spotting that, but that is not the issue. The model is populated using the individual set methods, just to check I corrected the syntax, and still the problem remains. The results List Array, contains the correct information, the store.add(result) however is not retrieving any data. I can manually recover data using result.get(0).getCompany() for example to recover the company name for the first record, but I store is not seeing this data. The result is a List array of <SearchInfo>.

Ersmarker
11 Jan 2012, 2:58 AM
As I said, you never do set("company",value):

Your setCompany method need to look like this:




public void setCompany(String company) {
set("company",company);
}

jamone
12 Jan 2012, 3:16 AM
Thanks, spot on.
Cheers