Solved

jQuery Datables - hiding column is NOT working

Posted on 2016-10-12
3
51 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 (Megan) earned 500 total points (awarded by participants)
ID: 41842112
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 (Megan)
ID: 41860609
Were you able to resolve your problem?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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 invoke it on a web page. 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.: (CODE)

777 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