依赖下拉功能ng2-smart-table

时间:2018-10-29 07:16:45

标签: angular6 ng2-smart-table

我们在项目中使用了ng2-smart-table,现在我有一个请求,其中选择输入列表之一取决于对另一个列表的选择。 例如,在下面的示例中,有2个输入(国家和城市),并且当用户从下拉列表中选择国家(地区)之一时,将填充城市。因此,每当用户选择其他国家/地区时,“城市”列表将填充相应的城市:

enter image description here

有人可以让我知道ng2-smart-table中是否可行吗?

我当前的设置

myGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

这是列表的填充方式:

mode: internal, country: { title: 'Country', type: 'html', valuePrepareFunction: (cell, row) => { return cell }, editor: { type: 'list', config: { list: [] }, } }, city: { title: 'City', type: 'html', editor: { type: 'list', config: { selectText: 'Select the Location to see options...', list: [] }, } }

let countryAll = this.countryService.getAll(); let cityAll =this.cityService.getAll();

const countryOptions = []; for (const l of this.countryAll) { locationOptions.push({ value: l.name, title: l.name }); }

this.settings.columns.country.editor.config.list = countryOptions;

const cityOptions = []; for (const l of this.cityAll) { locationOptions.push({ value: l.name, title: l.name }); }

2 个答案:

答案 0 :(得分:0)

要获取点击事件,请尝试这种方式。

paymentStatus: {
    title: 'Country',
    type: 'html',
    valuePrepareFunction: (cell, row) => { return row },
    editor: {
      type: 'list',
      config: {
        list: [{ value: 1, title: 'India' }, { value: 2, title: 'Canada' }]
      }
    }
  },

使用 valuePrepareFunction(),您将能够获取数据。

然后,您必须调用API并绑定到下拉列表中。

答案 1 :(得分:0)

以下对我有用的解决方案:

enter image description here

public settings = {
    actions: {
      position: 'right'
    },
    columns: {
      ctg_name: {
        title: 'Category',
      },
      ctg_visible: {
        title: 'Visible',
        editor: {
          type: 'list',
          config: {
            selectText: 'Select',
            list: [
              {value: '1', title:'True'},
              {value: '0', title:'False'}
            ]
          }
        }
      }
    }
  };

相关问题