0

we have used ng2-smart-table for our project and I have a request now where one of the select input list is dependent upon selection of another list. For instance, in the below example there are 2 Inputs (Country & Cities) and when User selects one of the Countries from drop down then the cities would get populated. So, whenever the user selects a different country then the Cities list would get populated with appropriates cities:

enter image description here

Could someone please let me know if this is possible in ng2-smart-table?

My current settings

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: [] }, } }

This is how the list is getting populated:

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 }); }

this.settings.columns.city.editor.config.list = cityOptions;

Deepak
  • 11
  • 1
  • 2

2 Answers2

0

To fetch click event try this way.

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

Using valuePrepareFunction() you will be able to get data.

Then you have to call API and bind into dropdown.

Sachin Shah
  • 4,503
  • 3
  • 23
  • 50
  • @Deepak Welcome :) – Sachin Shah Nov 05 '18 at 10:38
  • 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: [] }, } } – Deepak Nov 05 '18 at 10:43
  • Hi Sachin, thanks for following up. I was out of town and couldnt follow up. As i have provided my settings above. 'mode: internal' setting is used. Can you let me know how to bind the return value from Country to pass on to Cities? Amd again thanks a lot for your help. Really appreciate! – Deepak Nov 05 '18 at 10:45
  • @Deepak Can you please add above code in your question. So I can easily read it. – Sachin Shah Nov 05 '18 at 10:47
  • @Deepak I have also ask one question in comment under your question. Please reply of the question. So I'll be more clear on issue ... :) – Sachin Shah Nov 05 '18 at 10:48
  • Hi Sachin, I have added the code under question as you specified – Deepak Nov 06 '18 at 05:02
  • @Deepak Can you please update your status ? Still issue is open ? – Sachin Shah Nov 13 '18 at 11:11
0

Below solution work for me:

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'}
            ]
          }
        }
      }
    }
  };
Abdullah
  • 2,393
  • 1
  • 16
  • 29