4

jQuery DataTables with the Bootstrap design, seems to working fine, no issues. But when I try to use ColVis with it, it breaks everything.

I tried the minimal CSS, different JavaScript files from ColVis which didn't fixed it. Weird.

However, that's my CSS/Javascript with screenshots I was using:

http://pastebin.com/F83sthP7

Any suggestion how to fix it?

CSS:

<link rel="stylesheet" type="text/css" href="https://stackoverflow.com//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://stackoverflow.com//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css">
<link href="https://stackoverflow.com//cdn.datatables.net/colvis/1.1.0/css/dataTables.colVis.css" rel="stylesheet">

JavaScript:

<script type="text/javascript" language="javascript" src="https://stackoverflow.com//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" language="javascript" src="https://stackoverflow.com//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://stackoverflow.com//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.js"></script>
<script type="text/javascript" language="javascript" src="https://www.datatables.net/release-datatables/extensions/ColVis/js/dataTables.colVis.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
   $('#example').DataTable( {
      dom: 'C<"clear">lfrtip'
   } );
} );
</script>

Screenshots:


Screenshot 1]


Screenshot 2


1 Answer 1

1

CAUSE

Bootstrap add-on for jQuery DataTables requires dom option other than default 'lfrtip'. Unfortunately this is not documented anywhere but can be discovered by inspecting add-on source code.

SOLUTION

Use dom necessary for Twitter Bootstrap style (as seen in add-on source code) and modified so that ColVis button appears correctly.

JavaScript

$(document).ready(function (){
    var table = $('#example').DataTable({
      dom:
        "<'row'<'col-sm-6'l><'col-sm-3'f><'col-sm-3 text-right'C>>" +
        "<'row'<'col-sm-12'tr>>" +
        "<'row'<'col-sm-5'i><'col-sm-7'p>>",        
   });
});

CSS:

div.ColVis, button.ColVis_Button {
  float:none;
}

DEMO

See this jsFiddle for code and demonstration.

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

1 Comment

@Neoon, corrected code for better appearance on smaller screens.

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.