-1
Hello, I have a state field (UF) that is as dropdown and would like to sort it (by name). Could you please give me a north? My code is like this today:
estados = [
{label: 'Acre', value: 'AC'}, {label: 'Amazonas', value: 'AM'}, {label: 'Amapa', value: 'AP'},
{label: 'Pará', value: 'PA'}, {label: 'Roraima', value: 'RR'}, {label: 'Rondonia', value: 'RO'},
{label: 'Tocantins', value: 'TO'}, {label: 'Rio Grande do Sul', value: 'RS'}, {label: 'Santa Catarina', value: 'SC'},
{label: 'Paraná', value: 'PR'}, {label: 'São Paulo', value: 'SP'}, {label: 'Rio de Janeiro', value: 'RJ'},
{label: 'Minas Gerais', value: 'MG'}, {label: 'Espirito Santo', value: 'ES'}, {label: 'Goiás', value: 'GO'},
{label: 'Mato Grosso do Sul', value: 'MS'}, {label: 'Mato Grosso', value: 'MT'}, {label: 'Distrito Federal', value: 'DF'},
{label: 'Bahia', value: 'BA'}, {label: 'Sergipe', value: 'SE'}, {label: 'Alagoas', value: 'AL'},
{label: 'Paraíba', value: 'PB'}, {label: 'Piauí', value: 'PI'}, {label: 'Pernambuco', value: 'PE'},
{label: 'Rio Grande do Norte', value: 'RN'}, {label: 'Maranhão', value: 'MA'}, {label: 'Ceará', value: 'CE'}];
And in HTML it’s like this:
<p-dropdown [options]="estados" [autoWidth]="false" placeholder="UF"></p-dropdown>
Again, could you please take a north? Thank you!
As in order by name??
– LeAndrade
Do you see that in the array the names (label) are all out of order? I would sort by name. If it were via select, I would order by field. That’s exactly what I wanted to do in this array.
– Victor Freidinger
You want to order the label Is this alphabetical order? Like
Acre, Alagoas, Amapa, Amazonas, etc...
– LeAndrade
Exactly, @Le
– Victor Freidinger
But the data is static, inside a variable?
– LeAndrade
Yes, the data is static as shown above. They are within this array 'states'.
– Victor Freidinger
Because you don’t order them right there in alphabetical order?
– LeAndrade
In this case it would work because there are no more states, but, if they were names of people, for example, I would have to go out looking for where to order it?
– Victor Freidinger
I don’t understand, the options would not be fixed, would receive new values?
– LeAndrade
Yes, the options are fixed. And I want to order it, is it possible? You can help?
– Victor Freidinger
There is something like: Array := [here all the contents of the array] Array := Array.Sort() ?
– Victor Freidinger