5

How can I set the class on the 'search' field on the datatables plugin please. I'm using the Jquery UI theme as well.

        $('#idSmovData').dataTable( {
             "sScrollY": "600px"
            ,"bPaginate": false
            ,"bFilter": true
            ,"bJQueryUI": true
            ,"bInfo": false
            ,"bSort": false
        });
1
  • in jquery.datatables.css for the selection .dataTables_wrapper .dataTables_filter input (line:288) add border : solid #ddd 1px; border-radius: 5px; or whatever you prefer . Commented Aug 26, 2016 at 4:20

2 Answers 2

5

You can set the search filter wrapper div style class using oStdClasses

$.fn.dataTableExt.oStdClasses["sFilter"] = "my-style-class";

And than use regular css to target the search input field:

.my-style-class input[type=text] {
     color: green;
}

Please refer to the datatables styling section for more details.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks. Had to change to use oJUIClasses, but got there in the end.
@Keith sFilter is actually a property of oStdClasses. but, it's OK to use oJUIClasses as it extend oStdClasses.
On the datatables styling link you referenced, it says: $.fn.dataTableExt.oStdClasses - used when bJQueryUI is false $.fn.dataTableExt.oJUIClasses - used when bJQueryUI is true. As I'm using "bJQueryUI": true, I assumed that I would need to use oJUIClasses. Is there an equivalent of sFilter for oJUIClasses, or am I missing something?
$.fn.dataTableExt.oJUIClasses["sFilter"] = "my-style-class"; shoud work as well.
I just want to point out that this answer doesn't exactly answer the question asked in the OP, even though Keith seems satisfied. The question is how to apply a class to the input, not how to style it. The difference comes when styling your DataTables to work with an existing CSS framework such as Bootstrap, which may call for something like "input-small" being a class on the input field itself.
|
5
$('div.dataTables_filter input').addClass('form-control');
$('div.dataTables_length select').addClass('form-control');

Here I am adding the Bootstrap class form-control to the filter input and the length select, as an example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.