Announcement

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

    New record with default values

    Hi,

    Using: SmartClient Version: 8.2/LGPL Development Only (built 2011-12-05)
    On IE 8.

    When the user cursors to the end of my grid I want a new record to be created with default values

    I have a piece of code that according to samples should do this:

    Code:
    grid.addRowEditorEnterHandler(new RowEditorEnterHandler()
                                  {
                                        @Override
                                        public void onRowEditorEnter(RowEditorEnterEvent event)
                                        {
                                              CasualHourRecord chr = (CasualHourRecord) event.getRecord();
                                              if (chr == null) {
                                                    Log.debug("OnRowEditorEnter - record is null");
                                                    CasualHourRecord newCHRecord = createNewRecord();
                                                    grid.addData(newCHRecord);
                                              }
                                              else {
    chr.setRecState(CasualHourRecord.REC_STATE_UPDATED);
                                              }
                                        }
                                  });
    It almost works but I end up with both a blank row and new row with defaults
    How do I stop the blank row from coming up?

    Regards,

    Greg

    #2
    Well, you probably already has solved this, but if someone else needs the same thing (like me), here what I did:

    Code:
     addEditorExitHandler(new EditorExitHandler()
            {
    
                @Override
                public void onEditorExit(EditorExitEvent p_event)
                {
                    int v_indexUltimColuna = getFields().length - 1 - (getCanRemoveRecords() == true ? 1 : 0);
                    if (p_event.getEditCompletionEvent().equals(EditCompletionEvent.TAB) && p_event.getRowNum() == getTotalRows() - 1
                        && p_event.getColNum() == v_indexUltimColuna)
                    {              
                      //Needs to be deferred to work!  Scheduler.get().scheduleDeferred(new ScheduledCommand()
                        {
    
                            @Override
                            public void execute()
                            {
                                startEditingNew(v_defaultRecord);
    
                            }
                        });
    
                    }
    
                }
            });

    Comment

    Working...
    X