DataTables / DataTables/Plugins
diacritics-neutralise - "s.replace is not a function" error when string column contains pure integer value
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
I have a DataTable with (ajax) data loaded in one column which normally contains values of type string but sometimes contains integer values. E.g.:
{
id: 1
name: "Company A"
has_access: "1"
},
{
id: 2
name: "Company B"
has_access: "1"
},
{
id: 1
name: 727
has_access: 1
}
In the above, the third company is called 727, which unfortunately is returned as an integer type rather than string in the JSON. diacritics-neutralise hits a snag when it reaches processing this entry and gives an error: s.replace is not a function
I managed to change the back-end which generates the JSON so that it ensures 727 is always a string ("727") - that has been my solution here. However, it may be worth making the plugin more resilient to this situation by updating the removeDiacritics function to cast s to a string to ensure it's never caught off-guard:
function removeDiacritics ( s ) {
for (var i=0, l=diacriticsMap.length; i<l; i++) {
s = String(s).replace(diacriticsMap[i].letters, diacriticsMap[i].base);
}
return s;
}
The above worked for me before using the server-side solution mentioned above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the diacritics-neutralise plugin and locate the removeDiacritics function described in the issue. Reproduce the failure with a numeric value in a DataTable string column, then verify that diacritics processing completes without the s.replace error and preserves the expected value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100