-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
diacritics-neutralise - "s.replace is not a function" error when string column contains pure integer value #455
Comments
The same occurred when using any-number.js:32 Uncaught TypeError: Cannot read properties of null (reading 'replace')
at _anyNumberSort (any-number.js:32:11)
at DataTable.ext.type.order.any-number-asc (any-number.js:39:12)
at jquery.dataTables.min.js?version=1.13.6:4:42937
at Array.sort (<anonymous>)
at ie (jquery.dataTables.min.js?version=1.13.6:4:42765)
at u (jquery.dataTables.min.js?version=1.13.6:4:23709)
at B.<anonymous> (jquery.dataTables.min.js?version=1.13.6:4:55254)
at B.iterator (jquery.dataTables.min.js?version=1.13.6:4:52083)
at B.<anonymous> (jquery.dataTables.min.js?version=1.13.6:4:55209)
at B.draw (jquery.dataTables.min.js?version=1.13.6:4:53566) The error is caused by this line: Line 32 in 244f788
Or when an integer is involved: Uncaught TypeError: a.replace is not a function Like @themightystephen suggested, this can be circumvented by ensuring every value returned by the backend is a string using a PHP function like this: public function serializeTableRowDataArrayToJson(array $tableRowData) : string
{
$arrayWithStringValues = array_map(
static fn (mixed $value) : string => strval($value),
$tableRowData
);
return json_encode($arrayWithStringValues, JSON_HEX_TAG | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
} I agree that casting to a string in the plugin itself might be a better place to do... Note that this behaviour did not occur in for example version |
The plugin should really just allow for non-string types. If it isn't a string it can't contain a diacritic...! I'll look into that. |
The plug-in does actually cast to a string already: https://github.com/DataTables/Plugins/blob/master/sorting/src/diacritics-sort.ts#L320 . Could some one link me to a test case showing the issue so I can take a further look into it please? |
@AllanJard ah, maybe I hijacked an old issue then. My example was about any-number.js sorting plugin: Line 39 in 244f788
|
Thanks for the clarification. Fix committed here: 257a4c7 . Assuming you are happy with the fix, I'll close this issue off. |
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.:
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 casts
to a string to ensure it's never caught off-guard:The above worked for me before using the server-side solution mentioned above.
The text was updated successfully, but these errors were encountered: