Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datatables: how to stop it from adding 'odd' or 'even' to the class name

This is all I'm using for datatable...

$("#resultsTable").dataTable({
    dom:'Blfrtip',
    buttons: [
       'excelHtml5',
       'csvHtml5',
       'pdfHtml5'
    ],

    "fnPreDrawCallback":function(){
        $("#resultsTable").hide();
        //alert("Pre Draw");
    },
    "fnDrawCallback":function(){
        $("#resultsTable").show();
        //alert("Draw");
    },
    "fnInitComplete":function(){
        //alert("Complete");
    }
});

But it adds 'odd' or 'even' to the class name of each row it seems, which I do not want. How can I get it to leave the class names alone?

like image 449
user2782001 Avatar asked May 25 '16 21:05

user2782001


People also ask

What is lengthChange in DataTable?

The lengthChange option is used to specify whether the dropdown to change the number of rows per page is displayed or not. This dropdown is shown only when paging of the DataTable is enabled, as disabling it automatically removes the dropdown. A true value displays the dropdown and a false value removes it.

What is Serverside in DataTables?

DataTables' server-side processing mode is a feature that naturally fits with Scroller. Server-side processing can be used to show large data sets, with the server being used to do the data processing, and Scroller optimising the display of the data in a scrolling viewport.

What is stateSave in DataTables?

DataTables saves the state of a table (its paging position, ordering state etc). When the stateSave option is enabled, it can be restored when the user reloads a page, or comes back to the page after visiting a sub-page.


2 Answers

If you want to remove stripe classes globally, set the default options:

$.extend($.fn.dataTable.ext.classes, {
  sStripeEven: '', sStripeOdd: ''
});

If you want to disable the classes during initialization:

$('#example').dataTable( {
  "stripeClasses": []
} );

If you want to disable them on the table directly via data attributes:

<table data-stripe-classes="[]">
</table>
like image 122
akaspick Avatar answered Oct 14 '22 02:10

akaspick


I added "stripeClasses": [], but it didn't have any effect. I had to remove "table-striped" in the list of classes in the table element used to create this data table. For instance, if you have a list of classes like this:

<table class="display table table-striped table-bordered dt-responsive">

simply delete table-striped.

like image 3
Isa Ataseven Avatar answered Oct 14 '22 01:10

Isa Ataseven