@@ -335,9 +335,38 @@ export class MultipleSelectInstance {
335335 this . data = this . data . sort ( this . options . preSort ) ;
336336 }
337337
338+ if ( ! this . fromHtml ) {
339+ this . initHtmlRows ( ) ;
340+ }
341+
338342 this . dataTotal = setDataKeys ( this . data || [ ] ) ;
339343 }
340344
345+ protected initHtmlRows ( ) {
346+ this . elm . innerHTML = '' ;
347+ if ( ! this . data ) return
348+ this . data . forEach ( ( it : OptGroupRowData | OptionRowData ) => {
349+ console . log ( { it } )
350+ if ( it . type == 'optgroup' ) {
351+ const optgroup = document . createElement ( 'optgroup' ) ;
352+ optgroup . label = it . label ;
353+ ( it as OptGroupRowData ) . children . forEach ( ( opt : OptionRowData ) => {
354+ this . buildOption ( optgroup , opt ) ;
355+ } )
356+ this . elm . appendChild ( optgroup ) ;
357+ } else {
358+ this . buildOption ( this . elm , ( it as OptionRowData ) ) ;
359+ }
360+ } ) ;
361+ }
362+
363+ protected buildOption ( parent : HTMLElement , it : OptionRowData ) {
364+ const option = document . createElement ( 'option' ) ;
365+ option . value = it . value . toString ( ) ;
366+ option . text = it . text ;
367+ parent . appendChild ( option ) ;
368+ }
369+
341370 protected initRow ( elm : HTMLOptionElement , groupDisabled ?: boolean ) {
342371 const row = { } as OptionRowData | OptGroupRowData ;
343372 if ( elm . tagName ?. toLowerCase ( ) === 'option' ) {
@@ -1243,6 +1272,7 @@ export class MultipleSelectInstance {
12431272 isLazyProcess = true ;
12441273 this . dropElm ?. querySelector ( 'ul.ms-list' ) ?. remove ( ) ;
12451274 this . options . lazyData ( ) . then ( data => {
1275+ this . fromHtml = false ;
12461276 // when data is ready, remove spinner & update dropdown and selection
12471277 this . options . data = data ;
12481278 this . _isLazyLoaded = true ;
@@ -1553,7 +1583,7 @@ export class MultipleSelectInstance {
15531583 } else {
15541584 // when multiple values could be set, we need to loop through each
15551585 Array . from ( this . elm . options ) . forEach ( option => {
1556- option . selected = selectedValues . some ( val => val === option . value ) ;
1586+ option . selected = selectedValues . some ( val => val . toString ( ) === option . value ) ;
15571587 } ) ;
15581588 }
15591589
0 commit comments