Announcement

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

    ListGrid Duplicates created after adding records onload then dragging the same again

    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.

    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);
    The method to load our data back in after opening again
    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);
    		}
    	}
    }

    #2
    I'll supply more information if needed.

    Comment


      #3
      Hi Gil,
      Its not clear exactly what's going on here from the code you posted.

      In terms of expected behavior - typically you want to call dataSource.updateData() when updating an existing record and dataSource.addData() when creating a new one.

      If that doesn't help you resolve this, it would be best if we could see a simple complete test case demonstrating the issue. It'd be ideal if you can show us a full entryPoint class we can run on our end. Failing that, at least the full definitions for the relevant UI and data management APIs you're working with here.

      Thanks

      Comment


        #4
        Originally posted by Isomorphic
        Hi Gil,
        Its not clear exactly what's going on here from the code you posted.

        In terms of expected behavior - typically you want to call dataSource.updateData() when updating an existing record and dataSource.addData() when creating a new one.

        If that doesn't help you resolve this, it would be best if we could see a simple complete test case demonstrating the issue. It'd be ideal if you can show us a full entryPoint class we can run on our end. Failing that, at least the full definitions for the relevant UI and data management APIs you're working with here.

        Thanks
        Where do you want the application uploaded to ? Do you want an issue created and uploaded to it or something else, the forum won't allow me to upload a zip file.

        When clicking a button I open a Modal with a few ListGrid's which I have setup to use Drag and Drop from one to the other. When they close the Modal, it saves what they've dragged to the ListGrid and when they reopen the modal I repopulate that from pojo's as in my code example. However if I then try to drag the same one as I've just populated from a Pojo on load then the Drop operation isn't recognizing the pkey (what I'm guessing) and is allowing the same record to be added.

        I can try to create a single file but this relies on more than one, so it may require a small project.
        Last edited by gilcollins; 12 Nov 2010, 13:38.

        Comment


          #5
          Attached Single Modal Window that duplicates the issue

          1. Add a button to open the TestPromoSetToCatalog.selectCatalogs();

          2. This will create two list grids the one on the left is the main one and can drag the records to the right one

          3. What I'm duplicating here is that this window was already opened and records were selected by dragging them to the right window, now we are opening this Modal again and loading those previous selections into the right window so we can see what we selected previously.

          4. Select either one of the records from the left window and drag it to the right window, it is allowing this even though "selLGW.setPreventDuplicates(true);" is set, if you drag again from the left to the right it will show the error that you can't have duplicates but not from the ones previously loaded.

          If you need more information please ask.

          Thank you
          Attached Files

          Comment


            #6
            Thanks for the clear test case - we're looking into this and will be getting back to you soon

            Comment


              #7
              Originally posted by Isomorphic
              Thanks for the clear test case - we're looking into this and will be getting back to you soon
              Do you have any update on this?

              Comment


                #8
                Hello gilcollins,

                A fix was recently committed which we think will address this use case. Please try a nightly build (smartclient.com/builds).

                Comment


                  #9
                  Originally posted by Isomorphic
                  Hello gilcollins,

                  A fix was recently committed which we think will address this use case. Please try a nightly build (smartclient.com/builds).
                  Thank you this worked when changing to using DataSource's on the ListGrid's in Question and this update from the nightly.

                  Comment

                  Working...
                  X