jQWidgets Forums

jQuery UI Widgets Forums Grid Placing Aggregate Values outside Grid

This topic contains 3 replies, has 2 voices, and was last updated by  Benji6996 12 years, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Placing Aggregate Values outside Grid #13416

    Benji6996
    Participant

    Hi,

    I am trying to generate aggregate values and place them into a element on my page. I have achieved this successfully with the following method:

    Please note I have removed all irrelevant options.

    $("#sh_grid").jqxGrid({
    // other options here
    // removed for this example
    columns: [
    { text: 'Total Value', datafield: 'total', align: 'right', cellsalign: 'right', cellsformat: 'c2' }
    ],
    ready: function(){
    // Specify the localize parameters
    var localizationobj = {};
    localizationobj.currencysymbol = "£";
    $("#sh_grid").jqxGrid('localizestrings', localizationobj);
    // Get the sum and average values of the base total column
    var aggregates = $("#sh_grid").jqxGrid('getcolumnaggregateddata', 'total', ['sum', 'avg']);
    // Retrieve the number of filtered shipments
    var quantity = $("#sh_grid").jqxGrid('getdatainformation');
    quantity = quantity.rowscount;
    // Fill in the aggregates
    $('#sh_quantity_aggregate').text(quantity);
    $('#sh_total_aggregate').text('£'+aggregates.sum);
    $('#sh_average_aggregate').text('£'+aggregates.avg);
    }
    });

    However, there are two issues with the above method:

    1. I think there is a better way to do this using the ‘custom aggregates’ field, although I am unsure how to use this.
    2. The aggregate is not being formatted after it is calculated.

    Therefore my questions are simply, is this the best method to place custom aggregate values outside of the grid? If so, how can I ensure the result is formatted correctly?

    Thanks in advance

    B

    Placing Aggregate Values outside Grid #13443

    Benji6996
    Participant

    Alternatively, is there a method that one can call to format a number?

    Something like:

    $('#sh_total_aggregate').text(aggregates.sum.format('c2'));
    Placing Aggregate Values outside Grid #13444

    Peter Stoev
    Keymaster

    Hi Benji6996,

    You can also call the method like that:

    $(“#sh_grid”).jqxGrid(‘getcolumnaggregateddata’, ‘total’, [‘sum’, ‘avg’], true);

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Placing Aggregate Values outside Grid #13445

    Benji6996
    Participant

    Awesome, exactly what I needed, thank you Peter!! 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.