How to hide columns in table with special ID?
How to hide columns in table with special ID?
I create the ".tabula" class with settings for all my tables:
$(document).ready(function() {var table = $('.tabula').DataTable( {
dom: '<"H"Bfr>t<"F"ip>',
jQueryUI: true,
buttons: [ 'colvis',
{extend: 'collection', text: 'Select Type ↓',
buttons: ['selectCells' , 'selectRows', 'selectColumns']},
'selectAll', 'selectNone', 'pageLength'],
select: {info: true, style: 'multi'},
pagingType: "full_numbers",
lengthMenu: [[ 10, 25, 50, 100, -1 ],[ '10', '25', '50', '100', 'All' ]]
});});
How to hide columns in only one table with special ID and same class name?
I tried to create the settings for this table, but they are not working. Examples:
1)
$(document).ready(function() {
$('#nas1tab2').DataTable( {
"columnDefs": [{"targets": [ -1,-2,-3 ],"visible": false}]
});});
2)
$(document).ready(function() {
$('#nas1tab2').DataTable(
buttons: {extend: 'colvis',hide: [ -1,-2,-3 ]}]
});});
3)
$(document).ready(function() {
$('#nas1tab2.tabula').DataTable( {
"columnDefs": [{"targets": [ -1,-2,-3 ],"visible": false}]
});});
4)
$(document).ready(function() {
$('#nas1tab2.tabula').DataTable( {
buttons: {extend: 'colvis',hide: [ -1,-2,-3 ]}]
});});
This question has an accepted answers - jump to answer
Answers
So you want to apply the same settings to any table with the class
.tabula
, then apply other unique settings by the table ID?So theres 2 ways you can go about doing this.
.tabula
class, then you can just set global defaults, then override the defaults as you create the tableJSBin
Those are really the only way to do it. You cant assign config values by class or ID, then extend or override them, or set defaults and prioritize.
Hope this helps
Thanks a lot.
I removed class from "#nas1tab2" table, make a little bit correction of my CSS + changed JS script, and all works fine:
How does this have anything to do with css?
Simply, replaced color settled to the ".tabula" class to all Data Tables.
Example.
Changed from:
to:
But there is another connected question, if I stay in my JS only:
How to add a special settings for one table exactly in html code, between style tags?:
The versions provided below don't work:
..what?? I want to help, but your questions are very pourly written.
"exactly in html code" and "between style tags" are very confusing..
Whats the code currently look like? What are you expecting to see/happen? What is happening? Are you seeing any errors in the console? Etc etc
Restate the question, add details, be clear, and ill be more than happy to help :-)
del
What????
del = delete wrong post.