Author Topic: How to Add a Dropdown in Toolbar that Returns ID and Type on Selection  (Read 1786 times)

cui

  • Newbie
  • *
  • Posts: 11
    • View Profile
Hi everyone,

I want to add a dropdown menu in the toolbar where each option is represented by an object containing id, type, and title. Upon selection, I need to get both the id and type associated with that option. However, my current configuration does not work as expected.

Current Configuration
Here's how I've configured the dropdown:
Code: [Select]
{
  type: 'select',
  options: [
    {
      id: -1,
      type: 1,
      title: '默认视图', // This should be displayed in the dropdown
    },
  ],
  value: -1,
  listener: function () {
    console.error('select');
  },
}
However, this setup results in an error or does not correctly display the title nor returns the id and type upon selection.

Could anyone please guide me on how to achieve this? Specifically, how can I ensure that the dropdown displays the title and allows me to retrieve both id and type upon selection?
Any advice or pointers would be greatly appreciated.

Thank you in advance for your help!
Best regards

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6344
    • View Profile
Re: How to Add a Dropdown in Toolbar that Returns ID and Type on Selection
« Reply #1 on: December 31, 2024, 06:38:04 am »
you may need to add labelIndx and valueIndx properties in the toolbar dropdown item.

Format of options is documented in column.editor section which also applies to dropdown in toolbar.

https://paramquery.com/pro/api#option-column-editor

cui

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to Add a Dropdown in Toolbar that Returns ID and Type on Selection
« Reply #2 on: December 31, 2024, 11:57:00 am »
      {
        type: 'select',
        options: listViewMode.value,
        valueIndx: 'id',
        labelIndx: 'title',
        listener(val) {
          console.error('sselect', val)
        },
      }
The method you provided is effective. Thank you for your help!