datatables add class to filters

前端 未结 3 1862
北荒
北荒 2020-12-30 08:03

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

Th

相关标签:
3条回答
  • 2020-12-30 08:05

    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/.

    0 讨论(0)
  • 2020-12-30 08:08

    i'm use DataTable 1.10.2 and i use :

    $.extend( $.fn.dataTableExt.oStdClasses, {
        "sFilterInput": "form-control",
        "sLengthSelect": "form-control"
    });
    

    I go through the extend function instead of jquery.

    0 讨论(0)
  • 2020-12-30 08:27

    This can also be easily done with jQuery using fnDrawCallback. Here I add two classes to style for Bootstrap

    fnDrawCallback: function( oSettings ) {
    $('div#oTable_length select, div#oTable_filter input').addClass("form-control input-sm");
    },
    
    0 讨论(0)
提交回复
热议问题