2

I am using datatables to print the csv file data. The CSV file consists of data .this is an exmple data file.

name,city,category,discount
surya,gnt,all,10%
surya,gnt,all,10%
surya,gnt,all,10%
surya,gnt,all,10%
surya,gnt,all,10%

I want to skip first line of data . How to stop displaying th first line in my datatable. And my code is`

//saving csv file to firebase
           	$('#save-csv').bind('click', function() {
		   if (window.File && window.FileReader && window.FileList && window.Blob)        {
			var file = document.getElementById('files').files[0];
			var reader = new FileReader();
			  reader.readAsText(file);
			  reader.onload = function(event){
				var csv = event.target.result;
				var data = $.csv.toArrays(csv);
				var csvObj = {}
				for(key in data){
					csvObj[key] = {};
					csvObj[key].name = data[key][0];
					csvObj[key].city = data[key][1];
					csvObj[key].category = data[key][2];
					csvObj[key].discount = data[key][3];
				}
				console.log(csvObj);
				$scope.csvStores.stores = csvObj;
				$scope.csvStores.$save().then(function(res){
					console.info(res);
				}).catch(function(err){
					console.error(err);
				});
				$("#myModal").modal("hide");
				swal(
					'Saved',
					'Successfully Saved',
					'success'
				)
			     }
		    }else {
			
		 }
	     });
     

1
  • you are reading only 1 line and skip that line too? Commented Oct 8, 2016 at 4:37

1 Answer 1

0

Before you iterate over your data you should somehow remove/skip the first line. In my opinion it is better to remove, cause if you would like to use later this array, then you have to skip again. I have two ideas:

before the iteration call:data = data.shift(); based on this: http://www.w3schools.com/jsref/jsref_shift.asp This will remove the first element.

Or if you are using lodash, than you can easily call data = _.tail(data); based on this: https://lodash.com/docs/4.16.4#tail

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.