Grid Sorting Using JAVAScript


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Grid Sorting Using JAVAScript

  1. #1
    Join Date
    Jan 2009
    Posts
    5

    Grid Sorting Using JAVAScript

    Grid contains 25 columns and 15 rows.So i have implemented sorting using javascript.
    Column 2 contains names of customers.How to sort them alphabetically and incorporate in the given function?
    The following function sorts only floating numbers.
    Code:
    function sortGrid(colId,sortAscending){
        try{
            var sortCol = parseInt(colId);
            if(sortCol == 2){
                 // alert('col id less than 3');
                  return false;
            }
            var rowCount = this.rowId.length;
            for(var rowI=0;rowI<rowCount-1;rowI++){
                for(var rowJ=rowI+1;rowJ<rowCount;rowJ++){
                    var datI, datJ;
                    try{
                        datI = parseFloat(this.rowData[rowI][sortCol]);
                        if(isNaN(datI)){
                            datI = 0;
                        }
                    }catch(e){
                        datI = 0;
                    }try{
                        datJ = parseFloat(this.rowData[rowJ][sortCol]);
                        if(isNaN(datJ)){
                            datJ = 0;
                        }
                    }catch(e){
                        datJ = 0;
                    }
                    
                    if(datI > datJ){
                        if(sortAscending) this.swapArrayRows(rowI,rowJ);
                    }else if(datI < datJ){
                        if(!sortAscending) this.swapArrayRows(rowI,rowJ);
                    }
                }
            }
            return true;
        }catch(er){
           // alert('Error occured in sorting array :-: '+er);
            return false;
        }
    }
    Last edited by Hack; 01-29-2009 at 10:01 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What kind of grid are you using?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    u don't need to change anything in ur code since the "<" and ">" operators in JS works too for strings and chars ... just remove the "parseFloat()" instead use a direct assignment...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  4. #4
    Join Date
    Jan 2009
    Posts
    5
    I applied direct assignment but still the sorting of customer names not working

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Are you getting any errors or is it just not working?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Jan 2009
    Posts
    5
    Itz working.thank u

  7. #7
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What did you do?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. sorting in grid view
    By coimbatorian in forum ASP.NET
    Replies: 0
    Last Post: 02-13-2008, 09:40 AM
  2. Grid Columns - Sorting Arrow
    By christianbg in forum .NET
    Replies: 5
    Last Post: 09-14-2007, 07:04 AM
  3. sorting with javascript in xslt
    By masha in forum XML
    Replies: 0
    Last Post: 07-09-2005, 04:29 AM
  4. Replies: 1
    Last Post: 04-05-2002, 11:18 AM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center