Announcement

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

    Cancel SelectionEvent in ListGrid

    Hi.

    ListGrid with some fields and one field defined as boolean. In the UI it is displayed as check-box (it will be used to collect records for mass or bulk update operation).

    We don't want to use this code(business requirements reasons):
    Code:
    grid.setSelectionType(SelectionStyle.SIMPLE);
    grid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
    What I want to achieve is to not highlight record if user only check a checkbox in listgrid.
    The reason is, that under listGrid we have detailviewer with additional data related to selected (highlighted) record -> and we do not want to always fetch this additional data only when checkbox was checked/unchecked.

    Is this possible ? Can i somehow distinguish if only checkbox cell was clicked and then cancel SelectionEvent.

    Regards,
    Fero

    #2
    Sounds like what you want is basically not selection at all. By adding another field of type "boolean" to your grid and setting canToggle:true, you'll have a field showing clickable checkboxes which is unrelated to selection.

    Comment


      #3
      Hi again,

      not sure if i explain correctly what i need. So i am posting modified showcase GridMassUpdateSample.
      Code:
          public Canvas getViewPanel() {
      
              Canvas canvas = new Canvas();
      
              final ListGrid countryGrid = new ListGrid();
              countryGrid.setWidth(500);
              countryGrid.setHeight(224);
              countryGrid.setCellHeight(22);
              countryGrid.setDataSource(CountryXmlDS.getInstance());
      
              ListGridField nameField = new ListGridField("countryName", "Country");
              ListGridField continentField = new ListGridField("continent", "Continent");
              ListGridField memberG8Field = new ListGridField("member_g8", "Member G8");
              //memberG8Field.setCanToggle(true);
              memberG8Field.setCanEdit(true);
              ListGridField populationField = new ListGridField("population", "Population");
              populationField.setType(ListGridFieldType.INTEGER);
              populationField.setCellFormatter(new CellFormatter() {
                  public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                      if(value == null) {
                          return null;
                      }
                      NumberFormat nf = NumberFormat.getFormat("0,000");
                      try {
                          return nf.format(((Number) value).longValue());
                      } catch (Exception e) {
                          return value.toString();
                      }
                  }
              });
              ListGridField independenceField = new ListGridField("independence", "Independence");
              countryGrid.setFields(nameField,continentField, memberG8Field, populationField, independenceField);
      
              countryGrid.setAutoFetchData(true);
              countryGrid.setAutoSaveEdits(false);
              canvas.addChild(countryGrid);
      
              return canvas;
          }
      My gird is not editable. Only one column (checkbox one) should be. Therefore i am using memberG8Field.setCanEdit(true); and countryGrid.setAutoSaveEdits(false);

      You can see (on the showcase) when you click on checkbox that related record is also highlighted.
      My question is: Can i forbid to select (highlight) record if user only checked/unchecked checkbox ?

      Calling memberG8Field.setCanToggle(true); does not help me.

      Regards
      Fero
      Last edited by geletkaf; 4 May 2013, 03:12.

      Comment


        #4
        A quick note to let you know we are looking at this.

        Regards
        Isomorphic Software

        Comment


          #5
          Any news about this issue?

          Comment


            #6
            The problem here is a subtle one. When a record is updated in the dataSource backing a listGrid, the updated record is automatically folded into the data set for the grid.
            If the original record was marked as selected, this selection is lost.

            This is a longstanding behavior, but we acknowledge it can be frustrating and as such have made a change to address this. As of the next nightly build (May 17th), there will be a new boolean attribute available on listGrids - "reselectOnUpdate". When set to true (the default), updated data will be automatically re-selected (if the original record was selected within the result set when an update operation completes).

            This change is available in the 9.0d branch

            Regards
            Isomorphic Software

            Comment


              #7
              Hi, i tried http://smartclient.com/builds/SmartGWT/3.1p/PowerEdition/2013-05-17 and i cannot find this flag on listgrid.
              Also my problem was not about reselecting records after update. My problem is to not select at all record when only checkbox is checked. So again:

              My gird is not editable. Only one column (checkbox one) should be. Therefore i am using memberG8Field.setCanEdit(true); and countryGrid.setAutoSaveEdits(false);

              You can see (on the showcase) when you click on checkbox that related record is also highlighted.
              My question is: Can i forbid to select (highlight) record if user only checked/unchecked checkbox ?

              Comment


                #8
                Yes - don't setSelectionAppearance(checkbox) if that isn't what you want.

                Instead, just add a boolean column of your own and setCanToggle(true) on it

                Comment


                  #9
                  Originally posted by Isomorphic View Post
                  Yes - don't setSelectionAppearance(checkbox) if that isn't what you want.

                  Instead, just add a boolean column of your own and setCanToggle(true) on it
                  I am not setting selectionApperance. I am using setCanToggle(true). But record is still highlighted. Tested with the latest nightly build (3.1p) and Firefox 18.0.2.

                  Comment


                    #10
                    Ok - you should be able to resolve this as follows:

                    Add a "cellMouseDown" handler to your grid. This will provide a notification which you can use to both toggle the value, and suppress the default behavior (selecting the row the user clicks)

                    Within this handler, check whether the user clicked in the boolean column. If so, call setEditValue(...) to toggle the value of your boolean field, and then saveAllEdits() to save the value.

                    Cancel the event to suppress the normal selection of the clicked row.

                    Note that you may need canEdit set to true, but you should have editEvent set to "none" to suppress default behavior of entering normal edit mode on click or doubleClick.

                    Let us know if that doesn't allow you to get things working.

                    Regards
                    Isomorphic Software

                    Comment


                      #11
                      Thank you ! The solution with "cellMouseDown" handler worked.

                      Regards,
                      Fero

                      Comment


                        #12
                        Originally posted by Isomorphic View Post
                        As of the next nightly build (May 17th), there will be a new boolean attribute available on listGrids - "reselectOnUpdate". When set to true (the default), updated data will be automatically re-selected (if the original record was selected within the result set when an update operation completes).

                        This change is available in the 9.0d branch
                        Could you please add it also to smartgwt-3.1p?
                        We just wanted to use it now and realized that was added to smartclient-9.0d and not to 8.3p.

                        Thank you

                        Comment


                          #13
                          Sorry, no, that was a feature not a fix.

                          You can use DataChanged and selectRecord() to do the same thing yourself if you are trying to stay on 3.1 a bit longer.

                          Comment

                          Working...
                          X