Cell Text in drawCell hook has commas
See original GitHub issueI’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:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
Hmm, with the string you provided and the following code I get this result.
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 👍