Sorting

Sorting

aquilinoraquilinor Posts: 17Questions: 0Answers: 0
edited July 2013 in DataTables 1.9
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'

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Hi,

    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
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    That worked Thank You.
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    I am using infinite vertical scrolling and the scroll bar is very choppy is there a way to make it smoother?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    To be honest - not really. That's an inherent limitation of the infinite scrolling.

    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
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    Do I need to install ajax? what is the "sAjaxSource": "myData.txt",
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    How are you currently loading your data? Is it from the DOM? In which case, using infinite scrolling isn't going to give you any performance benefits.

    Allan
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    No I am using

    $(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.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Okay - unless there is a good reason to keep it, I'd very much recommend removed the `bScrollInfinite` option. Is isn't needed to have scrolling in DataTables, and you note that you don't like its display. I don't like it either! (which is why it might be removed in future).

    Regards,
    Allan
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    I did that but is there a way to have it scroll all on one page instead of going to multiple pages.
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    Is there a way to put totals at the bottom?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    > I did that but is there a way to have it scroll all on one page instead of going to multiple pages.

    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
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    I have a footer but it displays all the totals even after a filter, Is it possible to just display all and the amount when its filtered?
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    Thank You that worked great !! Now if I can fix the Totaling I will be all set.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    > I have a footer but it displays all the totals even after a filter, Is it possible to just display all and the amount when its filtered?

    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
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    Here is my Table:



    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)); ?>
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Ah - I see. So the rows totals are being calculated in PHP. I think you might want to do it in Javascript. This example shows how it might be done: http://datatables.net/release-datatables/examples/advanced_init/footer_callback.html

    Regards,
    Allan
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    I did that and I show in the footer 'NAN' , Is there something I am missing?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    That means that something non-numeric was used in the summation. I'd probably need to see the full code that you were using, and ideally a link to the page, to see what is going wrong.

    Regards,
    Allan
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    How Can I get you the full code? When I paste it in the comment section I get an error that the body is too long. Can we possible do a screen share?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Can you email it to me using allan@ this domain name please? I'm really just looking for the Javascript that you are using for the summation, but if you could send me the full page I'll be able to look through the data as well and see what is going wrong.

    Allan
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    on its way, Thank You
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    Hi Allan,

    Have you had a chance to look at my totaling issue?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Hi,

    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
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    I am sorry but where do I put that in my code? I am new to javscripts.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    The file you sent me had a fnFooterCallback function already. I was suggesting that the code above could be used to replace what is existing.

    Allan
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    Allan can you give me some time tomorrow so we can talk about my sorting issue I would really need to get this fixed and I am not to good with Java. My Cell Number is 609-781-4066 and my email address is aquilinor@brandycare.com I am also sending you an email.
  • aquilinoraquilinor Posts: 17Questions: 0Answers: 0
    If need be I will by more support.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    I've just replied by email.

    Thanks,
    Allan
This discussion has been closed.