TypeError in ColumnControl v1.0.6 when handling null values

TypeError in ColumnControl v1.0.6 when handling null values

TerraX3000TerraX3000 Posts: 21Questions: 7Answers: 1

Link to test case: https://live.datatables.net/reluqabe/1/
Link to Ajax data for test case: https://dummyjson.com/c/1e17-073c-43a5-9cca

Description of problem:

When using DataTables ColumnControl v1.0.6, a TypeError occurs when the table contains null values and the columnControl's searchlist feature attempts to process these values:

Uncaught TypeError: Cannot read properties of null (reading 'toString')
    at L (datatables.min.js:44:24350)

Steps to Reproduce:

Initialize DataTable with columnControl and searchlist enabled
Have data containing null values in columns
View the developer console to observe error message

Root Cause Analysis
The error occurs because fastData() can return null values, but the code attempts to call toString() on these values without checking for null first.

Reference commit Fix: Non-string data types could cause -content searchList to not match selected options.:
https://github.com/DataTables/ColumnControl/commit/416af3c276c0485565e5fc9476ecf478f74b7b6d

let filter = settings.fastData(rows[i], idx, 'filter').toString();

Suggested Fix:
The plugin should implement null checks before calling toString() on values. In the searchList.ts source, this would look like:

var filter = settings.fastData(rows[i], idx, 'filter');
filter = filter !== null ? filter.toString() : '';

Answers

  • allanallan Posts: 64,644Questions: 1Answers: 10,687 Site admin

    Hi,

    Thank you for letting me know about that error! I've committed a fix to address the problem and will tag a release with the change soon (hopefully tomorrow).

    Allan

  • TerraX3000TerraX3000 Posts: 21Questions: 7Answers: 1

    You are welcome--thanks for the quick fix!

Sign In or Register to comment.