Can't customize render of column to display a link

Can't customize render of column to display a link

ul1ssesul1sses Posts: 6Questions: 1Answers: 0

I don't know what i'm doing wrong, but using the render function on columnsDefs or columns options is not working.
I need to change the column "amount_b_f" to render a link.

  • Datasource is a array of objects wich is set on "data" option manually before calling Datatables() constructor. There is no server processing.

TEST CODE

var dataTableConfig = {
        dom: 'frtipB',
        buttons: [
            {extend: "copy", text: "Copy"},
            {extend: "print", text: "Print"},
            {extend: "excel", text: "Excel"}
        ],
        "scrollY": "45vh",
        "autoWidth": false,
        "processing": false,
        "serverSide": false,
        "language": {
            "sEmptyTable": "",
            "sZeroRecords": ""
        },
        "paging": false,
        "lengthChange": false,
        "info": false,
        "searching": false,
        "aaSorting": [],
        "orderMulti": false,
        "columnDefs": [
            {className: "dt-body-right", "targets": [3]},
            {className: "dt-body-center", "targets": [1, 2]}
        ],
        "columns": [
            {
                data: {
                    "_": "type",
                    "display": "type_f"
                }
            },
            {
                data: {
                    "_": "amount_a",
                    "display": "amount_a_f"
                }
            },
            {
                data: {
                    "_": "amount_b",
                    "display": "amount_b_f"
                }
            },
            {
                data: {
                    "_": "total",
                    "display": "total_f"
                }
            }
        ],
        "data": []
    };
    dataTableConfig.data = [some data];

    $('#tabType').DataTable(dataTableConfig);

This question has an accepted answers - jump to answer

Answers

  • ul1ssesul1sses Posts: 6Questions: 1Answers: 0

    Tried to use on columnsDefs, but the funcion is never called:

    {
        "render": function (data, type, row) {
            console.log("render #1");
            return "<a href='test'>" + data + "</a>";
        },
        "targets": [2]
    }
    
  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    Answer ✓

    Hi @ul1sses ,

    This example here shows a link in a table. What you had should work, so not sure what was going wrong. If still no joy, could you modify my example to demonstrate the problem, please.

    Cheers,

    Colin

This discussion has been closed.