Announcement

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

    List Grid with custom editor issue

    Hi,

    I have a list grid and one of the column in list grid has a datasource bound ComboBoxItem. during edits it works great but once user is done editing and hit enter (or use mouse ) to select the value from pick list and if i try to get the record - grid record stay in edit mode and does not return selected value from editor as well.

    ListGrid code:
    final ListGridField gridSymbolField = new ListGridField("symbol");
    gridSymbolField.setEditorType(createLookupItem());

    final ListGridField gridNameField = new ListGridField("name");
    gridNameField.setCanEdit(false);

    grid.setDataSource(detailDataSource);
    grid.setAlternateRecordStyles(true);
    grid.setEmptyCellValue("-");
    grid.setAutoFetchData(true);
    grid.setCanEdit(true);
    grid.setCanGroupBy(false);
    grid.setAutoSaveEdits(false);
    // grid.setModalEditing(true);
    grid.setEditEvent(ListGridEditEvent.CLICK);
    grid.setListEndEditAction(RowEndEditAction.NEXT);
    grid.setFields(gridSymbolField , gridNameField);


    And lookup item object is:

    ListGridField symbolField = new ListGridField("symbol");
    ListGridField nameField = new ListGridField("name");
    final ComboBoxItem comboBoxItem = new ComboBoxItem();
    comboBoxItem.setOptionDataSource(dataSource);
    comboBoxItem.setPickListFields(symbolField, nameField);
    comboBoxItem.setDisplayField("symbol");


    now either i add any listener on ComboBoxItem like ChangedListener or on grid like addEditorExitHandler to get what user has selected from combox's picklist using
    ListGridRecord record = comboBoxItem.getSelectedRecord();

    This grid stay in edit mode and does not return selected value.

    Kindly advice.

    #2
    Unable to follow your description. Try again.

    Comment


      #3
      Hey! Sorry if i was not very clear in my question. I guess below description will give you more clear idea.

      So What i have is a List grid with multiple fields and one of the field has "Databound Dropdown List Grid" as editor.
      And the problem i have is when i try to get selected record from "Dropdown List Grid" using "getSelectedRecord();" method - Outer List grid's record stay in edit mode and i don't get selected record in my code.

      Example code:

      // ---------List Grid--------
      ListGrid grid = new ListGrid();
      grid.setDataSource(detailDataSource);
      grid.setAlternateRecordStyles(true);
      grid.setEmptyCellValue("-");
      grid.setAutoFetchData(true);
      grid.setCanEdit(true);
      grid.setCanGroupBy(false);
      grid.setAutoSaveEdits(false);
      grid.setModalEditing(true);
      grid.setEditEvent(ListGridEditEvent.CLICK);
      grid.setListEndEditAction(RowEndEditAction.NEXT);
      grid.addEditorExitHandler(new EditorExitHandler(){
      public void onEditorExit(final EditorExitEvent event) {
      // Please note comboBoxItem is public variable in real code
      comboBoxItem.getSelectedRecord();
      // PROBLEM: Nothing Happens - grid stay as editable

      }
      }

      // ---------List Grid Fields --------
      final ListGridField gridSymbolField = new ListGridField("symbol");
      gridSymbolField.setEditorType(
      ListGridField symbolField = new ListGridField("symbol");
      ListGridField nameField = new ListGridField("name");

      final ComboBoxItem comboBoxItem = new ComboBoxItem();
      comboBoxItem.setOptionDataSource(dataSource);
      comboBoxItem.setPickListFields(symbolField, nameField);
      comboBoxItem.setDisplayField("symbol");
      );

      final ListGridField gridNameField = new ListGridField("name");
      gridNameField.setCanEdit(false);

      // add fields to List Grid
      grid.setFields(gridSymbolField, gridNameField );

      Comment


        #4
        If you want to programmatically end editing, call endEditing()

        Comment


          #5
          I already tried to do so but no effect. Below line is the killer

          ListGridRecord record = comboBoxItem.getSelectedRecord();

          If i comment above line then it works fine and i can read value what gets in to grid field. But I need to get hold of the object which is being returned from editor.

          Do we have API to do something like:

          grid.getCell(row, col).getEditor().getSelectedRecord()

          Thanks for your valuable advises.

          Comment


            #6
            You're really not making it clear what you expect to happen. You are calling a getter method - what does this have to do with whether editing ends?

            Comment


              #7
              Sorry, may be i am not using right terminology but the problem is :

              In example code "comboBoxItem" is set as an editor in ListGrid and once use select something from picklist and i try to get hold of that object using "comboBoxItem.getSelectedRecord();", the list grid which has "comboBoxItem" as editor in one of the field stay editable.

              Ideally what should happen is : when user select something comboBoxItem's pick list and hit enter that row in list grid should stop editing and comboBoxItem.getSelectedRecord() should return me selected record for that field.

              Comment


                #8
                In a ComboBox, when the changed event, editorExit, or another event fires, the user may or may not have selected a record - the user may only have entered some characters that do not yet match a record. getSelectedRecord() may therefore return null. Again, if you want to end editing, you can call endEditing().

                If you need more help than this, you should purchase training or support.

                Comment


                  #9
                  Below exception occurs If you have data bound combo box as a editor in grid's field and you try to call getSelectedRecord().

                  Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): Object doesn't support this property or method
                  number: -2146827850
                  description: Object doesn't support this property or method
                  at com.smartgwt.client.widgets.form.fields.ComboBoxItem.getSelectedRecord(Native Method)

                  And same combo box works well if it is not used editor inside list grid. I don't understand this behavior?

                  Comment


                    #10
                    With any error, always post the basic information that anyone responding to your question would always need: relevant versions, stack trace captured from the Developer Console in IE, sample code (ideally, a minimal standalone testcase that is immediately runnable without external dependencies).

                    Comment


                      #11
                      Environment:
                      1. SmartGWT 1.1
                      2. GWt 1.7

                      Below is the code:

                      Issue. ListGridRecord rec = comboBoxItem.getSelectedRecord(); does not work.

                      -------------------------------------------------------------------------
                      public class GridEditorTest extends VLayout {
                      public GridEditorTest(){
                      super();

                      createGUI();

                      setWidth100();
                      setHeight100();
                      setLayoutMargin(10);
                      }

                      private void createGUI() {
                      ListGrid grid = new ListGrid();

                      final ListGridField rowNum = new ListGridField("rowNum", "No");
                      rowNum.setWidth(70);
                      rowNum.setCanEdit(false);
                      rowNum.setCellFormatter(new CellFormatter() {
                      public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                      return (rowNum + 1) + "";
                      }
                      });

                      final ListGridField gridSymbolField = new ListGridField("Test");
                      gridSymbolField.setEditorType(createComboBoxItem());

                      grid.setAlternateRecordStyles(true);
                      grid.setEmptyCellValue("-");
                      grid.setAutoFetchData(true);
                      grid.setCanEdit(true);
                      grid.setCanGroupBy(false);
                      grid.setAutoSaveEdits(false);
                      grid.setModalEditing(true);
                      grid.setCanRemoveRecords(true);
                      grid.setListEndEditAction(RowEndEditAction.NEXT);
                      grid.setFields(rowNum, gridSymbolField);

                      addMember(grid);
                      grid.startEditingNew();
                      }

                      private ComboBoxItem createComboBoxItem() {
                      final ComboBoxItem comboBoxItem = new ComboBoxItem();
                      comboBoxItem.setOptionDataSource(ItemSupplyXmlDS.getInstance());
                      comboBoxItem.setFilterLocally(false);
                      comboBoxItem.addChangedHandler(new ChangedHandler(){
                      public void onChanged(ChangedEvent event) {
                      // NOTHING happens and throw an error.
                      ListGridRecord rec = comboBoxItem.getSelectedRecord();
                      GWT.log("rec:" + rec, null);
                      }
                      });
                      return comboBoxItem;
                      }
                      }

                      class ItemSupplyXmlDS extends DataSource {

                      private static ItemSupplyXmlDS instance = null;

                      public static ItemSupplyXmlDS getInstance() {
                      if (instance == null) {
                      instance = new ItemSupplyXmlDS("supplyItemDS");
                      }
                      return instance;
                      }

                      public ItemSupplyXmlDS(String id) {

                      setID(id);
                      setRecordXPath("/List/supplyItem");
                      DataSourceIntegerField pkField = new DataSourceIntegerField("itemID");
                      pkField.setHidden(true);
                      pkField.setPrimaryKey(true);

                      DataSourceTextField itemNameField = new DataSourceTextField("itemName", "Item Name", 128, true);
                      DataSourceTextField skuField = new DataSourceTextField("SKU", "SKU", 10, true);

                      DataSourceTextField descriptionField = new DataSourceTextField("description", "Description", 2000);
                      DataSourceTextField categoryField = new DataSourceTextField("category", "Category", 128, true);
                      categoryField.setForeignKey("supplyCategoryDS.categoryName");

                      DataSourceEnumField unitsField = new DataSourceEnumField("units", "Units", 5);
                      unitsField.setValueMap("Roll", "Ea", "Pkt", "Set", "Tube", "Pad", "Ream", "Tin", "Bag", "Ctn", "Box");

                      DataSourceFloatField unitCostField = new DataSourceFloatField("unitCost", "Unit Cost", 5);
                      FloatRangeValidator rangeValidator = new FloatRangeValidator();
                      rangeValidator.setMin(0);
                      rangeValidator.setErrorMessage("Please enter a valid (positive) cost");

                      FloatPrecisionValidator precisionValidator = new FloatPrecisionValidator();
                      precisionValidator.setPrecision(2);
                      precisionValidator.setErrorMessage("The maximum allowed precision is 2");

                      unitCostField.setValidators(rangeValidator, precisionValidator);

                      DataSourceBooleanField inStockField = new DataSourceBooleanField("inStock", "In Stock");

                      DataSourceDateField nextShipmentField = new DataSourceDateField("nextShipment", "Next Shipment");

                      setFields(pkField, itemNameField, skuField, descriptionField, categoryField, unitsField,
                      unitCostField, inStockField, nextShipmentField);

                      setDataURL("ds/test_data/supplyItem.data.xml");
                      setClientOnly(true);
                      }
                      }
                      -------------------------------------------------------------------------

                      Comment


                        #12
                        Before doing anything else, try SmartGWT 1.2, there were fixes in this area.

                        Comment


                          #13
                          Originally posted by Isomorphic
                          Before doing anything else, try SmartGWT 1.2, there were fixes in this area.
                          Thanks dude! - I am gona give a try right now.

                          Comment


                            #14
                            Originally posted by rathiandi
                            Thanks dude! - I am gona give a try right now.
                            Hey! I can't get that version 1.2 working.. I get below mesage even although i downloaded evalution version.

                            "Attempt to use data source of type iscServer with out SmartClient Server option. Please either set or upgrade to either pro or enterprises"

                            Do i need to update some licence file or something?

                            Comment


                              #15
                              Hi!
                              I have the same problem and I has updated to smartGWT 1.2 but the error is still.

                              Code:
                              Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): Object doesn't support this property or method
                               number: -2146827850
                               description: Object doesn't support this property or method
                              	at com.smartgwt.client.widgets.form.fields.ComboBoxItem.getSelectedRecord(Native Method)
                              	at com.kreators.grassias.client.presenter.SalesInvoicePresenter$4.onChanged(SalesInvoicePresenter.java:109)
                              	at com.smartgwt.client.widgets.form.fields.events.ChangedEvent.dispatch(ChangedEvent.java:96)
                              	at com.smartgwt.client.widgets.form.fields.events.ChangedEvent.dispatch(ChangedEvent.java:1)
                              	at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:65)
                              	at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:53)
                              	at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:178)
                              	at com.smartgwt.client.core.DataClass.fireEvent(DataClass.java:189)] in http://localhost/grassias/grassias/hosted.html?grassias, line 8
                              Let me summarized what I want to do:

                              I have a ListGrid transactionListGrid.
                              I have ComboBoxItem itemComboBoxItem with optionDataSource and pickListFields.
                              transactionListGrid will use itemComboBoxItem in one of it's field as the editor.

                              When itemComboBoxItem changed, I want other property of selectedRecord in itemComboBoxItem shown (such as description, unit, etc).

                              Code:
                                  itemComboBoxItem.addChangedHandler(new ChangedHandler(){
                                      
                                      public void onChanged(ChangedEvent event){
                                          itemComboBoxItem.getSelectedRecord();
                                      }
                              
                                  });
                              It is work fine if the itemComboBoxItem is never use as editorType,
                              but when it is put in

                              Code:
                              transactionListGrid.getField("itemCode").setEditorType(itemComboBoxItem)
                              it will generate above error.

                              Any idea or alternative ways?

                              Thanks.

                              Comment

                              Working...
                              X