After grid.removeAllColumns order of other columns are not right

I have a grid with a variety of configuration depending how the user select the parameters for the db query. So the first time all is ok, after if I change the parameters for query and grid.removeAllColumns the new configuration of grid is completely different from the correct orders.
The attachment uno if the first query, the attachment due is another query after a grid.removeAllColums and the attachment tre is the correct way that due should be.
18310427.png
18310430.png
18310433.png