Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 17th, 2005, 09:29 AM
Friend of Wrox
Points: 7,425, Level: 36
Points: 7,425, Level: 36 Points: 7,425, Level: 36 Points: 7,425, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,524
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default sorted table

Looking at this javascript, is the table that is built already sorted?

I am trying to sort the table with my MySQL hit (which the table gets its data from) into newest record first, but i think it has already been sorted by the javascript when it is built.

Heres my ASP MySQL Hit (this works fine in MySQL Control Center):

Set rs=con.execute("select * from trip_master where agencyid = '"&agencyid&"' and newdate > '" &new_date& "' and regular_trip <> 'Cancelled' order by pri_key desc limit "&vara&",50")

Heres my javascript:

<script language="Javascript">
<!--
var a=new Array();
var arr=new Array();
var seq=new Array();

str="<%=str%>"
tablecolour="<%=tablecolour%>"
trcolour1="<%=trcolour1%>"

function searchmytrip(df)
{
searchname=df.searchname.value;
searchagent=df.searchagent.value;
document.form.action = "/beaver/asp/mytrip.asp?searchagent=" + searchagent + "&searchname=" + searchname;
document.form.submit();
}
function searchagain(df)
{
searchname=df.searchname.value;
searchagent=df.searchagent.value;
document.searchform.action = "/beaver/asp/mytrip.asp?searchagent=" + searchagent + "&searchname=" + searchname;
document.searchform.submit();
}
function winopen(temp)
{
    temp="Cryptic.asp?1A=RT" + temp
    oCryp = window.open(temp,'Cryptic','width=700,height=450,s crollbars=yes,resizable=yes,top=50,left=50,menubar =no,status=no');
}


function load()
{
    a=str.split("~");
    for(i=0;i<a.length-1;i++)
    {
        arr[i]=a[i].split("^");
    }
    sortAsc(6,'d');
}
function sortAsc(sub,dtype)
{

    var tmpArr=new Array();
    var arrQa=new Array();
    for(i=0;i<arr.length;i++)
    {
        tmpArr[i]=arr[i][sub];
        arrQa[i]=arr[i][1];
        seq[i]=i;
    }

    var tmp;
    var tmp1;
    for(j=0;j<tmpArr.length;j++)
    {
        for(k=0;k<tmpArr.length-1;k++)
        {

            if(dtype=='i')
            {
                if(parseInt(tmpArr[k])>parseInt(tmpArr[k+1]))
                {
                    tmp=tmpArr[k+1];
                    tmpArr[k+1]=tmpArr[k];
                    tmpArr[k]=tmp;

                    tmpQa=arrQa[k+1];
                    arrQa[k+1]=arrQa[k];
                    arrQa[k]=tmpQa;

                    tmp1=seq[k+1];
                    seq[k+1]=seq[k];
                    seq[k]=tmp1;
                }
                else if(parseInt(tmpArr[k])==parseInt(tmpArr[k+1]))
                {
                    if(arrQa[k]>arrQa[k+1])
                    {
                        tmp=tmpArr[k+1];
                        tmpArr[k+1]=tmpArr[k];
                        tmpArr[k]=tmp;

                        tmpQa=arrQa[k+1];
                        arrQa[k+1]=arrQa[k];
                        arrQa[k]=tmpQa;

                        tmp1=seq[k+1];
                        seq[k+1]=seq[k];
                        seq[k]=tmp1;
                    }
                }
            }

            if(dtype=='s')
            {
                if(tmpArr[k]>tmpArr[k+1])
                {
                    tmp=tmpArr[k+1];
                    tmpArr[k+1]=tmpArr[k];
                    tmpArr[k]=tmp;

                    tmpQa=arrQa[k+1];
                    arrQa[k+1]=arrQa[k];
                    arrQa[k]=tmpQa;

                    tmp1=seq[k+1];
                    seq[k+1]=seq[k];
                    seq[k]=tmp1;
                }
                else if(tmpArr[k]==tmpArr[k+1])
                {
                    if(arrQa[k]>arrQa[k+1])
                    {
                        tmp=tmpArr[k+1];
                        tmpArr[k+1]=tmpArr[k];
                        tmpArr[k]=tmp;

                        tmpQa=arrQa[k+1];
                        arrQa[k+1]=arrQa[k];
                        arrQa[k]=tmpQa;

                        tmp1=seq[k+1];
                        seq[k+1]=seq[k];
                        seq[k]=tmp1;
                    }
                }

            }


            if(dtype=='d')
            {
                var d1=new Date(tmpArr[k]);
                var d2=new Date(tmpArr[k+1]);

                if(d1>d2)
                {
                    tmp=tmpArr[k+1];
                    tmpArr[k+1]=tmpArr[k];
                    tmpArr[k]=tmp;

                    tmpQa=arrQa[k+1];
                    arrQa[k+1]=arrQa[k];
                    arrQa[k]=tmpQa;

                    tmp1=seq[k+1];
                    seq[k+1]=seq[k];
                    seq[k]=tmp1;
                }
                else if(d1.valueOf()==d2.valueOf())
                {
                    if(arrQa[k]>arrQa[k+1])
                    {
                        tmp=tmpArr[k+1];
                        tmpArr[k+1]=tmpArr[k];
                        tmpArr[k]=tmp;

                        tmpQa=arrQa[k+1];
                        arrQa[k+1]=arrQa[k];
                        arrQa[k]=tmpQa;

                        tmp1=seq[k+1];
                        seq[k+1]=seq[k];
                        seq[k]=tmp1;
                    }
                }
            }

        }
    }
    maketable();
}

