Re-apply 'zebra' striping after hiding rows

Re-apply 'zebra' striping after hiding rows

matbeardmatbeard Posts: 22Questions: 0Answers: 0
edited March 2012 in General
I have a server-side data table that's pulls anywhere between 10 - 150 rows from a database. The user is then able to pseudo-filter the results by hiding certain rows.

This is done by applying a certain attribute the each row (based on the value of one of the fields) and then toggling the visibility using a series of checkboxes.

It's all working, apart from the odd/even striping, which obviously doesn't take account of the hidden rows.

Is there a workaround for this issue? I can't think of a way do do it using server-side filtering because the filters all need to be applied to the same field and it's a case of hiding one or more matches rather than showing them.

It may be possible using MySQL's REGEX filters (which I've adapted the server-side code to allow), but I can't get my head around it.

Any ideas are much appreciated.

Replies

  • francispiresfrancispires Posts: 3Questions: 0Answers: 0
    use this after hide the rows...
    $("#yourtable tbody tr:odd").css({'background-color':'#ccc'});
    $("#yourtable tbody tr:even").css({'background-color':'#000'});
  • jcreadyjcready Posts: 44Questions: 0Answers: 0
    Is there a way to disable the even/odd classes all together? I don't need the extra markup.

    [code]tr:ever td { background: #ccc }
    tr:odd td { background: #fff }[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    @jcready: Yes - set asStripeClasses to be an empty array.

    To the original issue - it sounds like rows are being hidden by CSS, not by DataTables. If you need rows to be removed, they should be filtered out from the result set using the DataTables API.

    Allan
This discussion has been closed.