boolean data and TypeError: sData.match is not a function

boolean data and TypeError: sData.match is not a function

raydlevel5raydlevel5 Posts: 40Questions: 17Answers: 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


  • kthorngrenkthorngren Posts: 2,682Questions: 19Answers: 596

    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:


  • colincolin Posts: 875Questions: 0Answers: 168

    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:

      return (data == true) ? 'true' : 'false'

    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:

       return ["1", "true"].includes(data)? 'true', 'false';



  • raydlevel5raydlevel5 Posts: 40Questions: 17Answers: 1
    Answer ✓

    @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:

    Thanks, close this out!

  • allanallan Posts: 46,189Questions: 1Answers: 6,410 Site admin

    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: .

    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 :).


Sign In or Register to comment.