DataTables / DataTables/Plugins

diacritics-neutralise - "s.replace is not a function" error when string column contains pure integer value

Open
#455 5 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.