Solved

jQuery Datables - hiding column is NOT working

Posted on 2016-10-12
3
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

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 43

Expert Comment

by:zephyr_hex (Megan)
ID: 41860609
Were you able to resolve your problem?
0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)
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…

752 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