jquery tablesorter plugin - retain alternative row colors

前端 未结 6 1516
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 20:36

I took an html table that I am applying alternative row colors to, and I added jquery table sorter on it so users can sort the table.

The issue is that the alternati

6条回答
  •  长发绾君心
    2021-01-01 21:28

    In order to maintain the zebra stripes after a sort has taken place you need to trigger the zebra widget again.

    $('#myTable')
    .tablesorter({ widgets: ['zebra'] })
    .bind('sortEnd', function(){
        $("#myTable").trigger("applyWidgets"); 
    });
    

    This is less of a hack, as you will be reusing the logic of the zebra widget rather than replicating it.

    Note: This kind of work-around is only required in instances where the default zebra widget is failing. I have found in most circumstances that this hack is not required as the widget is operating correctly post sort.

提交回复
热议问题