ce icon indicating copy to clipboard operation
ce copied to clipboard

Need index of selected value for dropdown column type

Open mhstreta opened this issue 6 years ago • 3 comments

Can i get the index of selected value of column type dropdown/autocomplete along with value in any of the events?

For example:

columns:[
   {
     type: 'dropdown',
     source: [ 'Apples','Bananas','Carrots','Oranges','Cheese','Pears' ]
   },
   ...
   ...
}

So if selected source value from dropdown is 'Carrots', it should also return index of the item as '2'.

In this case, currently i can only get 'Carrots' in onchange and onafterchanges events.

mhstreta avatar Aug 17 '20 12:08 mhstreta

You can use a list of key-value objects as the source

[ 
	     {id: 1, name: 'Apples'},
	     {id: 2, name: 'Bananas'},
	     {id: 3, name: 'Carrots'},
	     {id: 4, name: 'Oranges'},
	     {id: 5, name: 'Cheese'},
	     {id: 6, name: 'Pears'}
]

The row information will contain the id instead of the text

alfr3dosv avatar Aug 17 '20 18:08 alfr3dosv

@alfr3dosv Thanks for the help. I didn't know that it is possible to supply with array of objects.

mhstreta avatar Aug 18 '20 08:08 mhstreta

You can try to get back using: table.options.columns[0].source.indexOf(yourValue);

But I imagine the K => V dropdown would do a better job.

pphod avatar Aug 19 '20 20:08 pphod