jQWidgets Forums

jQuery UI Widgets Forums Grid Export to Excel fails

This topic contains 7 replies, has 2 voices, and was last updated by  Hristo 9 years, 4 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • Export to Excel fails #79190

    mflach
    Participant

    I have a grid with currency columns that generate an error (Uncaught TypeError: Cannot read property ‘charCodeAt’ of undefined [jqxdata.export.js:7]) when I export to Excel. If I export to csv I do not get the error and if I remove the cell format ‘c2’ I do not get the error.

    Any thoughts?

    Export to Excel fails #79191

    Hristo
    Participant

    Hello mflach,

    Could you provide us one example (in https://www.jseditor.io/ or http://jsfiddle.net/).
    If you prefer could look at this example: http://jsfiddle.net/txhi/hy17xx9z/
    There are column ‘Price’ with same cell settings cellsformat: 'c2',.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    Export to Excel fails #79223

    mflach
    Participant

    I’ve narrowed it down to my use of aggregates. Because my aggregates have a label, it messes up the currency formatting.

    
     aggregates: [
    	{ '<b>LSI</b>':
    	function (aggregatedValue, currentValue, column, record) 
    	{
    		var val = (record.RATE_ID == 11?0:currentValue);
    		return aggregatedValue + val;
    	}
    	},
    	{ '<b>Wyle</b>':
    	function (aggregatedValue, currentValue, column, record) 
    	{
    		var val = (record.RATE_ID != 11?0:currentValue);
    		return aggregatedValue + val;
    		}
    	}
    ]
    
    Export to Excel fails #79224

    mflach
    Participant

    Here is my full column description. Is there something that may be messing things up?

    BTW: I tested it on Fiddle but could get it to duplicate my experience.

    
    {text:'Dec 13 15', filterable: false, editable: false, cellsalign: 'right', align: 'right', cellsformat: 'c2', hidden: false, cellclassname: 'column1',width:130, datafield:'Dec_13_15',
    					 aggregates: [
    								{ '<b>LSI</b>':
    								function (aggregatedValue, currentValue, column, record) 
    									{
    									var val = (record.RATE_ID == 11?0:currentValue);
    									return aggregatedValue + val;
    									}
    								},
    								{ '<b>Wyle</b>':
    								function (aggregatedValue, currentValue, column, record) 
    									{
    									var val = (record.RATE_ID != 11?0:currentValue);
    									return aggregatedValue + val;
    									}
    								}
    								]
    			 }
    
    Export to Excel fails #79225

    mflach
    Participant

    OK, getting closer. I’ve now narrowed it down to my use of cellclassname. Here is the style for ‘column1’. If I take out cellclassname it work just fine.

    	.column1 {
                background-color: #99ccff;
                color: white;
            }    
    
    Export to Excel fails #79226

    mflach
    Participant

    I was able to duplicate this on Fiddle. Here is my column description and I used the same style from my project.

    Modified the grid with: showaggregates: true

    {
              text: 'Price',
              datafield: 'price',
              cellsalign: 'right',
              cellsformat: 'c2',
              cellclassname: 'column1',
     	  aggregates: ['min', 'max'],
              width: 100
    }
    Export to Excel fails #79227

    mflach
    Participant

    Also, the error is in buildFormat. The q.currencysymbol value is undefined.

    buildFormat : function (q) {
    	if (q.dataType == "number" || q.dataType == "float" || q.dataType == "int" || q.dataType == "integer") {
    		var p = q.formatString;
    		if (p == "" || p.indexOf("n") != -1 || p.indexOf("N") != -1) {
    			this.style += '\n\t\t\t<NumberFormat ss:Format="0"/>'
    		} else {
    			if (p == "f" || p == "F" || p == "D" || p.indexOf("d") != -1) {
    				this.style += '\n\t\t\t<NumberFormat ss:Format="#,##0.00_);[Red](#,##0.00)"/>'
    			} else {
    				if (p.indexOf("p") != -1 || p.indexOf("P") != -1) {
    					this.style += '\n\t\t\t<NumberFormat ss:Format="Percent"/>'
    				} else {
    					if (p.indexOf("c") != -1 || p.indexOf("C") != -1) {
    						if (typeof q.currencysymbol != 'undefined') // I added this
    						{
    						if (parseInt(q.currencysymbol.charCodeAt(0)) == 8364) {
    							this.style += '\n\t\t\t<NumberFormat ss:Format="Euro Currency"/>'
    						} else {
    							this.style += '\n\t\t\t<NumberFormat ss:Format="Currency"/>'
    						}
    						}
    						else
    						{
    							var myVar = 0;
    						}
    					}
    				}
    			}
    		}
    	} else {
    		if (q.dataType == "date") {
    			this.style += '\n\t\t\t<NumberFormat ss:Format="Short Date"/>'
    		}
    	}
    },
    Export to Excel fails #79257

    Hristo
    Participant

    Hello mflach,

    If I understand your goal correct. This article in API Documentation will be helpful.
    https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxgrid/jquery-grid-localization.htm
    Also one theme about aggregates may be interesting:
    http://www.jqwidgets.com/community/topic/grid-aggregates-accessing-other-column-summary-data/
    Please take a look this example too: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/aggregatesrenderer.htm?arctic

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.