[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Client side array sort

Asked by PT001 in JavaScript

I have a page that I'm trying to let the user sort the information.  It half works.  I can't seem to figure out the other half.  But that's the fun of it.  Anyhow, I was hoping someone out there could look at my code and offer a suggestion or two.  

The array is built during a pull from a db using SQL server.  That part runs alright.  The pull takes 2-5 mins so I was hoping to be able to sort the info on the client side.  

Below is a simple copy of the page I'm working with.  

<%@ LANGUAGE="VBSCRIPT" %>

<html>
<head>
<title>Test Search</title>

</head>

<body>
<SCRIPT Language="JavaScript">
// sort varibles
var lastSortBy = -1;  
var sortGT = 1;   // sort forwards
var sortLT = -1;  // reverse sort

var sortStyle = new Array(" sorted <i>in reverse</i> by "," **impossible** "," sorted by ");  

function fnOTSRecord( id, wo, pon, fnp, DS1_SYSID, City_Pair, WOSec)
{
    this.id                        = id;
    this.WorkOrder            = wo;
    this.pon                  = pon;
    this.fnp                  = fnp;
    this.DS1_SYSID            = DS1_SYSID;
    this.City_Pair            = City_Pair;
    this.WOSection            = WOSec;
    //alert("Constructing OTSRecord:\n" + id + "\n" + wo + "\n" + pon + "\n" + fnp);
}


var aOTSRecords = new Array(
    new fnOTSRecord('2425','6817','02410.201','1','3394','AUS  LAD','Remarks'),
    new fnOTSRecord('2425','6817','02410.201','1',1,'AUS  LAD','Remarks'),
    new fnOTSRecord('6844','9587','03394','2',2,'DET  COL','Details'),
    new fnOTSRecord('6845','009587','03394','3',3,'DET  COL','Details'),
    new fnOTSRecord('14226','13393','05388','4',4,'HSN  AUS','Routing'),
    new fnOTSRecord('14271','013420','05411','5',5,'STC  CHC','Details'),
    new fnOTSRecord('33943','22637','10172.1   01D','6',6,'ORL  BAL','Details'),
    new fnOTSRecord('33944','22638','10172.5','7',7,'DCA  BAL','Details'),
    new fnOTSRecord('33945','22639','10173.1   01D','8',8,'ORL  BAL','Details'),
    new fnOTSRecord('33946','22640','10173.5','9',9,'DCA  BAL','Details'),
    new fnOTSRecord('34804','23145','13375.1   01A','10',10,'DLS  SFS','Remarks'),
    new fnOTSRecord('39756','25750','01965     01D','11',11,'AUS  EPO','Remarks'),
    new fnOTSRecord('39757','025750','01965     01D','13',12,'AUS  EPO','Remarks'),
    new fnOTSRecord('41028','026414','02410.201','12',13,'AUS  LAD','Details'),
    new fnOTSRecord('41028','026414','02410.201','14',14,'AUS  LAD','Remarks'),
    new fnOTSRecord('41561','26689','12201     01D','15',15,'SDO  CHI','Remarks'),
    new fnOTSRecord('41561','26689','12201     01D','17',16,'SDO  CHI','Routing'),
    new fnOTSRecord('41643','26738','02410.201','16',17,'AUS  LAD','Routing'),
    new fnOTSRecord('41644','026738','02410.201','18',18,'AUS  LAD','Details'),
    new fnOTSRecord('41644','026738','02410.201','20',19,'AUS  LAD','Remarks'),
    new fnOTSRecord('41645','026738','02410.201','19',20,'AUS  LAD','Details'),
    new fnOTSRecord('63394','40528','23874.1','','15691','INS  CHT','Details'),
    new fnOTSRecord('67496','43394','27136','','19435','NYC  LAP','Details')    
);


// functions to sort
function fnSortByID( arg1, arg2 )
{
    if( arg1.ID == arg2.ID ) return 0;
    return ( parseInt(arg1.ID) < parseInt(arg2.ID) ) ? sortLT : sortGT;
}
function fnSortByWorkOrder( arg1, arg2 )
{
    if( arg1.WorkOrder == arg2.WorkOrder ) return 0;
    return ( parseInt(arg1.WorkOrder) < parseInt(arg2.WorkOrder) ) ? sortLT : sortGT;
}
function fnSortByPon( arg1, arg2 )
{
    if( arg1.pon == arg2.pon ) return 0;
    return ( arg1.pon < arg2.pon ) ? sortLT : sortGT;
}
function fnSortByFnp( arg1, arg2 )
{
    if( arg1.fnp == arg2.fnp ) return 0;
    return ( parseInt(arg1.fnp) < parseInt(arg2.fnp) ) ? sortLT : sortGT;
}
function fnSortByDS1( arg1, arg2 )
{
    if( arg1.DS1_SYSID == arg2.DS1_SYSID ) return 0;
    return ( arg1.DS1_SYSID < arg2.DS1_SYSID ) ? sortLT : sortGT;
}
function fnSortByCity_Pair( arg1, arg2 )
{
    if( arg1.City_Pair == arg2.City_Pair ) return 0;
    return ( arg1.City_Pair < arg2.City_Pair ) ? sortLT : sortGT;
}
function fnSortByWOSection( arg1, arg2 )
{
    if( arg1.WOSection == arg2.WOSection ) return 0;
    return ( arg1.WOSection < arg2.WOSection ) ? sortLT : sortGT;
}

// Array of sort functions
aSortFuncs = new Array( fnSortByID, fnSortByWorkOrder, fnSortByPon, fnSortByFnp,
                       fnSortByDS1, fnSortByCity_Pair, fnSortByWOSection);        
// Array of Field Names
aSortByNames = new Array( "ID", "Work Order", "PON", "FNP", "DS1 SYSID",
                                    "City Pair", "WO-Section" );

//alert("sortGT & sortLT:\n" + sortGT + "\n" + sortLT);
function sortBy( fldNum )
{
alert("sortGT & sortLT:\n" + sortGT + "\n" + sortLT + "\n" + fldNum + "\n" + lastSortBy  );
    if ( fldNum != lastSortBy )
    {
        sortGT = 1;
        sortLT = -1;
        lastSortBy = fldNum;
    } else {
        sortGT = - sortGT;
        sortLT = - sortLT; // reverse the sort
    }
 
 //   alert("sortGT & sortLT:\n" + sortGT + "\n" + sortLT + "\n" + fldNum + "\n" + lastSortBy + "\n" + parseInt(curItem.id) );
    aOTSRecords.sort( aSortFuncs[fldNum] );  //sort

    // displaying results    
    //parent.Display.document    
    document.open( ); // clears frame and prepares for (re)write...
    document.write( "<BODY bgColor=yellow>\n<CENTER>\n<H3>List of OTS orders "
             + sortStyle[sortGT+1] + aSortByNames[fldNum] + "</H3><P>\n" );
    document.write( "<!-- <FONT Size='-1'><I>Click on a column title to sort by that column; click again to reverse the sort.</I></FONT>\n -->");
    document.write( "<TABLE Width='100%' Border=0 CellPadding=3 bgColor=lightgreen>\n<TR>\n" );
    for( col = 0; col < aSortByNames.length; ++col )
    {
        document.write( "    <TH><A HREF='javascript:sortBy(" + col
                 + ")'>" + aSortByNames[col] + "</A></TH>\n" );
    }
    document.write( "</TR>\n" );
    for( row = 0; row < aOTSRecords.length; ++row )
    {
        curItem = aOTSRecords[row];
        document.write( "<TR>\n" );      
        document.write( "    <TD>" + parseInt(curItem.id) + "</TD>\n" );
        document.write( "    <TD>" + curItem.WorkOrder + "</TD>\n" );
        document.write( "    <TD>" + curItem.pon + "</TD>\n" );
        document.write( "    <TD>" + curItem.fnp + "</TD>\n" );
        document.write( "    <TD>" + curItem.DS1_SYSID + "</TD>\n" );
        document.write( "    <TD>" + curItem.City_Pair + "</TD>\n" );
        document.write( "    <TD>" + curItem.WOSection + "</TD>\n" );
        document.write( "</TR>\n" );
    }
    document.write( "</TABLE>\n<P><HR>" );
    document.write(aSortFuncs[5] + "<br>");
    document.write (aOTSRecords[5].id + "</body>\n");
    document.close( );
    alert("sortGT & sortLT:\n" + sortGT + "\n" + sortLT + "\n" + fldNum + "\n" + lastSortBy + "\n" + parseInt(curItem.id) );
}

sortBy(0);

</SCRIPT>
</body>
</html>
[+][-]05/30/03 12:25 PM, ID: 8616751Accepted Solution

Your question has an Asker Certified™ answer! PT001 verified that this solution worked for them--which means it will likely work for you, too. Click to view the solution free for 30-days now.

About this solution

Zone: JavaScript
Sign Up Now!
Solution Provided By: amit_g
Participating Experts: 2
Solution Grade: A
 
[+][-]05/30/03 11:06 AM, ID: 8616156Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/30/03 11:11 AM, ID: 8616200Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/30/03 12:42 PM, ID: 8616842Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/30/03 01:58 PM, ID: 8617239Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20100608-EE-VQP-165