1

I want to hide some columns in datatable when page change size (responsive). I would like to show/hide some columns depending on curremt size.

Thank you.

1

3 Answers 3

8

It is very simple.

var tbl = $('your_datatable_selector');

// Work with column 2
tbl.DataTable().column(2).visible(false); // or true, if you want to show it
Sign up to request clarification or add additional context in comments.

1 Comment

2

Use Responsive extension to show/hide columns dynamically based on screen size.

Optionally you can determine which columns will be hidden first using responsivePriority option, see Column priority for more details.

Alternatively you can assign special classes to th elements to define column behavior, see Class logic for more details.

You just need to include additional CSS/JS files and use responsive option as shown below.

$('#example').DataTable( {
    responsive: true
} );

Comments

2
{

    var table = $(`'#screenFieldsTable'`).DataTable(); 
    
    // Hide two columns 
    
    table.columns( [10,11] ).visible( false );

}

1 Comment

Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, can you edit your answer to include an explanation of what you're doing and why you believe it is the best approach?

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.