locked
HTLM Client: number format with thousand seperator RRS feed

  • Question

  • Hi,

    I spent now hours on searching for a solution but could not find anything on this. For the HTML Client I simply want to format a number like 1000 to 1.000 in a table, i.e with a thousand seperator. I have seen samples where it seems I need some code to the PostRender event. However jquery does not seem to simply support this or I have missed something.

    Would be great if someone would point me in the right direction.

    Thursday, June 5, 2014 8:10 PM

Answers

  • There is a small helper library accounting.js (3 kb minified) that has a very simple API and is flexible for this sort of thing.

    myapp.Main.DecimalProperty_render = function (element, contentItem) {
        // Write code here.
        contentItem.dataBind('value', function() {
            element.textContent = accounting.formatNumber(contentItem.value, 2, '.', ',');  // (number, precision, thousand, decimal)
        });
    };

    • Marked as answer by Stanwell Tuesday, June 17, 2014 6:07 AM
    Tuesday, June 17, 2014 4:39 AM
  • Hi Simon,

    great it works now. Thanks at lot for your help.

    In order not get better insight in jscript formating would you know if there is a list of jscript standard masks somewhere available?

    • Marked as answer by Stanwell Tuesday, June 17, 2014 6:07 AM
    Tuesday, June 17, 2014 6:07 AM

All replies

  • For the HTML Client I simply want to format a number like 1000 to 1.000 in a table, i.e with a thousand seperator. I have seen samples where it seems I need some code to the PostRender event. However jquery does not seem to simply support this or I have missed something.

    Please post your code, it will be helpful to troubleshoot. :)
    Monday, June 16, 2014 6:23 AM
  • Hi qiangs,

    thanks so much for coming back to me. The solution uses a RIA Service to connect to an Oracle based Warehouse. A strange Observation I have done is that even the type of the integer value (record count) makes a difference. When I expose the record count via Long Integer via RIA Service and consequently in the LS data source even the sample (toFixed(2)) is not fired. However if I Change it to Integer this works. Unfortunately I cannot find the correct mask to Format:

    1000 to 1,000 or whatever thousand delimiter.

    myapp.BrowseImportLogsSorted.RowCount_postRender = function (element, contentItem) {
        // Write code here.
        contentItem.dataBind("value", function (value) {
            if (value) {
                $(element).text(value.format("#.##0"));
                //The following statement is taken from various samples
                //It only fires when the RIA Service exposes the attribute as Integer, Long Integer does not seem to work
                //$(element).text(value.toFixed(2));
            }
        });
    };

    Thanks again for having a look at this!

    Monday, June 16, 2014 7:13 AM
  • the format "n00" will format a number with thousand separators and no decimal places.

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    Monday, June 16, 2014 10:23 PM
  • There is a small helper library accounting.js (3 kb minified) that has a very simple API and is flexible for this sort of thing.

    myapp.Main.DecimalProperty_render = function (element, contentItem) {
        // Write code here.
        contentItem.dataBind('value', function() {
            element.textContent = accounting.formatNumber(contentItem.value, 2, '.', ',');  // (number, precision, thousand, decimal)
        });
    };

    • Marked as answer by Stanwell Tuesday, June 17, 2014 6:07 AM
    Tuesday, June 17, 2014 4:39 AM
  • Hi Simon,

    great it works now. Thanks at lot for your help.

    In order not get better insight in jscript formating would you know if there is a list of jscript standard masks somewhere available?

    • Marked as answer by Stanwell Tuesday, June 17, 2014 6:07 AM
    Tuesday, June 17, 2014 6:07 AM
  • Hi LittleBobbyTables,

    thanks a lot for this additional help. Much appreciated!

    Tuesday, June 17, 2014 6:09 AM
  • The .NET Framework number format strings are defined here. http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    Tuesday, June 17, 2014 6:31 AM