Web Analytics Made Easy -
StatCounter Sorting List - CodingForum

Announcement

Collapse
No announcement yet.

Sorting List

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sorting List

    I have a list of rows having a column Name , now i wan't that on click of the column header label Name the whole list of rows should get sorted in ascending order and on re click of the label the list should now get sorted in descending order . Can some one help me with the code as it is very urgent.

  • #2
    certainly, code below:

    Code:
    if (youHaveAServerSideLanguageAvailable){
    	with(theServerSideLanguage){
    		yourdata.shouldbe = InADatabase
    		if(yourDataIsInADatabase){
    			for (eachColumn in yourData){
    				runAQueryThatSortsItDifferently()
    			}
    		}
    	}
    }
    else{
    	itsGonnaBeARightPain(true)
    }

    Comment


    • #3
      oddest answer I ever seen.

      anyway when you say a list of rows do you mean a html table or?
      perhaps post some code :P

      Comment


      • #4
        Maybe this will help you

        http://www.vladdy.net/webdesign/dom_tables.html
        KOR
        Offshore programming
        -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

        Comment


        • #5
          Originally posted by Kor
          Maybe this will help you

          http://www.vladdy.net/webdesign/dom_tables.html
          !!!CAUTION!!! Contains some old code, parts of which I'm rather ashamed of
          Vladdy | KL
          "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

          Comment


          • #6
            Now you see Vladdy, I intended to help Parijat. I got interesed in this problem either.

            To all.
            Well, I started in solving the problem using innerHTML instead of DOM methods. I managed to get something, unfortunately it works NS only. IE gives an bizzare error starting second array, I don't know why...

            I'll put my code here also (I put it in another forum, as well) maybe here someone will find out why this strange error in IE

            PHP Code:
            <html>
            <
            head>
            <
            script>
            function 
            change(){
            tdocument.getElementById('tab');
            var 
            = new Array()
            for(
            i=0;i<t.rows.length;i++){
            a[i] = t.rows[i].innerHTML;
            }
            for(
            i=0;i<t.rows.length;i++){
            // the line bellow brings an unexpected runtime error in IE
            t.rows[(t.rows.length-1)-i].innerHTML a[i];
            }
            }
            </
            script>
            </
            head>
            <
            body>
            <
            table id="tab" width="30%" border="1">
              <
            tr>
                <
            td>1</td>
              </
            tr>
              <
            tr>
                <
            td>2</td>
              </
            tr>
              <
            tr>
                <
            td>3</td>
              </
            tr>
            </
            table>
            <
            br>
            <
            input type="button" value="rearange" onclick="change()">
            </
            body>
            </
            html
            KOR
            Offshore programming
            -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

            Comment


            • #7
              I appreciate a plug, Kor. Just wanted to warn him that some part of that code which I wrote about 2 years ago are far from optimum
              Vladdy | KL
              "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

              Comment


              • #8
                Solved

                I presumed that error occured somehow because IE innerHTML returns tags written with upper caps, don't know why... (silly thing)

                Now I decided to replace Cell innerHTML, rather than Row, so here it is:

                PHP Code:
                <html>
                <
                head>
                <
                script>
                function 
                ch(){
                tdocument.getElementById('tab');
                = new Array();
                for(
                i=0;i<t.rows.length;i++){
                    
                a[i] = new Array();
                    for(
                j=0;j<t.rows[i].cells.length;j++){
                    
                a[i][j] = t.rows[i].cells[j].innerHTML;
                    }
                }

                for(
                i=0;i<t.rows.length;i++){
                    for(
                j=0;j<t.rows[(t.rows.length-1)-i].cells.length;j++){
                    
                t.rows[(t.rows.length-1)-i].cells[j].innerHTML a[i][j];
                    }
                }
                }
                </
                script>
                </
                head>
                <
                body>
                <
                table id="tab" width="30%" border="1">
                  <
                tr
                    <
                TD>1</TD>
                    <
                TD>oak</TD>
                  </
                tr>
                  <
                tr
                    <
                TD>2</TD>
                    <
                TD>bla</TD>
                  </
                tr>
                  <
                tr
                    <
                TD>3</TD>
                    <
                TD>blabla</TD>
                  </
                tr>
                </
                table>
                <
                br>
                <
                input type="button" value="rearange" onclick="ch()">
                </
                body>
                </
                html
                KOR
                Offshore programming
                -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                Comment


                • #9
                  and to match exactly what Parijat wants:

                  PHP Code:
                  <html>
                  <
                  head>
                  <
                  script>
                  function 
                  ch(){
                  tdocument.getElementById('tab');
                  = new Array();
                  for(
                  i=1;i<t.rows.length;i++){
                      
                  a[i] = new Array();
                      for(
                  j=0;j<t.rows[i].cells.length;j++){
                      
                  a[i][j] = t.rows[i].cells[j].innerHTML;
                      }
                  }
                  for(
                  i=1;i<t.rows.length;i++){
                      for(
                  j=0;j<t.rows[t.rows.length-i].cells.length;j++){
                      
                  t.rows[t.rows.length-i].cells[j].innerHTML a[i][j];
                      }
                  }
                  }
                  </
                  script>
                  </
                  head>
                  <
                  body>
                  <
                  table id="tab" width="30%" border="1">
                    <
                  tr
                      <
                  td><a href="#" onclick="ch()">NAME</a></td>
                      <
                  td>somestuff</td>
                    </
                  tr>
                    <
                  tr
                      <
                  td>1</td>
                      <
                  td>oak</td>
                    </
                  tr>
                    <
                  tr
                      <
                  td>2</td>
                      <
                  td>bla</td>
                    </
                  tr>
                    <
                  tr
                      <
                  td>3</td>
                      <
                  td>blabla</td>
                    </
                  tr>
                    <
                  tr>
                      <
                  td>4</td>
                      <
                  td>oak oak</td>
                    </
                  tr>
                  </
                  table>
                  </
                  body>
                  </
                  html
                  KOR
                  Offshore programming
                  -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                  Comment


                  • #10
                    My version of what I think you want.

                    http://www.the-hive.dk/~donp/Library/DataGridTest.HTML

                    Comment


                    • #11
                      yeap, nice...

                      I was now just thinking what kind of sorting criteria Parijat wants. Presume that alphabetical, so now I try to sort using RegExp, not very good on this, rather begginer...
                      KOR
                      Offshore programming
                      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                      Comment


                      • #12
                        hey thanks all for the code its working for me
                        i would like to specially thank kor for putting so much effort in helping me

                        Comment


                        • #13
                          Well, I myself start in building similar stuff for one of my projects, so your request made me try to solve it in avance...

                          Anyway, the problem is now only half solved, as I (and maybe you too) need first to sort the colums. Some of our mates here gave me some solutions for the sorting

                          http://www.codingforum.net/showthrea...threadid=34057

                          , so, when ready, I might send you my result (If I will not forget your name... )
                          KOR
                          Offshore programming
                          -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                          Comment

                          Working...
                          X