• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Renderer: return usMoney or suppress zero-value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renderer: return usMoney or suppress zero-value

    I have a backend RPG program that returns records and one of the fields is a dollar value field. So I have a renderer on the grid field in order to show it as usMoney:

    return Ext.util.Format.usMoney(value);

    This works great.

    However, if the user clicks a checkbox to indicate they only want to see those customers who have more than one record, I only return some basic data like account #, name, and the number of records for that customer... NOT the dollar value field (because it doesn't make sense in this grouped record). In this case, the dollar value field on the grid displays $0.00 and I'd like to suppress that.

    So I tried editing my renderer to suppress the value if it is zero, and otherwise return the usMoney:

    xtype: 'gridcolumn',
    renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
    if(value === 0) return "";
    else
    return Ext.util.Format.usMoney(value);
    },

    I don't get an error from what I can tell, but I still see $0.00.

    Any ideas? Thanks.

  • #2
    I am guessing that your back-end response must be passing back a character 0 rather than a numeric.

    Comment


    • #3
      This is the field I see coming back in the response:

      "ZY@AMT":56

      So that 56 looks numeric and the usMoney correctly renders it as $56.00.

      In the grouped case, I don't return this field at all, and the grid shows it as $0.00

      Comment


      • #4
        Either return the field with the value that your "if" condition is looking for or change your "if" condition to compare against an empty value.

        Comment


        • #5
          Ok, changing the backend to add passing a zero as that field for the grouped scenario works. I added this into the selected fields in my SQL that gets built:

          +'0 as ZY@AMT, '+

          Thanks.
          Last edited by roedea; 03-09-2017, 07:08 PM.

          Comment


          • #6
            Another way would have been to have your renderer check if the value is empty.

            Example
            Code:
            renderer: function (value) {
                if (Ext.isEmpty(value) || value === 0) {
                    return '';
                }
            
                return Ext.util.Format.usMoney(value);
            }
            Glad you got it handled.

            Comment

            Working...
            X