SmartGWT 2.3 nightly downloaded 10292010
Windows 7 64bit using MyEclipse IDE
I have a View that when you click a button opens a Modal window on that window I have Drag and Drop working between a couple ListGrids, after dragging a few records I then save them to a POJO type object upon clicking a button "Save" and close the Modal.
If I click the button again on the main View it calls a method loadGrid that pulls those values from the POJO and adds them back into the ListGrid that they were dragged to earlier, so they can see what they already have added previously, however when I drag and drop again it lets me add the same primary keys creating duplicates records in the ListGrid, posted the code below.
How can I make it so that it sees these records as the same? The primary key is the same, the types are the same, not sure what it could be...
I was using ListGridFields before but changed to using a DataSource and DataSourceFields figuring it may have something to do with that... to no avail.
The method to load our data back in after opening again
Windows 7 64bit using MyEclipse IDE
I have a View that when you click a button opens a Modal window on that window I have Drag and Drop working between a couple ListGrids, after dragging a few records I then save them to a POJO type object upon clicking a button "Save" and close the Modal.
If I click the button again on the main View it calls a method loadGrid that pulls those values from the POJO and adds them back into the ListGrid that they were dragged to earlier, so they can see what they already have added previously, however when I drag and drop again it lets me add the same primary keys creating duplicates records in the ListGrid, posted the code below.
How can I make it so that it sees these records as the same? The primary key is the same, the types are the same, not sure what it could be...
I was using ListGridFields before but changed to using a DataSource and DataSourceFields figuring it may have something to do with that... to no avail.
Code:
final ListGrid selLGW = new ListGrid(); selLGW.setWidth("100%"); selLGW.setHeight("95%"); selLGW.setLeft(350); selLGW.setShowAllRecords(true); selLGW.setEmptyMessage("Drop Rows Here"); selLGW.setCanAcceptDroppedRecords(true); selLGW.setPreventDuplicates(true); DataSource ds = new DataSource(); DataSourceIntegerField catIdFld = new DataSourceIntegerField("catid", "Id"); catIdFld.setPrimaryKey(true); DataSourceTextField startDTFld = new DataSourceTextField("dsc", "Catalog"); ds.setFields(catIdFld, startDTFld); ds.setClientOnly(true); selLGW.setDataSource(ds); selLGW.setAutoFetchData(true); btnSave.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { @Override public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) { ArrayList<CatalogPromoState> cats = ps.getCatalogs(); ListGridRecord[] recs = selLGW.getRecords(); for (ListGridRecord rec : recs) { CatalogPromoState tmp = new CatalogPromoState(); tmp.setCatid(rec.getAttributeAsInt("catid")); tmp.setDsc(rec.getAttributeAsString("dsc")); cats.add(tmp); } winModal.destroy(); } }); loadGrid(selLGW, ps);
Code:
private static void loadGrid(ListGrid lg, PromotionStore ps) { ArrayList<CatalogPromoState> cats = ps.getCatalogs(); if(cats.size() > 0) { for (CatalogPromoState cat : cats) { ListGridRecord tmp = new ListGridRecord(); tmp.setAttribute("catid", cat.getCatid()); tmp.setAttribute("dsc", cat.getDsc()); lg.getDataSource().addData(tmp); } } }
Comment