How to get current columns after column's order changed

Hi,
I created a form. When I load this form a list of records will be displayed. I can change column’s position by clicking and dragging the column. Can somebody tell me after I moved the column how can I get the columns in the new order on the screen? Is there any method to use?
I tried getFields() but they are not in the order same as it on the screen.

Thanks,

banff.moon:
how can I get the columns in the new order on the screen

What exactly do you mean with that?

Just guessing I would say you created a form in tableview, executed your solution and played around with the order of the columns.
In the end you’d like to get a list of columnnames in the order they are displayed on your screen…

If your elements are all named and my assuming is right, this will do the job:

var $form = arguments[0];
var $elements = forms[$form].elements.allnames;
       
if($elements.length > 0)
{
    $elements.sort(function(a,b){return forms[$form].elements[a].getLocationX() - forms[$form].elements[b].getLocationX()});
}

for(i = 0 ; i < $elements.length ; i++)
{
    application.output($elements[i])
}

If your elements aren’t (always) named, you should use the solutionmodel (think you tried that already).
You’ll need somewhat more code and be aware that there are different types of element-objects that have to be converted & combined into 1 array.
If you’ve managed to do that, the whole sorting part of the code above will remain the same.

var $form		= arguments[0];

if(solutionModel.getForm($form) == null) return;
	
var $smForm		= solutionModel.getForm($form);
var $smFields	= $smForm.getFields();
var $smButtons	= $smForm.getButtons();
var $smLabels	= $smForm.getLabels();
var $smElements = new Array();
	
for (var i = 0; i < $smFields.length; i++) {$smElements[$smElements.length] = $smFields[i]};
for (var i = 0; i < $smButtons.length; i++) {$smElements[$smElements.length] = $smButtons[i]};
for (var i = 0; i < $smLabels.length; i++) {$smElements[$smElements.length] = $smLabels[i]};

$smElements.sort(function(a,b){return a.x - b.x});
		
for (var i = 0; i < $smElements.length; i++) 
{
    application.output($elements[i])
}

Hope this is what you were looking for!

Thank you so much. This is what I want. I’ll try now…

mboegem:
What exactly do you mean with that?

That’s great. I got the columns. Now I’d like to ask another question. I used the second part of code (use solutionModel to get columns) because like what you said the elements are not always named. If I also need get the value list of each element what should I do?
I can get the property “valuelist” by using $elements*.valuelist based on your example code. Then how can I get the value list name?*
Thanks again,

banff.moon:
Then how can I get the value list name?

using $elements*.valuelist will get you a jsObject for the valuelist.*
using the valuelist-node from the solutionModel will bring you further.
In this case: $elements*.valuelist.name will return what you want.*

mboegem:

banff.moon:
Then how can I get the value list name?

using $elements*.valuelist will get you a jsObject for the valuelist.*
using the valuelist-node from the solutionModel will bring you further.
In this case: $elements*.valuelist.name will return what you want.[/quote]*
Thanks for your help.