question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cell Text in drawCell hook has commas

See original GitHub issue

I’ve created a JSFiddle to show that when I grab the cell text from a specific cell of the autotable it is filled with sporadic commas and all formatting (“\n”) are gone. I need to grab and modify this data by using the addPageContent but their are commas in text that should only have one comma. Here is the JSFiddle

https://jsfiddle.net/ptw5n61a/1/

When I do the following

   drawCell: function(cell, data) {
		           	 if (data.column.dataKey === "description") {
		           		 var cellVal = cell.text.toString();
		           		 
		           		 if (cellVal != undefined && cellVal != '') {
		           			titleAndDesc.push({
		      	              title: cellVal.substring(0, cellVal.indexOf(':')),
		    	              desc: cellVal.substring(cellVal.indexOf(':')+1)
		    	            });
		    	            i++;
		           		 }
		           	 }
		    	    }

And then try to get those values in the addPageContent hook

addPageContent: function() {  
		        	for (var i = 0; i < titleAndDesc.length; i++) {
		        		   console.log("TITLE: "+titleAndDesc[i].title);
		        		   console.log("DESC: "+titleAndDesc[i].desc);
		        	   }
		             } 

I see the following in the console.

TITLE: Title DESC: This is a string and it’s only a string.,Any attempts to make this not a string will,be met with resistance, but with that,resistance you will learn proper use

Why does this happen? Is it a bug??

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinneibargercommented, Feb 13, 2019

Thanks Simon! Shortly after I typed this I figured out a way similar to what you suggested. The “\n” was replaced with “,” because the data.cell.text is now a String array with the lines separated by “\n”. I simply treated that data as such and parsed the array and re-wrote the content. All of this so I could simply bold the first word of the first line…

The API rocks! Thanks!

1reaction
simonbengtssoncommented, Feb 13, 2019

Hmm, with the string you provided and the following code I get this result.

let doc = new jsPDF('l', 'pt');
doc.autoTable({body: [["This is a string and it's only a string.\nAny attempts to make this not a string will be met with resistance,\nbut with that resistance you will learn proper use."]]});
doc.save("test.pdf");
screenshot 2019-02-13 at 15 47 55

And using the didDrawCell you can manually draw any content you want in a cell using any formatting. A little bit cumbersome, but I think that’s the easiest api for it. Let me know if you have a suggestion for a betteer API 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Excel - commas within text and formulas create new columns
Select any cell. On the Data tab of the ribbon, click Text to Columns. Select Delimited, then click Next >. Make sure that...
Read more >
How to add comma at end of cell/text in Excel? - ExtendOffice
Select a blank cell such as cell B1 which is adjacent to the cell you want to add comma at end, enter the...
Read more >
Add Commas Between Words | Before or After Cell Text
Download the featured file https://www.bluepecantraining.com/add... This video is about concatenating commas with numeric or text values in ...
Read more >
Combine data from different cells with a comma or any other ...
How to Combine data from different cells using the TEXTJOIN function in Excel is explained in this video.Check my online course on Excel ......
Read more >
VB How can I use commas within an excel cell? - Stack Overflow
How to load text containing commas in a single Excel cell with EPPlus . The code is C# but it's easy to convert...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found