jQWidgets Forums

jQuery UI Widgets Forums Grid Formatting final aggregates value

This topic contains 4 replies, has 2 voices, and was last updated by  AA5MC 5 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Formatting final aggregates value #105795

    AA5MC
    Participant

    Hello,

    I have a custom aggregates that calculates total file size from values from another column. all works well ( see below)

    { text: "FileSizeVar",width: 50, datafield: "FileSizeVar",cellsalign: 'center', align: 'center',
                                  
                                            aggregates: [{ '<b>Total</b>': 
                                                               function (aggregatedValue, currentValue, column, record) {
                                                                    var total = record['FileSize'];
                                                                  return aggregatedValue + total;
                                                                } 
                                                          }]
                                            },

    however, I want to format the final value after the rendering is completed, using the function below which takes the aggregates and formats it to make it more readable. Is this possible?

        function formatFileSize(bytes,decimalPoint) {
                       if(bytes == 0) return '0 Bytes';
                       var k = 1000,
                       dm = decimalPoint || 2,
                       sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
                       i = Math.floor(Math.log(bytes) / Math.log(k));
                       return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
                 } 

    Best Regards
    Mike

    Formatting final aggregates value #105814

    Todor
    Participant

    Hello Mike,

    Please review the following demo whether it fits your needs.

    Let us know if you need further assistance.

    Best Regards,
    Todor

    jQWidgets Team
    https://www.jqwidgets.com

    Formatting final aggregates value #105822

    AA5MC
    Participant

    Hello Todor,

    Thank you! I got it to work, however I had to remove the theme reference from this line:
    var renderstring = "<div class='jqx-widget-content jqx-widget-content-" + <strong>theme</strong> + "' style='float: left; width: 100%; height: 100%;'>";

    What I’m getting is a error saying the theme is not define and the background color is now white. which is because of the theme reference being missing. any help in correctly the theme issue would be greatly appreciated

    Best regards
    Mike Colonna

    if any one else is interested here is what I did to get the cell data and aggregates to show a readable file size:

                 {text: "File Size", width: 50, datafield: "FileSize", cellsalign: 'center', align: 'center', aggregates: ['sum'],
                                     aggregatesrenderer: function (aggregates, column, element, summaryData) {
                                         var renderstring = "<div class='jqx-widget-content jqx-widget-content-" + theme + "' style='float: left; width: 100%; height: 100%;'>";
                                         var size = 0;
                                         var name = "Total Size ";
                                         $.each(aggregates, function (key, value) {
                                             size += value;
                                         });
                                         renderstring += '<div style="color:black; position: relative; margin: 6px; text-align: right; overflow: hidden;"><Strong>' + name + ':</strong> ' + formatFileSize(size) + '</div></div>';
                                         return renderstring;
                                     }
                                , cellsrenderer: function (row, column, value, defaultHtml, columnSettings, record) {
                                          
                                          return  defaultHtml.replace(value,formatFileSize(value,0));
                                  

    }},

    Formatting final aggregates value #105841

    Todor
    Participant

    Hello Mike,

    In order to use a certain theme you have to include its css file. For example jqx.light.css, jqx.dark.css etc.

    Let us know if you need further assistance.

    Best Regards,
    Todor

    jQWidgets Team
    https://www.jqwidgets.com

    Formatting final aggregates value #105861

    AA5MC
    Participant

    Thank y will do !

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

You must be logged in to reply to this topic.