DataTables rendering custom column
Asked Answered
P

1

8

Is it possible to render custom column in DataTables.net? I've read a lot of tutorials and documentations, but cannot make it working. I would like to create thirds column with link where I use information from first column. My code looks like these:

$(document).ready(function () {
    $('#categories').DataTable({
        "ajax": '@Url.Action("Table", "Categories")',
        "columns": [
            { "data": "Name" },
            { "data": "Parent" },
            null
        ],
        "columnsDefs": [
            {
                "render": function(data){
                    return "<a href='~/Admin/Categories/Edit' + data.Name + '>EDIT</a>";
                },
                "targets": 0
            }
        ]
    });
});

In json I'm only getting Name and Parent column informations. Any ideas to create third column with Name inside it? Thanks!

Phemia answered 27/1, 2017 at 18:19 Comment(0)
P
21

Okay, so I've managed to do it by myself. Here is the answer for next generations:

 $(document).ready(function () {
    $('#categories').dataTable({
        "ajax": '@Url.Action("Table", "Categories")',
        "aoColumns": [
            { "data": "Name" },
            { "data": "Parent" },
            {
                "mData": "Name",
                "mRender": function (data, type, row) {
                    return "<a href='Admin/Categories/Edit/" + data + "'>EDIT</a>";
                }
            }
        ]
    });
});
Phemia answered 28/1, 2017 at 11:2 Comment(3)
Unfortunately, I don't have this project on my disk anymore. If you have any questions maybe I'll help you :)Phemia
thanks! I actually figured out my problem the other dayRundown
Cool! Good to hear that!Phemia

© 2022 - 2024 — McMap. All rights reserved.