How can i sort my list in the choicebox below?
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
//Table Exists
info = db4.describeTable(items[i].getColumnText(2));
//Create a variable with all the field names for the dynamic SQL query.
for (var e = 0; e < info.length; ++e)
{
name = info[e].name;
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
else
{
//Table Does Not Exists, Loop to the next Table Name in the list.
alert("Table: " + items[i].getColumnText(2) + " does not exist in " + items[i].getColumnText(0) + "/" + items[i].getColumnText(1));
continue;
}
Kirix Support Forums
sort list in choicebox
8 posts
• Page 1 of 1
Re: sort list in choicebox
Use an ORDER BY clause in your SQL query. You can also use standard JavaScript functions to sort your result array. The SQL way is probably the best in this case.
Ben Williams
Kirix Support Team
Kirix Support Team
-
Ben - Kirix Support Team
- Posts: 525
- Joined: Mon Dec 19, 2005 6:29 am
Re: sort list in choicebox
Sorting the SQL query won't have any affect in my results. I am just using that to see if it exists. See I am using "info = db4.describeTable(items[i].getColumnText(2));" to get the field names. how do i sort that?
- abenitez77
- Registered User
- Posts: 143
- Joined: Fri Jan 21, 2011 12:42 pm
Re: sort list in choicebox
Put the table names into an array and then call Array.sort()
Ben Williams
Kirix Support Team
Kirix Support Team
-
Ben - Kirix Support Team
- Posts: 525
- Joined: Mon Dec 19, 2005 6:29 am
Re: sort list in choicebox
Tried that ...didn't work...see my code below.
function onButton5Clicked()
{
var db4
var i
var info = new Array;
//var info
var name
choiceboxFieldNames.clear();
// Multicolumn list selections
// Create Array of selected items in list.
var items = m_list.getSelectedItems();
for (var i in items)
{
// Create the connection
db4 = new DbConnection("mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
if (db4.isConnected())
{
//print("Connection Successful on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
//break;
}
else
{
print("Connection failed on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
continue;
}
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
//Table Exists
info = db4.describeTable(items[i].getColumnText(2));
info.sort();
//Create a variable with all the field names for the dynamic SQL query.
for (var e = 0; e < info.length; ++e)
{
name = info[e].name;
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
else
{
//Table Does Not Exists, Loop to the next Table Name in the list.
alert("Table: " + items[i].getColumnText(2) + " does not exist in " + items[i].getColumnText(0) + "/" + items[i].getColumnText(1));
continue;
}
}
HostApp.refresh();
}
function onButton5Clicked()
{
var db4
var i
var info = new Array;
//var info
var name
choiceboxFieldNames.clear();
// Multicolumn list selections
// Create Array of selected items in list.
var items = m_list.getSelectedItems();
for (var i in items)
{
// Create the connection
db4 = new DbConnection("mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
if (db4.isConnected())
{
//print("Connection Successful on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
//break;
}
else
{
print("Connection failed on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
continue;
}
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
//Table Exists
info = db4.describeTable(items[i].getColumnText(2));
info.sort();
//Create a variable with all the field names for the dynamic SQL query.
for (var e = 0; e < info.length; ++e)
{
name = info[e].name;
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
else
{
//Table Does Not Exists, Loop to the next Table Name in the list.
alert("Table: " + items[i].getColumnText(2) + " does not exist in " + items[i].getColumnText(0) + "/" + items[i].getColumnText(1));
continue;
}
}
HostApp.refresh();
}
- abenitez77
- Registered User
- Posts: 143
- Joined: Fri Jan 21, 2011 12:42 pm
Re: sort list in choicebox
Ok, I think i figured it out. This is working for me.
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
// Get the Field Names from a Table.
var flds = db4.describeTable(items[i].getColumnText(2));
// Put the field names into an Array.
for (var a = 0; a < flds.length; ++a)
{
ArrFlds[a] = flds[a].name;
}
// Sort the Array.
ArrFlds.sort();
//Put the field names from the Array into the choicebox for FieldNames to select from.
for (var e = 0; e < ArrFlds.length; ++e)
{
name = ArrFlds[e];
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
// Get the Field Names from a Table.
var flds = db4.describeTable(items[i].getColumnText(2));
// Put the field names into an Array.
for (var a = 0; a < flds.length; ++a)
{
ArrFlds[a] = flds[a].name;
}
// Sort the Array.
ArrFlds.sort();
//Put the field names from the Array into the choicebox for FieldNames to select from.
for (var e = 0; e < ArrFlds.length; ++e)
{
name = ArrFlds[e];
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
- abenitez77
- Registered User
- Posts: 143
- Joined: Fri Jan 21, 2011 12:42 pm
-
Ben - Kirix Support Team
- Posts: 525
- Joined: Mon Dec 19, 2005 6:29 am
Re: sort list in choicebox
I am able to add field names to a choicebox from a listbox. Now, I want to be able to select 2 different tables in my listbox and get only the fieldnames added to the choicebox that exists in both tables. How can I edit my code to make this work?
code:
//function to connect to server and retrieve Field Names for dropdown.
function onButton5Clicked()
{
var db4
var i
var ArrFlds = new Array;
//var info
var name
choiceboxFieldNames.clear();
// Multicolumn list selections
// Create Array of selected items in list.
var items = m_list.getSelectedItems();
for (var i in items)
{
// Create the connection
db4 = new DbConnection("mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
if (db4.isConnected())
{
//print("Connection Successful on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
//break;
}
else
{
print("Connection failed on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
continue;
}
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
// Get the Field Names from a Table.
var flds = db4.describeTable(items[i].getColumnText(2));
// Put the field names into an Array.
for (var a = 0; a < flds.length; ++a)
{
ArrFlds[a] = flds[a].name;
}
// Sort the Array.
ArrFlds.sort();
//Put the field names from the Array into the choicebox for FieldNames to select from.
for (var e = 0; e < ArrFlds.length; ++e)
{
name = ArrFlds[e];
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
else
{
//Table Does Not Exists, Loop to the next Table Name in the list.
alert("Table: " + items[i].getColumnText(2) + " does not exist in " + items[i].getColumnText(0) + "/" + items[i].getColumnText(1));
continue;
}
}
HostApp.refresh();
}
code:
//function to connect to server and retrieve Field Names for dropdown.
function onButton5Clicked()
{
var db4
var i
var ArrFlds = new Array;
//var info
var name
choiceboxFieldNames.clear();
// Multicolumn list selections
// Create Array of selected items in list.
var items = m_list.getSelectedItems();
for (var i in items)
{
// Create the connection
db4 = new DbConnection("mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
if (db4.isConnected())
{
//print("Connection Successful on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
//break;
}
else
{
print("Connection failed on - mssql://" + items[i].getColumnText(0) + ":1434/" + items[i].getColumnText(1));
continue;
}
// Check to make sure Table Exists in the DB.
var TblExists = db4.execute("SELECT Table_Name FROM information_schema.tables Where Table_Name = '" + items[i].getColumnText(2) + "'");
if (TblExists.hasNext())
{
// Get the Field Names from a Table.
var flds = db4.describeTable(items[i].getColumnText(2));
// Put the field names into an Array.
for (var a = 0; a < flds.length; ++a)
{
ArrFlds[a] = flds[a].name;
}
// Sort the Array.
ArrFlds.sort();
//Put the field names from the Array into the choicebox for FieldNames to select from.
for (var e = 0; e < ArrFlds.length; ++e)
{
name = ArrFlds[e];
choiceboxFieldNames.addItem(name.toUpperCase());
}
}
else
{
//Table Does Not Exists, Loop to the next Table Name in the list.
alert("Table: " + items[i].getColumnText(2) + " does not exist in " + items[i].getColumnText(0) + "/" + items[i].getColumnText(1));
continue;
}
}
HostApp.refresh();
}
- abenitez77
- Registered User
- Posts: 143
- Joined: Fri Jan 21, 2011 12:42 pm
8 posts
· Page 1 of 1
Return to Strata Help & Feedback