# Sorting Array

**URL:** <https://forum.servoy.com/t/sorting-array/2246>\
**Category:** Classic Servoy\
**Created:** [July 14, 2004, 8:26am UTC](https://forum.servoy.com/t/sorting-array/2246 "2004-07-14T08:26:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 14, 2004, 8:26am UTC](https://forum.servoy.com/t/sorting-array/2246/1 "2004-07-14T08:26:34Z")

</div>

I am doing a getDataSetByQuery placing the results (a list of numbers) into an array, and then sorting the array as follows:

```auto
var queryStatement = "SELECT sgb_branch_nbr FROM sgb_branch";
var query = queryStatement;
var maxReturnedRows = 200;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,null,maxReturnedRows);
var branch_numbers = dataset.getColumnAsArray(1);
branch_numbers.sort();
application.setValueListItems( "sgbContactAccess", branch_numbers );   
controller.loadAllRecords();
}

```

The results are sorted, but the numbers are appearing as follows:  
121.0  
168.0  
181.0  
201.0

Does anyone know how to remove the ‘.0’

Thanks for any help

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 14, 2004, 8:27am UTC](https://forum.servoy.com/t/sorting-array/2246/2 "2004-07-14T08:27:50Z")

</div>

have you tried parseInt?

---

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 14, 2004, 8:39am UTC](https://forum.servoy.com/t/sorting-array/2246/3 "2004-07-14T08:39:35Z")

</div>

No, I haven’t. How/where should I use it. Sorry, I am a bit of a newbie where Java is concerned.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 14, 2004, 8:50am UTC](https://forum.servoy.com/t/sorting-array/2246/4 "2004-07-14T08:50:04Z")

</div>

what datatype does the column sgb\_branch\_nbr have? Is it an integer or a number?

---

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 14, 2004, 8:56am UTC](https://forum.servoy.com/t/sorting-array/2246/5 "2004-07-14T08:56:34Z")

</div>

It’s an integer.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 14, 2004, 9:04am UTC](https://forum.servoy.com/t/sorting-array/2246/6 "2004-07-14T09:04:06Z")

</div>

could you try this:

var branch\_numbers\_int = new Array();  
for ( var i = 0 ; i \< branch\_numbers.length ; i++ )  
{  
branch\_numbers\_int _= parseInt(branch\_numbers\*)  
\__}\*\_  
_and then work with branch\_numbers\_int?_

---

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 14, 2004, 9:37am UTC](https://forum.servoy.com/t/sorting-array/2246/7 "2004-07-14T09:37:48Z")

</div>

I have tried this:

```auto
var queryStatement = "SELECT sgb_branch_nbr FROM sgb_branch";
var query = queryStatement;
var maxReturnedRows = 200;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,null,maxReturnedRows);
var branch_numbers = dataset.getColumnAsArray(1);
var branch_numbers_int = new Array();
for (var i = 0; i < branch_numbers.length ; i++)
{
branch_numbers_int[i] = parseInt(branch_numbers[i])
}
branch_numbers_int.sort()
application.setValueListItems( "sgbContactAccess", branch_numbers_int);   
}

```

and I get:  
102.0  
103.0  
121.0  
etc.  
I have tried this:

```auto
var queryStatement = "SELECT sgb_branch_nbr FROM sgb_branch";
var query = queryStatement;
var maxReturnedRows = 200;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,null,maxReturnedRows);
var branch_numbers = dataset.getColumnAsArray(1);
branch_numbers.sort()
var branch_numbers_int = new Array();
for (var i = 0; i < branch_numbers.length ; i++)
{
branch_numbers_int[i] = parseInt(branch_numbers[i])
}
application.setValueListItems( "sgbContactAccess", branch_numbers_int);   
}

```

and I get the same result.  
I have also tried it without the sort:

```auto
var queryStatement = "SELECT sgb_branch_nbr FROM sgb_branch";
var query = queryStatement;
var maxReturnedRows = 200;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,null,maxReturnedRows);
var branch_numbers = dataset.getColumnAsArray(1);
var branch_numbers_int = new Array();
for (var i = 0; i < branch_numbers.length ; i++)
{
branch_numbers_int[i] = parseInt(branch_numbers[i])
}
application.setValueListItems( "sgbContactAccess", branch_numbers_int);   
}

```

and surprisingly, I still get the same result.  
Am I doing something wrong here?[/quote]

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 14, 2004, 9:50am UTC](https://forum.servoy.com/t/sorting-array/2246/8 "2004-07-14T09:50:56Z")

</div>

I have never played with “numbered” value lists…

Your value list has to be attached to some field. How is the number formatting of that field?

---

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 14, 2004, 10:01am UTC](https://forum.servoy.com/t/sorting-array/2246/9 "2004-07-14T10:01:33Z")

</div>

The valuelist is attached to the field sgb\_branch\_nbr (this is in a portal) and the field property is 0000

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 14, 2004, 11:48am UTC](https://forum.servoy.com/t/sorting-array/2246/10 "2004-07-14T11:48:16Z")

</div>

ok. forget my tips regarding parseInt. I have made a test solution and came up with the same results as you.

So the question has to be passed on to the Servoyans, since they build the value lists. I am also getting 281.0 and so on.

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [July 14, 2004, 1:54pm UTC](https://forum.servoy.com/t/sorting-array/2246/11 "2004-07-14T13:54:31Z")

</div>

check out:

> **[Number formatting for valuelists](https://forum.servoy.com/viewtopic.php?t=2392&highlight=)**
>
> var counter = controller.getMaxRecordIndex()+1; var ListArray = new Array(); for ( var i = 0 ; i \< counter ; i++ ) { ListArray\*=i+1;\* } application.setValueListItems('LoopSeqList',ListArray); This method functions as expected. The only...

you can use utils.numberFormat(Object number, Object fractions)  
inside the utils node of the editor.

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [July 20, 2004, 1:44pm UTC](https://forum.servoy.com/t/sorting-array/2246/12 "2004-07-20T13:44:15Z")

</div>

I am starting to add listings to my solution that are the result of a query. I want to be able to add a button for each record that I can attach to method to that would display a related form.

Is there any documentation regarding this issue. From everything I have read, this would be the best way to display large listings. I can run the query but I am unsure the the best way to display the result set to include a button.

Thanks,  
Erich

---

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 20, 2004, 1:53pm UTC](https://forum.servoy.com/t/sorting-array/2246/13 "2004-07-20T13:53:31Z")

</div>

If you place a button (or image) alongside the field(s) in the row on the form, the button will be displayed for each record. You can then attach a method to the button (or image).  
Note: If your list is diplayed in a portal, you will need to select the portal before inserting a button or image to the form. If not, then the button will not be displayed for each record.

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [July 20, 2004, 2:00pm UTC](https://forum.servoy.com/t/sorting-array/2246/14 "2004-07-20T14:00:44Z")

</div>

how do I map the query results into the fileds in the listing?

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Clive\_Sanders](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Clive\_Sanders](https://forum.servoy.com/u/Clive_Sanders)\
**Post date:** [July 20, 2004, 2:16pm UTC](https://forum.servoy.com/t/sorting-array/2246/15 "2004-07-20T14:16:05Z")

</div>

```auto
var queryStatement = "SELECT......
var query = queryStatement;
var maxReturnedRows = 200;
var dataset = databaseManager.getDataSetByQuery(forms.myForm.controller.getServerName(),query,null,maxReturnedRows);
var myVar = dataset.getcolumnAsArray(1);

```

Add extra myVar and increment (1) for each filed you are selecting.

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [July 20, 2004, 2:32pm UTC](https://forum.servoy.com/t/sorting-array/2246/16 "2004-07-20T14:32:08Z")

</div>

Excellent, thanks for your time.
