Sorting
Sorting
aquilinor
Posts: 17Questions: 0Answers: 0
I am new to Datatable and Java so I am haveing a problem with sorting, We I click on a column to sort it does not sort by the smallest to the Largest amount 9,999.00 will come before 624,999.00 can some help me with this. my debug code is 'ajeweh'
This discussion has been closed.
Replies
It sounds like you need a sorting plug-in to cope with this, since you have non-numeric data in the column (which is why DataTables isn't detecting it as numeric up-front).
This plug-in should do the business for you:
http://datatables.net/plug-ins/sorting#formatted_numbers
It has a type detection plug-in as well, so the type is automatically detected:
http://datatables.net/plug-ins/type-detection#formatted_numbers
There is an example of how to use these two plug-in types here:
http://datatables.net/release-datatables/examples/plug-ins/sorting_plugin.html
Regards,
Allan
I'd suggest you use Scroller instead: http://datatables.net/extras/scroller . Scroller effectively replaces the infinite scrolling, which will one day be removed from DataTables in favour of Scroller (haven't decided when yet though!).
Allan
Allan
$(document).ready(function() {
$('#example').dataTable( {
"bJQueryUI": false,
"bScrollInfinite": true,
"bScrollCollapse": true,
"sScrollY": "500px",
"iDisplayLength": 50,
"sPaginationType": "full_numbers"
} );
} );
I just needed fixed headers that are scrollable and sortable.
Regards,
Allan
Absolutely. Just disable pagination with the bPaginate option.
> Is there a way to put totals at the bottom?
What totals? Do you have a footer that you want to display?
Allan
Absolutely. Perhaps you could show me what code you are using to sum the column at the moment, and I'll say how it can be modified to get just the filtered elements.
Allan
Vendor
Acquisitions
Development
Management
Operational
Refresh
Sales
Generator
Project
Recurring
CAPEX
Total
<?php
// Get the AP Detail information
$apCategoryDetail = getapCategoryDetail($facility,$category);
//echo ("");
//print_r($apCategoryDetail);
//echo ("");
// Display each row of AP detail information
foreach($apCategoryDetail as $vendorID => $row) {
?>
<?php echo($row['Name']); ?>
$<?php echo(number_format($row['Acquisitions'], 2)); ?>
$<?php echo(number_format($row['Development'], 2)); ?>
$<?php echo(number_format($row['Management'], 2)); ?>
$<?php echo(number_format($row['Operational'], 2)); ?>
$<?php echo(number_format($row['Refresh'], 2)); ?>
$<?php echo(number_format($row['Sales'], 2)); ?>
$<?php echo(number_format($row['Generator Project'], 2)); ?>
$<?php echo(number_format($row['Recurring CAPEX'], 2)); ?>
$<?php echo(number_format($row['Acquisitions'] + $row['Development'] + $row['Management'] + $row['Operational'] +
$row['Refresh'] + $row['Sales'] + $row['Generator Project'] + $row['Recurring CAPEX'], 2)); ?>
<?php
$total['Acquisitions'] += $row['Acquisitions'];
$total['Development'] += $row['Development'];
$total['Management'] += $row['Management'];
$total['Operational'] += $row['Operational'];
$total['Refresh'] += $row['Refresh'];
$total['Sales'] += $row['Sales'];
$total['Generator Project'] += $row['Generator Project'];
$total['Recurring CAPEX'] += $row['Recurring CAPEX'];
}
?>
Totals
$<?php echo(number_format($total['Acquisitions'], 2)); ?>
$<?php echo(number_format($total['Development'], 2)); ?>
$<?php echo(number_format($total['Management'], 2)); ?>
$<?php echo(number_format($total['Operational'], 2)); ?>
$<?php echo(number_format($total['Refresh'], 2)); ?>
$<?php echo(number_format($total['Sales'], 2)); ?>
$<?php echo(number_format($total['Generator Project'], 2)); ?>
$<?php echo(number_format($total['Recurring CAPEX'], 2)); ?>
$<?php echo(number_format($total['Acquisitions'] + $total['Development'] + $total['Management'] + $total['Operational'] + $total['Refresh'] + $total['Sales'] + $total['Generator Project'] + $total['Recurring CAPEX'], 2)); ?>
Regards,
Allan
Regards,
Allan
Allan
Have you had a chance to look at my totaling issue?
I'm really sorry about the huge delay in replying to you!
So, to explain what is needed, let me explain two of the parameters that are passed into fnFooterCallback - the second parameter (aaData) is the data for every single row in the table, regardless of filtering or sorting (it is in "data index" order). And the last parameter (aiDisplay) is an array of indexes, which tell us which rows are to be shown in the table, after filtering and sorting - these indexes point at items in aaData.
With that knowledge, you can loop over aiDisplay and use something like this: `aaData[ aiDisplay[i] ][3]*1` to get data from the table - based only on the filter.
Based on that, your function becomes:
[code]
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
/*
* Calculate the total market share for all browsers in this table (ie inc. outside
* the pagination)
*/
var Management = 0;
for ( var i=0 ; i
Allan
Thanks,
Allan