tabalinas / jsgrid-php

Sample project for jsgrid with PHP REST-service
MIT License
91 stars 48 forks source link

update "Select" field #11

Closed hk298 closed 8 years ago

hk298 commented 8 years ago

The PHP sample uses two tables: clients and countries, and the clients grid has a country drop down box. Now I'd like to have a grid for countries as well and display both in a tab. I got that working. However, when I change a country name, I'd like the clients grid to update and display the new value.

Below is a code snippet. The event fires and I do get a new "countries" array. However, how do I convince the clients grid displayed in the other tab to update? I tried several things to no avail.

var countries;

$(function() {

  $.ajax({
    type: "GET",
    url: "/grid/dbTable1.php"
  }).done(function(array) {

    countries = array;
    countries.unshift({ id: "0", name: "" });

    $("#jsGridClients").jsGrid({
      height: "90%",
      //----  cut  ----
    });
  });

  $("#jsGridCountries").jsGrid({

    onItemUpdated: function(args) {
      $.ajax({
        type: "GET",
        url: "/grid/dbViper2.php"
      }).done(function(array) {
        trunks = array;
        trunks.unshift({ id: "0", name: "" });
        //$("#jsGridViperDestinations").jsGrid("fieldOption", "trunk", trunks)
        //$("#jsGridViperDestinations").jsGrid("loadData");
        //$("#jsGridViperDestinations").jsGrid("render");
        //$("#jsGridViperDestinations").jsGrid("refresh");
      });
    },
tabalinas commented 8 years ago

Setting the option of select field should do the trick (as far as I understand your case). The thing is this line is incorrect:

$("#jsGridViperDestinations").jsGrid("fieldOption", "trunk", trunks)

You missed the field option name parameter (3rd), please checkout docs http://js-grid.com/docs/#fieldoptionfieldnamefieldindex-optionname-optionvalue.

hk298 commented 8 years ago

Yes!! Now it works, thanks. $("#jsGridViperDestinations").jsGrid("fieldOption", "trunk", "items", trunks)

tabalinas commented 8 years ago

You are welcome!