function maketable(edit)
{
str="<table width=700 cellspacing=1 cellpadding=2 border=1 align='center'><tr bgcolor='#ececec'bordercolor='#cccccc'><td align='left'><a href='#' onclick=\"sortAsc(0,'s')\" title='Click here to sort by Name'>Name</a></td><td width='10%' align=center><a href='#' onclick=\"sortAsc(10,'s')\" title='Click here to sort by Trip Status'>Status</a></td><td align='center'><a href='#' onclick=\"sortAsc(1,'s')\" title='Click here to sort by Booking No.'>Booking No.</a></td><td align='center'><a href='#' onclick=\"sortAsc(2,'d')\" title='Click here to sort by Departure Date'>Departure Date</a></td><td align='center'><a href='#' onclick=\"sortAsc(3,'s')\" title='Click here to sort by Itinerary'>Itinerary</a></td><td align='center'><a href='#' onclick=\"sortAsc(6,'d')\" title='Click here to sort by Booking Date'>Booking Date</a></td></tr>"

    var curdes="<%=curdes%>";
    for(i=0;i<seq.length;i++)
    {
        f=seq[i];
        regsel="";
        norsel="";
        optsel="";
        trasel="";
        buttval="";
        callfunc="";
        stxt="";
        saux="";
        if(arr[f][12]!="")
        {
             saux+=arr[f][12].toUpperCase( );
        }
        if(arr[f][13]!="")
        {
             saux+=".";
             saux+=arr[f][13].toUpperCase( );
        }

        if(arr[f][10].toUpperCase( )=="REPEAT")
        {
            regsel="selected";
            stxt="Repeat";
        }
        else if(arr[f][10].toUpperCase( )=="CANCELLED")
        {
            trasel="selected";
            stxt="Cancelled";
        }
        else if(arr[f][10].toUpperCase( )=="TRASH")
        {
            trasel="selected";
            stxt="Trash";
        }
        else if(arr[f][10].toUpperCase( )=="OPTION")

        {
            optsel="selected";
            stxt="Option";
        }
        else
        {
            norsel="selected";
            stxt="Confirmed";
        }

        if(edit==true)
        {
            txvis="hidden";
            txpos="absolute"
            opvis="visible";
            oppos="";
            buttval="Update";
            callfunc="update_regtrip()";
        }
        else
        {
            txvis="visible";
            txpos="";
            opvis="hidden";
            oppos="absolute";
            buttval="Edit";
            callfunc="maketable(true)";
        }
        statustxt="<div style='visibility:" + txvis + ";position:" + txpos + "'>" + stxt +"</div>"
        statustxt+="<div style='visibility:" + opvis + ";position:" + oppos + "'><input type='hidden' name='trip" + i + "' value='" + arr[f][1] + "' ><select name='tripstat" + i + "'><option value='Repeat'" + regsel + ">Repeat</option><option value='Confirmed' " + norsel + ">Confirmed</option><option value='Option' " + optsel + ">Option</option><option value='Trash' " + trasel + ">Trash</option></select></div>"

        str+="<tr bgcolor='#ececec' bordercolor='#cccccc'>"
// str+="<td align='center'>" + statustxt + "</td><td align='left'>" + arr[f][0] + "</td>"+"<td align='left'><a href='mytrip1.asp?tripid=" + arr[f][11] + "&pnrno="+ arr[f][1] + "&totalfare="+ arr[f][7] + " " + curdes +"'>1A/" + arr[f][1] + "</a></td>"+"<td align='center'>" + arr[f] + "</td>"+" <td align='center'>" + arr[f][3] + "</td>"+"<td align='center'>" + arr[f][4] + "</td>"+"<td align='right'>" + arr[f][7] + "</td>"+"<td align='center'>" + arr[f][9] + "</td>"+"<td align='center'>" + saux + "</td>"
        str+="<td align='left'>" + arr[f][0] + "</td>"+"<td align='center'>" + statustxt + "</td>"+"<td align='center'><a href='mytrip_new.asp?pnrno="+ arr[f][1] +"'>" + arr[f][1] + "</a></td>"+"<td align='center'>" + arr[f] + "</td>"+"<td align='center'>" + arr[f][3] + "</td>"+"<td align='center'>" + arr[f][9] + "</td>"
        str+="</tr>"
    }
    str+="<tr><td></td></tr></table>"
    document.all.tt.innerHTML=str;

}
function update_regtrip()
{
    document.regform.submit();
    return true;
}
//-->
</script>


www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems rendering to a table with sorted results jlmacdonald XSLT 6 March 27th, 2008 05:54 PM
Position of sorted nodes tall rog XSLT 5 July 9th, 2007 05:59 PM
How to get least value numbers in a sorted array? ashokparchuri Other Programming Languages 3 December 5th, 2006 08:25 AM
Grouped and sorted table row numbers ADenny XSLT 1 April 24th, 2006 10:06 AM
Search in a sorted list yajleejnus Classic ASP Basics 0 June 11th, 2003 04:00 PM



All times are GMT -4. The time now is 07:20 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.