Can't seem to get Column to hide

Can't seem to get Column to hide

samb90samb90 Posts: 13Questions: 0Answers: 0
edited July 2012 in General
Hello,

I am using Datatables and have it set up using Server Side Processing. This is working fine!

From the server side I am retrieving 7 columns, 1 of these columns is the primary key and is used for ordering records. As such I do not want the primary key column being displayed. I have tried using the following code to try and make the 6th column containing the primary key invisible but the column is still visible:

[code] dTable= $('#example').dataTable( {
"bProcessing": true,
"bStateSave": true,
"bServerSide": true,
'aoColumnDefs': [
{'aTargets': [6], 'bVisible': false}
],
'sPaginationType': 'full_numbers',
"sAjaxSource": "./include/testserver.php",
[/code]

Can any recommend any solutions to this problem please?

Regards,
Sam

Replies

  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    DataTables uses array indexing (i.e. starts at 0) for column indexes. So to hide the 6th column in the table you would use the column index of 5 (i.e. aTargets: [5]).

    Allan
  • samb90samb90 Posts: 13Questions: 0Answers: 0
    Sorry I meant regardless of the indexing in place no column is being hidden.
  • samb90samb90 Posts: 13Questions: 0Answers: 0
    edited July 2012
    I've just tried to use aoColumns instead of aoColumnDef and am having no luck at hiding any columns in my table

    [code]
    "aoColumns": [
    /* col1*/ null,
    /* col2*/ null,
    /* col3*/ null,
    /* col4*/ null,
    /* col5*/ null,
    /* col6*/ null,
    /* col7 */ {"bVisible": false },
    /* col8*/ null,
    /* col9 */ null,
    /* col10*/ null,
    /* col11*/ null
    ],
    [/code]
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    Can you link to a page showing the issue please? As you can see here ( http://datatables.net/release-datatables/examples/basic_init/hidden_columns.html ) bVisible should be working just fine.

    Allan
  • dmiserdmiser Posts: 6Questions: 0Answers: 0
    I'm seeing the same problem. Here's a link to a page. I must be doing something wrong, but I just don't see it. Thanks for any help.

    http://www.distribucon.com/datatable
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    Hi dmiser,

    Thanks very much for the link! The problem is with this line:

    [code]
    "aoColumnDefs": { "bVisible": false, "aTargets": [0]}
    [/code]

    aoColumnDefs is expecting an array of objects, not just a single object. You can see a working example here: http://live.datatables.net/epuyoy/edit#javascript,html .

    Btw - I see you are using Bootstrap with your page - you might be interested in using these two files for DataTables integration with Bootstrap: https://github.com/DataTables/Plugins/tree/master/integration . You don't need to include "jquery.dataTables.css" which you include these files (indeed, it could make thinks go slightly odd).

    These are the latest versions of the Boostrap integration files for DataTables and have a number of improvements of the ones found in the blog (I'll be updating the blog soon!).

    Allan
  • dmiserdmiser Posts: 6Questions: 0Answers: 0
    Thanks for that. I changed it to emit an array of objects. I compared to the sample that you linked, and everything appears to line up. The link has the updates. But the column still isn't hiding. I've tried to use aoColumns as well with no luck.

    Thanks for the other suggestions, too. I'll give those a look once I get a bit further down this path.

    Dan
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    If you have a look at your Javascript on that page, it is still saying:

    [code]
    "aoColumnDefs": { "bVisible": false, "aTargets": [0]},
    [/code]

    Allan
  • dmiserdmiser Posts: 6Questions: 0Answers: 0
    Grrrrr. Sorry. Copied the wrong file. I checked the page source this time and it really does have the array now, but still doesn't hide the column. Again, sorry for wasting your time.
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    Looks like it works to me :-). I no longer see the 'id' column, just starting at name. Perhaps need to clear your browser's cache?

    Allan
  • dmiserdmiser Posts: 6Questions: 0Answers: 0
    Clearing the cache was the trick. Thank you so much.
  • dmiserdmiser Posts: 6Questions: 0Answers: 0
    Allan,

    Would you mind expanding on why visibility changes need a cache clearing? Changing other attributes like sTitle reflect immediately on the screen without clearing the cache. I'm trying to contribute to an ASP.NET MVC wrapper around datatables, and they hit the same problem where they needed to clear the cache when changing visibility and were wondering why that would be needed.

    Thanks for any input.

    Dan
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    > Would you mind expanding on why visibility changes need a cache clearing?

    It shouldn't do - but your browser was caching an old version of the script for some reason, rather than reading the latest version. The browser should work that out automatically if the server is fully set up for caching, but it sounds like something when wrong there. Perhaps the browser is only refreshing certain files? I think you would need to look at exactly what the browser is doing to find out what is happening there.

    Allan
This discussion has been closed.