Can't seem to get Column to hide
Can't seem to get Column to hide
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
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
This discussion has been closed.
Replies
Allan
[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]
Allan
http://www.distribucon.com/datatable
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
Thanks for the other suggestions, too. I'll give those a look once I get a bit further down this path.
Dan
[code]
"aoColumnDefs": { "bVisible": false, "aTargets": [0]},
[/code]
Allan
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
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