Announcement

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

    a way to change field editor types in listgrid

    Hi,

    I want to specify 3 editor types (password, text and integer) in a certain ListGrid field. I saw 3 ways to do it:
    1) by definining CellRenderer (in this post: http://forums.smartclient.com/showthread.php?t=12013). I understand that cell renderer renders a cell view. How can it change the editor type using it? I am confused..

    2) by overriding getEditorType() in JSNI. I can't use the straight-forward implementation that returns "PasswordItem" or "TextItem", because in Integer field I need to return a text item with KeyPressFilter.
    The best way I found is to invoke a smartGWT function on my listGrid implementation. It had another problem: I couldn't get the edited row (getFocusRow() and getEventRow() return wrong values in certain scenarios: if you navigate with arrows and listgrid field contains a validation error)

    Code:
        protected native JavaScriptObject create()/*-{
            var config = this.@com.smartgwt.client.widgets.BaseWidget::getConfig()();
            var scClassName = this.@com.smartgwt.client.widgets.BaseWidget::scClassName;
    
            var widget = $wnd.isc[scClassName].create(config);
    //overwrite this method as an entry point to check the editorType
            widget.getEditorType = function (field, values) {
                if(field.masterIndex==2){
                    //run function on listgrid and set the editors and validators
                    $wnd.teststst(field.masterIndex);
                }
                var editorProperties = $wnd.isc.addProperties({},field,field.editorProperties);
                return $wnd.isc.DynamicForm.getEditorType(editorProperties, this);
            }
            this.@com.smartgwt.client.widgets.BaseWidget::doInit()();
            return widget;
        }-*/;
    3) override canEditCell() and set different editorType and validators on the valueField. It has a problem as (2): when grid contains errors, arrows navigation shows wrong editors.

    Code:
       protected boolean canEditCell(int rowNum, int colNum) {
            String fieldName = getFieldName(colNum);
            if (fieldName.equals("value")) {
             valueField.setEditorType(myRecord.getEditorType());
             valueField.setValidators(myRecord.getValidators());
            }
            return super.canEditCell(rowNum, colNum);
        }

    What is the preferred way? Please help me to continue from here


    thanks
    Last edited by philla; 4 Nov 2010, 03:13.

    #2
    Why can't you use ListGridField.setEditorType()?

    Comment


      #3
      ListGridField.setEditorType() sets editorType for column, I need to set it for cell (I show password/integer/text values in the same column)
      Last edited by philla; 4 Nov 2010, 05:34.

      Comment


        #4
        No support in this subject?
        Could you explain how to use CellRenderer to control editor?

        Comment


          #5
          In case you need more details:
          1) I use smartGWT2.3 and GWT2.1.0
          2) I run in a regular mode
          3) IE8.0, Windows XP / 2008
          4) I expect that canEditCell will change the editorType and validators of a cell, when user navigates with arrows and listGrid contains an error. They are changed in other cases, but not in this particular case.
          Actual behaviour: when row A contains validation error and user moves down with arrows, canEditCell is invoked several times with id of row A, then several times with the next row id, but the editorType and validators are remained as in the row A.

          5) According to javadoc, getEditorType on listGrid can be used to solve my problem:
          //> @method listGrid.getEditorType() ([A])

          // - can be overridden to provide a different specific form item type for some field based on
          // the record/field data.
          //
          However, it has the same bug as I described in point 4 regarding canEditCell.


          Should I add this problem to smartGWT issues list?
          Any response is appreciated.
          Last edited by philla; 9 Jan 2011, 00:51.

          Comment


            #6
            Hi, I'm wondering about the same thing:
            depending on a value in the Record, a field should show a different EditorType when being edited - so different editors per row, same column.

            We can assume here that the value which implies the editor does not change, so the editor would not change again after creation.

            ListGrid.getEditorType is not in SmartGWT SC_SNAPSHOT-2011-05-31.

            Comment


              #7
              Are we permitted to say "me too" on this forum?

              GridCellWidgetsSample.java is a great example of "per cell" rendering, but does not support editing.

              GridDependentSelectsSample.java shows a way to do "per cell" editing, but this method is only applicable to SelectItem's.

              With a little effort, "per cell" editing can be accomplished using GWT 2.2

              But with all its advantages, SmartGWT appears to be missing this basic piece of functionality.

              This is absolutely essential if I am to successfully convert my jsp app to SmartGWT.
              And in my case, the editor will change after creation, depending on the value of another column.

              Thanks for any help (for otherwise I'm pretty screwed...)
              Last edited by scottsplace; 26 Jun 2011, 09:05.

              Comment


                #8
                Hi All
                We've now added support for supplying custom FormItem properties dynamically per cell via a new API ListGrid.setEditorCustomizer().

                ListGridEditorCustomizer is a new interface with a "getEditor()" method, called when the user starts editing a row, allowing the developer to return a custom FormItem per cell (or for default behavior, return the "defaultProperties" available on the ListGridEditorContext object passed in).

                Here's a very crude sample usage which shows a SelectItem in every other record for some field:

                Code:
                        grid.setEditorCustomizer(new ListGridEditorCustomizer() {
                            
                            @Override
                            public FormItem getEditor(ListGridEditorContext context) {
                                
                                ListGridField field = context.getEditField();
                                
                                if ("f1".equals(field.getName())) {
                                    
                                    int rowNum = context.getRowNum();
                                    if (rowNum % 2 == 0) {
                                        return new TextItem();
                                    } else {
                                        return new SelectItem();
                                        
                                    }
                                }
                                // For all fields except "f1" rely on standard behavior 
                                return context.getDefaultProperties();
                            }
                        });
                This change will be present in the next nightly build (June 28 or greater).

                Regards
                Isomorphic Software

                Comment


                  #9
                  Wow!
                  Thanks for such a quick response, especially considering that I'm not a paying customer (yet)...

                  It works for most things quite well.

                  A couple of glitches that I've encountered (06-30-11 nightly):
                  1) For other defined ListGridField's, the setEditorType is ignored.
                  Easy workaround is to put all editors under this framework.

                  2) ListGridField "Changed Handlers" are no longer called. Easy enough to test - just add the following to the GridDependentSelectsSample showcase example:

                  Code:
                  localDataGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                    @Override
                    public FormItem getEditor(ListGridEditorContext context) {
                      return context.getDefaultProperties();
                    }
                  });
                  This last one is a show stopper.
                  I'll have to ask the boss about buying a support plan, but we're a very small company.
                  Last edited by scottsplace; 2 Jul 2011, 14:19.

                  Comment


                    #10
                    Fundamentally there were some issues with the getter for the "default" Form item properties which were responsible for these issues. These are fixed in our internal code base for the upcoming 2.5 release.

                    Comment


                      #11
                      Thanks guys, this works well!


                      I did seem to have some trouble with the value persisted by different editors to the ListGrid:

                      Example:
                      case ListGridFied of type String
                      for some row, we change the editor, which returns a different type (e.g. Date). It seems logical that I need to transform the editor's return type into the ListGridField's type (my real world types are something else).
                      I thought to use a ValueFormatter there, to parse the editor's datatype into the type of the ListGridField. The function got hit, but the value still was saved in the the editor's datatype.

                      I managed to workaround that by creating a new ListGridField, and in its EditorExitHandler, I put the user chosen value into the type of the original field.
                      That turns out to be even a better idea, as I don't have to re-transform that String value back to a Date onEditorEntered.

                      Comment


                        #12
                        That is what I was looking for,

                        Thanks !

                        Comment

                        Working...
                        X