Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables add class to filters

I am currently seeking a method to add an additional custom class to the jQuery datatables filters (Records per page and Search)

These items render as follow:

<div id="DataTables_Table_0_length" class="dataTables_length">
    <label>
        <select size="1" name="DataTables_Table_0_length" 
                aria-controls="DataTables_Table_0">
            <option value="10" selected="selected">10</option>
            <option value="25">25</option><option value="50">50</option>
            <option value="100">100</option>
        </select>
        records per page
    </label>
</div>

and

<div class="dataTables_filter" id="DataTables_Table_0_filter">
    <label>
        Search: <input type="text" aria-controls="DataTables_Table_0">
    </label>
</div>

Does anyone know how I can best add an additional class to each of them? Some advise would be as usual very much appreciated.

like image 954
nickyfsh Avatar asked May 20 '13 08:05

nickyfsh


1 Answers

Check out http://legacy.datatables.net/styling/custom_classes. DataTables has a slightly complicated way to override the CSS classes for some of the core elements. Here's one way

$(document).ready(function() {
    var extensions = {
        "sFilter": "dataTables_filter custom_filter_class",
        "sLength": "dataTables_length custom_length_class"
    }
    // Used when bJQueryUI is false
    $.extend($.fn.dataTableExt.oStdClasses, extensions);
    // Used when bJQueryUI is true
    $.extend($.fn.dataTableExt.oJUIClasses, extensions);
    $('#example').dataTable();
});

Check out a working example here: http://jsfiddle.net/k2ava/3/.

like image 134
Nick Fishman Avatar answered Nov 05 '22 18:11

Nick Fishman