Solved

jQuery Datables - hiding column is NOT working

Posted on 2016-10-12
3
28 Views
Last Modified: 2016-11-01
I am trying to hide a column in my Datatables. but it is not working.    

I was trying to use this function - "table.fnSetColumnVis( 12, false);"


$(document).ready(function() 
{

$('table[summary="2CIA4_Rules "]').attr('id','ruletable');
$('#ruletable thead').remove();
$('table[summary="2CIA4_Rules "]').find('tr').each(function(){
         var trow = $(this);
         trow.prepend('<td class="rowbutton"><button class="ui-button">User List</button></td>');
     });
$('#ruletable').prepend('<thead><tr class="ruleheader"><td>List</td><td>Rule</td><td>Owner</td><td>Audience</td><td>Curriculum</td><td>Target Area</td><td>Leader</td><td>Leader_WWID</td><td>MRC</td><td>Legal</td><td>JobFunction</td><td>SubFunction</td><td>Exclusions</td><td>Year 4 Notes</td><td>Comments</td><td>ChangeNotes</td></tr></thead');

var mSortingString = [];
var disableSortingColumn = 0; 
mSortingString.push({ "bSortable": false, "aTargets": [disableSortingColumn] });    

var table = $( ".ms-listviewtable" ).DataTable( {
		dom: 'Tf<"clear">rtip',
		"paging": false,
		"sScrollY": "400px",
		"sScrollX": true,
		"aoColumnDefs": mSortingString
    });   

table.fnSetColumnVis( 12, false);

});

Open in new window

0
Comment
Question by:aehrenwo
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
zephyr_hex earned 500 total points (awarded by participants)
Comment Utility
Since DataTables 1.10, you can use columns().visible()
Here is the syntax:

table.columns(12).visible(false);

Open in new window


If you want to hide multiple columns:

table.columns([11,12]).visible(false);

Open in new window


Here is a Fiddle Demo
0
 
LVL 42

Expert Comment

by:zephyr_hex
Comment Utility
Were you able to resolve your problem?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now