Alternate row coloring in jquery

后端 未结 3 675
攒了一身酷
攒了一身酷 2021-01-18 06:43

I have a table with expand and collapse of rows, with column sortable. Below is my code, is there is any ways to improve its performance. And read appending complete group

相关标签:
3条回答
  • 2021-01-18 07:16

    Tutorials:Zebra Striping Made Easy from the jQuery is a great tutorial on how to do the zebra striping.

    0 讨论(0)
  • 2021-01-18 07:18

    You might find the :even and :odd selectors useful.

    You could then use them like this:

    $('.stripyTable tr:even').addClass('even');
    $('.stripyTable tr:odd').addClass('odd');
    $('.stripyTable .submenu tr:even').addClass('alt_row_sub');
    $('.stripyTable .submenu tr:odd').addClass('alt_row_sub2');
    

    The other thing to consider is whether you can get the different styling of the subsections just with CSS, then in your JS you only need to worry about applying the odd / even classes. The CSS might look something like:

    .odd { background-color: blue; }
    .even { background-color: white; }
    .sub .odd { background-color: green; }
    .sub .even { background-color: yellow; }
    
    0 讨论(0)
  • 2021-01-18 07:22

    you are inside each loop, do this :

    $.each(myData, function(index, row) {
    
           if(index % 2 == 0)
           {
                row.addClass("AltRow");
           }
    )};
    
    0 讨论(0)
提交回复
热议问题