identical data in column
identical data in column
blag
Posts: 18Questions: 0Answers: 0
Please forgive me, this may be a common question by a newbie - if so, I apologise for my ignorance!!
My tables are derived from a database, via PHP and DataTables is being tested for use to enable sorting of the tables that are pulled from the server. It is not uncommon for me to find that one or more of the columns in the tables contain the same data in each cell. Thus in a table containing x rows in the body, the column headed 'Colour' may (sometimes) only contain 'Brown' in x cells or the Column headed 'Price' may (occasionally) only contain '2.99' in x cells.
Where this data differs within a column, having the facility to sort is useful, but unnecessary where all cells in a column (except the header, of course) contain identical data. Can anyone suggest how I disable the sort according to the contents of the column?
My tables are derived from a database, via PHP and DataTables is being tested for use to enable sorting of the tables that are pulled from the server. It is not uncommon for me to find that one or more of the columns in the tables contain the same data in each cell. Thus in a table containing x rows in the body, the column headed 'Colour' may (sometimes) only contain 'Brown' in x cells or the Column headed 'Price' may (occasionally) only contain '2.99' in x cells.
Where this data differs within a column, having the facility to sort is useful, but unnecessary where all cells in a column (except the header, of course) contain identical data. Can anyone suggest how I disable the sort according to the contents of the column?
This discussion has been closed.
Replies
Allan
Thanks for the response. My Javascript is not good, and although I have been doing some stuff in JQuery, my skill is 'basic'.
Via PHP I can determine at the time the page is created, which columns are 'sortable' and I can even add the class 'sorting' to each 'sortable' column's header (th), but if I do this, the DataTables script overrrides those set by PHP. I'd appreciate some guidance on how to implement this.
The values in this list can change depending on the PHP-defined class attribute/property.
I am then trying to use this javascript array to 'force' the sortable status at intialisation by TableData
here is my clumsy code
[code]//PHP assigns the class 'sorting_disabled' to each table header where the column's td cells are identical
$(function(){if($('#tbl>tbody>tr').length>1){
//checks to see if there is more than one row in the body of the table
var n='',lg=$('#tbl th'),cols=lg.length-1,i=0;
$('#tbl th').each(function(index){
//checks each of the table's headers
if($(this).hasClass('sorting_disabled')){
n+=index;
if(i
Finally, this works:
[code]
$(function(){
if($('#tbl>tbody>tr').length>1)
{var n=new Array(),j=0;
$('#tbl th')
.each(function(index){
if($(this).hasClass('sorting_disabled')){
n[j]=index;j++;}
});
$('#tbl').dataTable({"aaSorting":[],"bPaginate":false,
"aoColumnDefs":[{"bSortable":false,"aTargets":
n.slice()
}],
"bFilter":false,"bInfo":false,"bAutoWidth":false,"bLengthChange":false});}
;}
);
[/code]
n.slice(), without the square brackets '[' and ']', passes the array as the value of 'aTargets'.
If this can be simplified I'd appreciate advice!!