Having issues with asSorting
Having issues with asSorting
Hi all,
Trying to use aoColumnDefs and asSorting, and have run into something weird. What I have currently is:
[code]
$('.display').dataTable({
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"aoColumnDefs": [
{"aTargets": ["nosort"], "bSortable": false},
{"aTargets": ["sort-asc"], "asSorting": ["asc"]},
{"aTargets": ["sort-desc"], "asSorting": ["desc"]},
{"aTargets": ["_all"], "asSorting": ["asc","desc"]}
]
});
[/code]
and the html is:
[code]
Username
Status
Created
Last Login
<?php foreach($this->users as $user) { ?>
Edit
<?php echo $user->username; ?>
<?php echo ucfirst($user->status); ?>
<?php echo date('m/d/y', $user->createdDate); ?>
<?php echo date('m/d/y', $user->lastLogin); ?>
<?php } ?>
[/code]
Everything seems fine except this. The Username column is NOT sorting by default. But clicking on it once sorts it and then only lets you sort ascending.
What I am trying to achieve is to sort the Username field by default, but allow it to sort in either direction. How can I achieve this? (Preferable using class names with aoColumnDefs because I would like one statement to create every datatable in the site.)
Thanks in advance,
Terry
Trying to use aoColumnDefs and asSorting, and have run into something weird. What I have currently is:
[code]
$('.display').dataTable({
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"aoColumnDefs": [
{"aTargets": ["nosort"], "bSortable": false},
{"aTargets": ["sort-asc"], "asSorting": ["asc"]},
{"aTargets": ["sort-desc"], "asSorting": ["desc"]},
{"aTargets": ["_all"], "asSorting": ["asc","desc"]}
]
});
[/code]
and the html is:
[code]
Username
Status
Created
Last Login
<?php foreach($this->users as $user) { ?>
Edit
<?php echo $user->username; ?>
<?php echo ucfirst($user->status); ?>
<?php echo date('m/d/y', $user->createdDate); ?>
<?php echo date('m/d/y', $user->lastLogin); ?>
<?php } ?>
[/code]
Everything seems fine except this. The Username column is NOT sorting by default. But clicking on it once sorts it and then only lets you sort ascending.
What I am trying to achieve is to sort the Username field by default, but allow it to sort in either direction. How can I achieve this? (Preferable using class names with aoColumnDefs because I would like one statement to create every datatable in the site.)
Thanks in advance,
Terry
This discussion has been closed.
Replies
You need to specify that you want to sort on the second column by default with aaSorting: http://datatables.net/usage/options#aaSorting . Otherwise DataTables will try to sort on the first column, see that it can't be sorted and do nothing.
Allan
I saw that option, but then saw the documentation for asSorting here: http://datatables.net/usage/columns and it says: "You can control the default sorting direction..." Which would imply allowing it to sort by default. If you are correct, I think this documentation needs to be changed to be more clear, maybe simply changing it to "You can control the order in which sorting direction is applied..." instead.
Thanks, I will figure out how to use aaSorting then.
Terry
With oColumns.asSorting you can control the default sorting direction as the documentation says - but only for columns which have the ability to be sorted - it does not control the default sorting state - that is the realm of aaSorting. For example with asSorting you could change the first column to sort by desc first and then asc (rather than the otherway around, which is the default).
Regards,
Allan