0

How to remove column using class name in jQuery DataTables?

My code is like this : http://jsfiddle.net/oscar11/ebRXw/801/

$(document).ready(function() {
    $('#example').DataTable( {
        "responsive": true,
         "aoColumnDefs": [
             { 

                 "className": 'never', 
                 "targets": 1
             }
             ]
    } );
} );

But the first column is not deleted.

2 Answers 2

2

SOLUTION

Use class name assigned to th element in table header (col-hide in my example) in targets option (without the leading dot .) to target certain columns and visible option to make these columns hidden.

"columnDefs": [
    { targets: "col-hide", visible: false }   
]

For example:

$('#example').DataTable( {
    "responsive": true,
    "columnDefs": [
        { targets: "col-hide", visible: false }   
    ]
} );

DEMO

See this jsFiddle for code and demonstration.

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

2 Comments

@mosestoh, glad to help. If you just wanted to hide second column, you could have used columnDefs: [{ targets: 1, visible: false }] instead without assigning classes.
Okey Grycode.com. Thank you. You much help me. I'm still a beginner. I still need a lot to learn.
1

You can use display:none; with added class to hide the targeted column as

.never {
    display:none;
}

http://jsfiddle.net/ebRXw/803/

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.