To create optgroup in dynamic cascade you have to have query result to have value 'optgroup' and the usual text will be optgroup name.
e.g. if you have the following records with text and value, red and green will be optgroups:
red - optgroup
a -1
b -2
green -optgroup
c -3
d -4
Not very easy to do in query, implementation from normal select dynamic is much better.