ionic picklist angular code example

Example: ionic picker

<ion-button expand="block" onclick="openPicker()">Show Single Column Picker</ion-button>

const defaultColumnOptions = [
      [
        'Dog',
        'Cat',
        'Bird',
        'Lizard',
        'Chinchilla'
      ]
    ]

    const multiColumnOptions = [
      [
        'Minified',
        'Responsive',
        'Full Stack',
        'Mobile First',
        'Serverless'
      ],
      [
        'Tomato',
        'Avocado',
        'Onion',
        'Potato',
        'Artichoke'
      ]
    ]

    async function openPicker(numColumns = 1, numOptions = 5, columnOptions = defaultColumnOptions){
      const picker = await pickerController.create({
        columns: this.getColumns(numColumns, numOptions, columnOptions),
        buttons: [
          {
            text: 'Cancel',
            role: 'cancel'
          },
          {
            text: 'Confirm',
            handler: (value) => {
              console.log(`Got Value ${value}`);
            }
          }
        ]
      });

      await picker.present();
    }

    function getColumns(numColumns, numOptions, columnOptions) {
      let columns = [];
      for (let i = 0; i < numColumns; i++) {
        columns.push({
          name: `col-${i}`,
          options: this.getColumnOptions(i, numOptions, columnOptions)
        });
      }

      return columns;
    }

    function getColumnOptions(columnIndex, numOptions, columnOptions) {
      let options = [];
      for (let i = 0; i < numOptions; i++) {
        options.push({
          text: columnOptions[columnIndex][i % numOptions],
          value: i
        })
      }

      return options;
    }

Tags:

Html Example