Apply stripeClasses only when data is available?

Apply stripeClasses only when data is available?

lerxstlerxst Posts: 1Questions: 1Answers: 0

Is there an easy way to turn this off only when I've filtered my list down to no entries? In other words, I want the stripe classes when I'm showing data, but when there are no rows loaded, or no rows currently visible (because of a search filter), I don't want the messages to that effect having the stripeClasses applied to it.

Answers

  • rf1234rf1234 Posts: 3,036Questions: 88Answers: 423
    var table = $('#example').DataTable();
     
    if ( ! table.data().any() ) {
        $('#yourId').removeClass('table-striped');
    } else {
        $('#yourId').addClass('table-striped');
    }
    

    https://datatables.net/reference/api/any()

  • allanallan Posts: 63,892Questions: 1Answers: 10,530 Site admin

    That will work for Bootstrap styling (not sure if that is being used in this case or not), but not for DataTables styling.

    I'm not clear on why having stripeClasses apply would be a problem when you have no records?

    Allan

This discussion has been closed.