angular-ui/ui-grid

CSV Import with column name as a number gives error

Open

#6503 aperta il 14 dic 2017

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)JavaScript (2496 fork)batch import
help wantedneeds: analysis

Metriche repository

Star
 (5395 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Hello There,

I am trying to import a csv with numbers and strings in first row. This numbers & strings needs to be column headers which are actually product ids in my application.

Eg: customer_id, customer_name,8,7,3

This produces error: Uncaught TypeError: value.replace is not a function

I fixed this issue with below

processHeaders: function( grid, headerRow ) { var headers = []; if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ){ // we are going to create new columnDefs for all these columns, so just remove // spaces from the names to create fields headerRow.forEach( function( value, index ) { if(typeof value !== 'number'){ headers.push( value.replace( /[^0-9a-zA-Z-]/g, '' ) ); } else { headers.push( value); } }); return headers; } else { var lookupHash = service.flattenColumnDefs( grid, grid.options.columnDefs ); headerRow.forEach( function( value, index ) { if ( lookupHash[value] ) { headers.push( lookupHash[value] ); } else if ( lookupHash[ value.toLowerCase() ] ) { headers.push( lookupHash[ value.toLowerCase() ] ); } else { headers.push( null ); } }); return headers; } },

Now the issue is that the position of the column changes. Its no more the same as in the csv. The column names which are a string are pushed to the end and the numbers are listed first.

Attaching the csv file upload.txt Please change the extenstion to .csv i have changed it to .txt as .csv is not supported here.

Guida contributor