Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

BooleanCell selection change on click when not in edit mode #166

Open
JoshClose opened this issue May 9, 2013 · 9 comments
Open

BooleanCell selection change on click when not in edit mode #166

JoshClose opened this issue May 9, 2013 · 9 comments

Comments

@JoshClose
Copy link

Is there a way to have the boolean cell when not in edit mode change the selection when clicking the checkbox? Right now I have to click it twice. Once to enable editing, and once to change the selection. I would like to be able to just click it if it's editable.

@wyuenho
Copy link
Contributor

wyuenho commented May 15, 2013

This was done to be consistent with all the other cell types. BooleanCell is really an odd ball because it really shouldn't have a difference between edit mode and display mode. This used to be the old behavior. There are actually many reasons why it is the way it is now, it has to do with keyboard nav and cross-browser issues. I'll see what I can do, but no promises of a quick fix tho.

@JoshClose
Copy link
Author

Thanks. This one is actually a big deal for my project.

@JoshClose
Copy link
Author

I was able to do this fairly easily. By just changing the model when the input was clicked.

var BooleanCell = Backgrid.BooleanCell = Cell.extend({

  /** @property */
  className: "boolean-cell",

  /** @property */
  editor: BooleanCellEditor,

  /** @property */
  events: {
      "click": "enterEditMode",
      "click input": "inputClick"
  },

  /**
     Renders a checkbox and check it if the model value of this column is true,
     uncheck otherwise.
  */
  render: function () {
    this.$el.empty();
    this.$el.append($("<input>", {
      tabIndex: -1,
      type: "checkbox",
      checked: this.formatter.fromRaw(this.model.get(this.column.get("name")))
    }));
    this.delegateEvents();
    return this;
  },

  inputClick: function (event) {
      var attributes = {};
      attributes[this.column.get("name")] = $(event.target).prop("checked");
      this.model.set(attributes);
  }

});

@ptheofan
Copy link

+1

would be nice to add an option for booleanCell to allow toggling on single click

@bengladwell
Copy link

@JoshClose - In my case, it wasn't really necessary to change the BooleanCell code. I just extended it in the column definition:

[
...
  {
    name: <column name>,
    cell: Backgrid.BooleanCell.extend({
      events: {
        'change input': function (e) {
          this.model.set(this.column.get('name'), e.target.checked);
        }
      }
    })
  }
]

In this case, I'm just disregarding edit mode.

@jkrehm
Copy link

jkrehm commented Dec 4, 2013

@bengladwell That works great for me, too. It doesn't allow for editable = false, but I think that could be added without much difficulty.

@tnat1031
Copy link

@bengladwell thanks, very helpful!

@RokGrdina
Copy link

@bengladwell Thank you, this was helpful

@amanpatel
Copy link

@bengladwell Thanks for the solution. Very clean.

@cloudflarearchive cloudflarearchive locked and limited conversation to collaborators Jun 27, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants