Checking data type in renderer

Checking data type in renderer

NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I am trying to check render type (display, sort, ...) and not getting the right value and can't figure out what I am doing wrong.

When I debug and check the renderer's parameters, 'data' is an IP address, 'row' is all the column values and 'type' is always "type" instead of "display" or "sort" or ...

It is a simple check and should work out of the box:

"columns": [
    {
        "data": "CLIENTIP",
        "render": function (data, type, row) {
            if (type === 'display') {                 // This returns "type", "if" statement never executes
                var cellContent = '';

                if (null != data && '' != data) {
                    cellContent = "<span class='PageLink'>" + data + "</span>";
                }
                return cellContent;
            }
            return data;
        }
    }, {
            ...
    }

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    This example here may help. It's using columns.render in a similar fashion to you. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Colin

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2
    Answer ✓

    Thank you @colin

    I wanted to open a modal showing details when IP address was clicked. I solved the issue using below and bypassing the "type" check.

    "columns": [
        {
            "data": "CLIENTIP",
            "render": function (data, type, row) {
                cellContent = "<span class=\"ml-2 PageLink rowDetail\"><a href='javascript:' title='Show Details'>" + data + "</a></span>";
                return cellContent;
            }
        }, {
                ...
        }
    ]
    
    $('#myTable').on('click', '.rowDetail', function () {
        let rowData = $('table').DataTable().row($(this).closest('tr')).data();
        showDetail(rowData);
    });
    

    Thank you for your feedback. Love datatables even though it has caused losing a few strands of hair every now and then :smile:

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Looks like a good solution - thanks for posting back :)

    Allan

Sign In or Register to comment.