Results 1 to 4 of 4

Thread: GXT ComboBox with disabled item

  1. #1
    Sencha User
    Join Date
    Dec 2013
    Posts
    3

    Default Answered: GXT ComboBox with disabled item

    Hi, I'm trying unsuccessfully to disable an option (item) of a ComboBox.
    I can't exclude the item from the list, only view disabled like this:
    Code:
    <html><body>
    
    
    <select>
      <option disabled="" value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="opel">Opel</option>
      <option value="audi">Audi</option>
    </select>
      
    </body>
    </html>
    Which is the best way to do it in GXT?

  2. Look:

    Code:
    combo.setCell(new AbstractCell<DbMountPosition>() {
                @Override
                public void render(Context context, Value value, SafeHtmlBuilder sb) {
        if(value.getName().equals("Volvo"){
     sb.appendHtmlConstant("<span  class="strike">" + value.getName() + "</div>");
    }
                   
                }
            });
    combo.addBeforeSelectionHandler(new BeforeSelectionHandler<DbMountPosition>() {
                @Override
                public void onBeforeSelection(BeforeSelectionEvent<DbMountPosition> event) {
                    // You can get the item with event.getItem();
                    // You can stop the event with event.cancel();
                    if(event.getItem().getName().equals("Volvo"){
                       event.cancel()
                   }
                }
            });
    CSS:
    Code:
    .strike {     text-decoration: line-through; }

  3. #2
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    49

    Default

    One way to do this would be to add a before selection handler, and call cancel on the item you want disabled. This would not change the appearance though, so if you wanted it grayed out you would need to customize the style.

  4. #3
    Sencha User
    Join Date
    Dec 2013
    Posts
    3

    Default

    I'm not able to find where "cancel" is.

  5. #4
    Sencha Premium Member
    Join Date
    Dec 2012
    Posts
    100
    Answers
    5

    Default

    Look:

    Code:
    combo.setCell(new AbstractCell<DbMountPosition>() {
                @Override
                public void render(Context context, Value value, SafeHtmlBuilder sb) {
        if(value.getName().equals("Volvo"){
     sb.appendHtmlConstant("<span  class="strike">" + value.getName() + "</div>");
    }
                   
                }
            });
    combo.addBeforeSelectionHandler(new BeforeSelectionHandler<DbMountPosition>() {
                @Override
                public void onBeforeSelection(BeforeSelectionEvent<DbMountPosition> event) {
                    // You can get the item with event.getItem();
                    // You can stop the event with event.cancel();
                    if(event.getItem().getName().equals("Volvo"){
                       event.cancel()
                   }
                }
            });
    CSS:
    Code:
    .strike {     text-decoration: line-through; }

Posting Permissions

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