Author Topic: I want to change select.options in editorBegin, but it is not reflected.  (Read 2097 times)

ohbayashi

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 41
    • View Profile
I want to change select.options in editorBegin, but it is not reflected.
How should the optimal coding be?

colModel ("ID1" to "ID4")
Code: [Select]
colModel = [
  { title: "ID1", dataIndx: "id1", editable: false },
  { title: "NM1", dataIndx: "name1",
    editor: {
      type: "select",
      labelIndx: "name",
      valueIndx: "id",
      prepend: { "": "-- select --" },
      options: [],
      mapIndices: { "id": id1, "name": name1 }
    }
   },
  { title: "ID2", dataIndx: "id2", editable: false },
  { title: "NM2", dataIndx: "name2" },
    editor: {
      type: "select",
      labelIndx: "name",
      valueIndx: "id",
      prepend: { "": "-- select --" },
      options: [],
      mapIndices: { "id": id2, "name": name2 }
    }
   },
]

Grid Events.
Code: [Select]
                editorBegin: function (evt, ui) {
                    this.showLoading();
                    var id = ui.dataIndx;
                    if (!id.match(/name[2-4]/)) { return };

                    var parentId = parseInt(id.replace(/name/g, "")) - 1,
                        val = ui.rowData["id" + parentId];
                    if (!val) { return };

                    var col = this.getColumn({ dataIndx: id });
                    $.getJSON("/api/names_select/" + val, function (dataJSON) {
                        col.editor.options = dataJSON.names;
                    })
                    // this.refreshCell({ dataIndx: id });
                },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
As of now, select list options can be set synchronously but not asynchronously after editor is created.

Please check this if you need to set select list options asynchronously before editor is created:

https://paramquery.com/pro/demos/edit_select

Please use autocomplete if you need to change options asynchronously after editor is created.

https://paramquery.com/pro/demos/editing_custom

ohbayashi

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 41
    • View Profile
We decided to correspond with before create.
Thank you.