aoColumns When number of columns vary
aoColumns When number of columns vary
I have a page which will have a different number of columns, depending on the access rights of the user. There will either be 6 or 4 columns in the table. If there are 6, then this initialisation works fine.
[code]
jQuery(document).ready(function() {
oTable = jQuery('#rate').dataTable( { // Initialise the Open Quote Table
"sScrollY": "540px", // Set scrollable area to 300 pixels
"bScrollCollapse": true, // Shrink the table if only a few rows displayed
"bPaginate": false, // Turn off pagination furniture (turning it on breaks Scrolling)
"bAutoWidth": true, // Let Datatable manage the column widths
"bSort": true, // Turn on Sorting for all columna
"bInfo": false, // Turn off "Showing x to y of nn entries" element
"aaSorting": [[ 0, "desc" ]], // By default, sort by Quote No. Descending
"oLanguage": {"sEmptyTable": "No Sales Activities found for selected year.", // Change the empty table text
"sSearch": "Search:"}, // Change Text for Filter box
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false }
]
} );
[/code]
However, if I am only displaying 4 columns, it obviously breaks the table.
I gather from trolling through the discussions, that the number of columns can be retrieved from
oSettings.aoColumns.length
but I don't know if, or how, I can make use of that to adjust the initialisation depending on how many columns I am displaying. If this is possible, how should I alter the initialisation? I am by no means a jQuery or Javascript expert, so you may have to use words of one syllable for me to understand. Thanks.
Ron
[code]
jQuery(document).ready(function() {
oTable = jQuery('#rate').dataTable( { // Initialise the Open Quote Table
"sScrollY": "540px", // Set scrollable area to 300 pixels
"bScrollCollapse": true, // Shrink the table if only a few rows displayed
"bPaginate": false, // Turn off pagination furniture (turning it on breaks Scrolling)
"bAutoWidth": true, // Let Datatable manage the column widths
"bSort": true, // Turn on Sorting for all columna
"bInfo": false, // Turn off "Showing x to y of nn entries" element
"aaSorting": [[ 0, "desc" ]], // By default, sort by Quote No. Descending
"oLanguage": {"sEmptyTable": "No Sales Activities found for selected year.", // Change the empty table text
"sSearch": "Search:"}, // Change Text for Filter box
"aoColumns": [
null,
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false },
{ "bSortable": false }
]
} );
[/code]
However, if I am only displaying 4 columns, it obviously breaks the table.
I gather from trolling through the discussions, that the number of columns can be retrieved from
oSettings.aoColumns.length
but I don't know if, or how, I can make use of that to adjust the initialisation depending on how many columns I am displaying. If this is possible, how should I alter the initialisation? I am by no means a jQuery or Javascript expert, so you may have to use words of one syllable for me to understand. Thanks.
Ron
This discussion has been closed.
Replies
[code]
aoColumnDefs: [
{ bSortable: true, aTargets: [ 0 ] },
{ bSortable: false, aTargets: [ '_all' ] }
]
[/code]
will disable sorting on all columns, except the first one: http://datatables.net/usage/columns .
Allan
[code]
"aoColumnDefs": [
{"aTargets": [ 0 ], "bSortable": true },
{"aTargets": [ -3 ], "bSortable": true },
{ "aTargets": [ '_all' ], "bSortable": false }
]
[/code]
To allow sorting on the first and third last columns, and not allowing the others to be used for sorting. I have noticed a glitch, however. When defining more than one column as sortable, only the first column has the sort arrows shown. If you click on one of the other sortable columns, the arrows are shown for that column, but are removed from the other column. So, only one column at a time displays the sort arrows. (I am using DT 1.7.5). Thanks
Allan
Allan
Am using the latest version 1.9.4. When I use following code my sorting arrow is not showing by default.
[code] "aoColumnDefs": [{ "bSortable": true, "aTargets": [ 0 ] },{ "bSortable": false, "aTargets": [ '_all' ] }][/code]
Where I was wrong?
Allan
Have you had a chance to look at the issue of the sort arrows not being displayed on sortable columns which are not currently selected for sort? This is not a major issue, but the arrows provide a useful cue for users. Thanks.
PS Happy New Year
[code]
"aoColumnDefs": [
{"aTargets": [ 0,1 ], "bSortable": true },
{"aTargets": [ '_all' ], "bSortable": false }
]
with a table definition of:
Pgm Year
GST Rate AU
GST Rate NZ
AU/NZ Exchg Rate
Edit
Delete
[/code]
Results in the sort arrows only being displayed for the currently sorted columns. However, if you change it to:
[code]
"aoColumnDefs": [
{"aTargets": [ "sortme"], "bSortable": true },
{"aTargets": [ 'nosort' ], "bSortable": false }
]
:
:
Pgm Year
GST Rate AU
GST Rate NZ
AU/NZ Exchg Rate
Edit
Delete
[/code]
The sort arrows are displayed correctly.
Hope this helps.