Results 1 to 4 of 4

Thread: Select Rows in Grid (only by click on checkbox, not by click on the row) in GXT3

  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2011
    Posts
    23
    Vote Rating
    0
      0  

    Default Select Rows in Grid (only by click on checkbox, not by click on the row) in GXT3

    Hello everybody,

    I have a grid with a CheckBoxSelectionModel, (1) I want to permitt only to checkboxes of the grid to select-deselct rows of the grid (no other ways) also (2) I dont't want to highlight the selected rows, in GXT3.

    Could anybody help me with any suggetsion.

    Kind regards

  2. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    413
    Answers
    20
    Vote Rating
    21
      0  

    Default

    Yes. We wanted and needed the same behavior. Here's our extension of CheckBoxSelectionModel - Please let me know if you have any issues with it.

    Just a head's up/caveat: the class name of the checkbox cell changed from beta3 to beta4 and since this class name isn't hard-coded anywhere as a public static final variable, you will need to be careful when upgrading GXT versions to ensure it hasn't changed again.

    Code:
    import com.google.gwt.dom.client.Element;
    import com.google.gwt.dom.client.NativeEvent;
    import com.sencha.gxt.core.client.IdentityValueProvider;
    import com.sencha.gxt.widget.core.client.event.RowClickEvent;
    import com.sencha.gxt.widget.core.client.event.RowMouseDownEvent;
    import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
    
    
    /**
     * This class extends GXT's CheckBoxSelectionModel<M> class and modifies two
     * behaviors from the parent class:
     *
     * 1.  It ignores row clicks with the mouse.  This forces the user to click the
     * actual checkbox in order to select the row.  This was done because it creates
     * sort of a bad behavior by automatically selecting the checkbox when the user
     * clicks anywhere on in the row.
     *
     * 2.  For mouse-down events on the row, it ignores the click unless the click
     * happens to be in the actual checkbox cell for that row.  I.e., it does not
     * propagate the event if the mouse-down event happens outside the checkbox
     * cell.  This ultimately provides the same functionality as #1 above.
     *
     * @param <M> the model object (Java POJO that adhears to the Java Bean
     * contract) represented by a row.
     */
    public class IgnoreRowClickCheckBoxSelectionModel<M> extends CheckBoxSelectionModel<M> {
    
    
      public IgnoreRowClickCheckBoxSelectionModel(IdentityValueProvider<M> identity) {
        super(identity);
      }
    
    
      @Override
      protected void handleRowClick(RowClickEvent event) { }
    
    
      @Override
      protected void handleRowMouseDown(RowMouseDownEvent event) {
    
    
        boolean left = event.getEvent().getButton() == NativeEvent.BUTTON_LEFT;
        Element target = event.getEvent().getEventTarget().cast();
    
    
        if (left && target.getClassName().equals("x-grid-row-checker")) {
          M model = listStore.get(event.getRowIndex());
          if (model != null) {
            if (isSelected(model)) {
              deselect(model);
            }
            else {
              select(model, true);
            }
          }
        }
      }
    }

  3. #3
    Ext GWT Premium Member
    Join Date
    Jun 2011
    Posts
    23
    Vote Rating
    0
      0  

    Default thanks

    Hi icfantv,
    thanks for your response, it works also for gxt3-rc.

  4. #4
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    413
    Answers
    20
    Vote Rating
    21
      0  

    Default

    You're welcome. Enjoy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •