Is there a way to get DataTables to apply stripe classes to the elements too?

Is there a way to get DataTables to apply stripe classes to the elements too?

jasonperronejasonperrone Posts: 9Questions: 0Answers: 0
edited January 2013 in DataTables 1.9
The asStripeClasses feature is awesome. I dynamically create tags when creating my tables based on style choices made by the user and then I use the stripe feature to have DataTables assign those classes to the TR's when building the table, and badda boom badda bing, works perfectly.

My problem is I want to allow people to choose td styling on an alternate row basis, styling like font-size. Because the datatable td cells are not being assigned with a class, my td's are inheriting their styles from places I cannot change (long story). I think my problem would be solved if DataTables put the stripe classes not just on the tr elements but also the td elements they contain.

Any thoughts?

Replies

  • jasonperronejasonperrone Posts: 9Questions: 0Answers: 0
    This code gets me what I want. I don't like changing your base code. Any thoughts on incorporating this into base? This is line 1464 of 1.9.4:
    // apply classes to TD cells too
    var tdNodes = nRow.childNodes;
    for (var i = 0; i < tdNodes.length; i++) {
    var tdNode = tdNodes[i];
    $(tdNode).removeClass( aoData._sRowStripe ).addClass( sStripe );
    }
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Adding it to the TD elements would slow DataTables down significantly, so that won't be put into the core.

    However, can't you just do:

    [code]
    tr.odd td { ... }
    tr.event td { ... }
    [/code]

    in your CSS?

    Allan
  • jasonperronejasonperrone Posts: 9Questions: 0Answers: 0
    That was the first thing I tried and it caused the formatting to no longer be applied to the row. Let me try that again.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There might be another style overriding it. The Inspector in Webkit browsers or Firebug would tell you for sure.

    Allan
  • jasonperronejasonperrone Posts: 9Questions: 0Answers: 0
    Actually, you are right. that's exactly what it was, I remember now. I can fix that. Thanks, Allan, my workaround to change dataTables was stupid. I can eliminate the class in my base css file that is overriding and set the styles only in this spot.

    Thanks, sorry to waste your time.
This discussion has been closed.