Skip to content

Instantly share code, notes, and snippets.

@php-coder
Last active May 16, 2017 22:31
Show Gist options
  • Save php-coder/d3020e4d8d00b8c5befe755c46f06f1b to your computer and use it in GitHub Desktop.
Save php-coder/d3020e4d8d00b8c5befe755c46f06f1b to your computer and use it in GitHub Desktop.
How to do it in Thymeleaf?
Data from the database:
5 BMW Cars
2 Ford Cars
6 Fun NULL
1 Chess Sport
4 Football Sport
3 Rugby Sport
I'd like to show them as a <select> with <optgroup>'s **without** data transformation:
<select>
<optgroup label="Cars">
<option value="5">BMW</option>
<option value="2">Ford</option>
</optgroup>
<option value="6">Fun</option>
<optgroup label="Sport">
<option value="1">Chess</option>
<option value="4">Football</option>
<option value="3">Rugby</option>
</optgroup>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment