jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Grid export results to undefined + [number of decimals]
Tagged: Cell, cellsrenderer, datafields, decimal, export, Exportdata, grid, jqxgrid, row, source, value
This topic contains 6 replies, has 2 voices, and was last updated by Dimitar 10 years, 11 months ago.
-
Author
-
I am using the Grid export commanf to export a table
$(‘#tbl’).jqxGrid(‘exportdata’, ‘xls’, ‘Name_of_file’);
but when the csv,or xls file download i get instead of numbers cells containing “undefined + [number of decimals of the numeric value of the number]”
here is the code i use to create the table
$(document).ready(function () { // prepare the data var MyData = new Array(); var rowData = {}; rowData['indicator'] = 'lala1' ; rowData['Scen184'] = 71.3997381167 ; rowData['Scen191'] = 84.274851009 ; rowData['Scen202'] = 71.542449764 ; rowData['Scen203'] = 77.3878273359 ; rowData['Scen211'] = 71.4697028011 ; rowData['Scen212'] = 103.0735303676 ; rowData['Scen232'] = 84.3237359693 ; rowData['Scen233'] = 100.8684595143 ; rowData['Scen234'] = 100.8684595143 ; rowData['Scen235'] = 116.6486419572 ; rowData['Scen236'] = 115.9726933539 ; MyData[0] = rowData; var rowData = {}; rowData['indicator'] = 'lala2' ; rowData['Scen184'] = 0.015393697 ; rowData['Scen191'] = 0.0184680063 ; rowData['Scen202'] = 0.0154384934 ; rowData['Scen203'] = 0.0180208433 ; rowData['Scen211'] = 0.0154582422 ; rowData['Scen212'] = 0.0208813239 ; rowData['Scen232'] = 0.0184808453 ; rowData['Scen233'] = 0.0224558574 ; rowData['Scen234'] = 0.0224558574 ; rowData['Scen235'] = 0.0265567484 ; rowData['Scen236'] = 0.0263714685 ; MyData[1] = rowData; var source = { localdata: MyData, datatype: 'array' }; var TABLEdataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function (data) { }, loadError: function (xhr, status, error) { } }); $('#tblEcoefficiencyIndicatorTotals').jqxGrid( { theme: DefaultTheme , columnsreorder: true, autoheight: true,autorowheight: true,width: '100%', columnsresize: true, sortable: true,filterable: true,enabletooltips: true, selectionmode: 'singlecell', source: TABLEdataAdapter, columns: [ { text: 'Indicator', datafield: 'indicator',resizable:true ,width : '200px',rendered: tooltiprenderer }, { text: 'Baseline', datafield: 'Scen184',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 1', datafield: 'Scen191',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 2', datafield: 'Scen202',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 3', datafield: 'Scen203',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 5', datafield: 'Scen211',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 4', datafield: 'Scen212',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 12', datafield: 'Scen232',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 34', datafield: 'Scen233',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 34', datafield: 'Scen234',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 1234', datafield: 'Scen235',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, { text: 'Scenario 12345', datafield: 'Scen236',resizable:true,type: 'float',cellsformat: 'd3', cellsalign:'right',rendered: tooltiprenderer }, ] }); });
also note that i am usng this code to change the number of decimals in each column
I do not believe this code is causing this behaiviour as this code does not execute until requested$("#btnChangeDecimals").bind("click", function (e) { gridName = $("#grid2edit").val(); $(".columnData2Change").each(function (index, element) { thisClm_datafield = $(this).data('datafield'); thisClm_displayfield = $(this).data('displayfield'); newHowMany = $(this).val(); console.log("checking datafield : " + thisClm_datafield); clms = $("#" + aJQXGrid).jqxGrid('columns'); for (i = 0 ; i < clms.records.length ; i++) { clm = clms.records[i]; if (clm.datafield == thisClm_datafield) { console.log("pre "); console.log($("#" + gridName).jqxGrid('getcolumnproperty', thisClm_datafield, 'cellsformat')); $("#" + gridName).jqxGrid('setcolumnproperty', thisClm_datafield, 'cellsformat', "d" + newHowMany); //clm.cellsformat = "c" + newHowMany ; console.log("after "); console.log($("#" + gridName).jqxGrid('getcolumnproperty', thisClm_datafield, 'cellsformat')); console.log("================================================="); } } }); console.log(" changing on grid " + gridName); $("#" + gridName).jqxGrid('refresh'); console.log("OK now refresh grid " + gridName + " !"); });
p.s. i am using the latest jQWidgets v3.2.2 (2014-Mar-21)
i created an example here….
http://jsfiddle.net/XSKXc/35/Hello agelospanagiotakis,
This occurs because you have not defined your datafields in the source object. Try updating it to:
var source = { localdata: MyData, datafields: [{ name: 'indicator', type: 'string' }, { name: 'Scen184', type: 'float' }, { name: 'Scen191', type: 'float' }, { name: 'Scen202', type: 'float' }], datatype: 'array' };
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/thank you so much for your guidance. This made it work as expected.
Is it possible to change the decimals displayed based on each row and not each column?
should i use the rendercells event or there is a better way ?Hi agelospanagiotakis,
We recommend using the cellsrenderer callback function. For more information, please check out the Grid Cells Rendering tutorial.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.