0

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!

Dave Hayes
  • 56
  • 7

1 Answers1

1

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!
}
Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Ferrybig Feb 18 '16 at 13:57
  • Thank you. Exactly what I needed. It would be nice to see this example in the documentation too. – Dave Hayes Feb 18 '16 at 22:31