Dave Hayes
Dave Hayes

Reputation: 56

Reloading w2ui's grid.columns.editable.items if the field is a combo box

I'm trying to alter the "items" array attached to a combo box inside an editable field of w2ui's grid after the grid has been initially rendered.

To demonstrate my issue I've set up a jsfiddle taken from the "grid inline editing" demo here:

http://jsfiddle.net/8dkdoc4p/5/

and since some box appeared saying I must include code (why?) here's conceptually what I am trying to do. Note that this won't make too much sense unless you've seen this grid demo: http://w2ui.com/web/demos/#!grid/grid-21

function alterComboBox() {
   people.push({ id: myid, text: "ID " + myid});
   myid++;
   w2ui['grid'].refresh();
}

The idea is to add another item for the combo box at run time and have the grid actually display the new item as another option.

Thanks in advance!

Upvotes: 0

Views: 1695

Answers (1)

Mike Scotty
Mike Scotty

Reputation: 10782

You have to re-assign the global record "people" to the w2ui grid columns after altering the record.

In case of your "select" field, you also have to call the render() method.

http://jsfiddle.net/8dkdoc4p/8/

var myid = 22;
function alterComboBox() {

    people.push({ id: myid, text: "ID " + myid});
  myid++;
  w2ui['grid'].getColumn('list').editable.items = people;
  w2ui['grid'].getColumn('combo').editable.items = people;
  w2ui['grid'].getColumn('select').editable.items = people;
  w2ui['grid'].getColumn('select').render();
  //w2ui['grid'].refresh(); // no need!
}

Upvotes: 1

Related Questions