It's not a secret anymore!*
The moose likes HTML, CSS and JavaScript and the fly likes jQuery: How to change table row background color when we do sorting? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQuery: How to change table row background color when we do sorting?" Watch "jQuery: How to change table row background color when we do sorting?" New topic
Author

jQuery: How to change table row background color when we do sorting?

Madhav Kanneganti
Greenhorn

Joined: Jan 20, 2012
Posts: 25
I've a table rows with alternate background colors (while and cyan, even and odd respectively) , but when I do sorting with Jquery those rows colors are not changing according to orders.


From the above "alt" class also doesn't help to me. Can anyone help on this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60737
    
  65

Firstly, "alt" is a horrible name. Use something more descriptive.

Think about it for a minute:
  • You have some rows that have the alt class name.
  • Then you rearrange the rows.
  • And then you add alt to every other row in the rearrangement.


  • Now which rows have the class name. Is it just the odd rows? Really?


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Rob Crowther
    author
    Ranch Hand

    Joined: Nov 06, 2012
    Posts: 295
        
        5

    Why are you doing it with jQuery anyway? Every current browser can do this with CSS:

    Do you specifically need IE8 support? Write some code in a conditional comment to handle IE8 and before, support all the other browsers the easy way.


    Read my books: Hello! HTML5 & CSS3 | HTML5 in Action | Read my blog
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60737
        
      65

    Doing it with CSS completely solves the problem.

    But do you understand why the original problem exists?

    Hint: open the JavaScript debugger and look at the elements of the DOM after the sort. See which ones now have the alt class.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: jQuery: How to change table row background color when we do sorting?
     
    Similar Threads
    can i set an event for jtable header?
    Generalized table striping using JQuery
    jQuery in Action - is jQuery an abstraction
    Help! Colors for Table Rows
    jQuery HotKey - Handling more than two key combination