p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   sorted table (http://p2p.wrox.com/showthread.php?t=26986)

crmpicco March 17th, 2005 10:29 AM

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][8] + "</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][8] + "</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


All times are GMT -4. The time now is 01:49 PM.

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