boolean data and TypeError: sData.match is not a function
boolean data and TypeError: sData.match is not a function
rldean1
Posts: 141Questions: 66Answers: 1
If I try to return data that contains 0/1 or true/false, I get the "TypeError: sData.match is not a function". I must intercept and render the content for it to display properly, as shown below.
Is this normal?
table = $('#example').DataTable({
dom: "Bfrtip",
data: aoo,
columns: [
{ data: 'PosTitle', title: 'PosTitle' },
{ data: 'PosCode', title: 'PosCode' },
{
data: 'Publish',
title: 'Publish',
visible: true,
/*
* if the Publish column contains boolean data "true/false" or "0\1",
* I must use the Render function
*/
render: function (data, type, row) {
return (data == true) ? 'true' : 'false';
}
}
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not clear if the above code is working or not. Doesn't surprise me that you would need to render the text if the data contains true or false. If the data contains 0 or 1 it should show 0 or 1 without using render.
Maybe you can put together an example of your question:
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
As Kevin said, the DataTable will just display the data that's sent - if you send 0/1, it'll display 0/1.
I suspect there's a problem with this line though:
Data isn't a boolean, it's a string, so you'll need something like the following if you want to consolidate the booleans 1/true and 0/false into a single value:
Cheers,
Colin
@kthorngren and @colin
I tried as hard as I could and I could not replicate the issue. In the response string, whether we're dealing with "0", 0, false, or "false", DataTables renders correctly in the simulator.
This is not a critical situation, just a strange occurrence. I suppose I'll stumble upon the answer eventually.
Here's a Plunker example: https://plnkr.co/edit/GtgiDI?p=preview
Thanks, close this out!
I had wondered if returning a boolean value from a rendering function might cause this issue, but DataTables will cast it to be a string: http://live.datatables.net/xuneviho/1/edit .
If anyone else finds this thread with the same issue, if you could show us an example of the issue happening, that would be great. Until then, we'll consider it done .
Allan
@allan : I have discovered what led me to this question. I don't have an answer yet, but I wanted to comment here for you and posterity.
When I use SQL's
for json path
, some datatypes likesmallint
,bit
, anddecimal()
are not surrounded by double-quotes. You end up with something like this:"key": 0
instead of this:"key": "0"
Anyway, in some other tests, specifically with
decimal
andsmallint
, I discovered that as long as thevalue
in thekey: value
structure has double-quotes, DataTables will not require you to render the data in any special way. Basically, it avoids the "TypeError: sData.match is not a function" error.Anyway, I posted a comment on Stackoverflow with a better explanation: https://stackoverflow.com/questions/50936023/enforce-quotes-around-all-values-in-json-output
What's odd there is that DataTables will specifically convert integer data to be searchable as a string. Here is a little example showing it working: http://live.datatables.net/ziwuyake/1/edit .
Allan