How do I add a Custom Column?

How do I add a Custom Column?

HillChris1234HillChris1234 Posts: 27Questions: 13Answers: 2

I've read the articles on defaultContent and render, but they aren't helping.

Basically what I want to do is create a column where text is concatenated to the data when it's rendered. So, something like:

        $('#myTable').DataTable({
            "ajax": {
                "url": "/Brokers/loaddata",
                "type": "GET",
                "datatype": "json"
            },
            "columns": [
                { "data": "Code" },
                { "defaultContent": "Your code is " + data.Code }
            ]
        });

This would create 2 columns. One would have the Code returned from the Json. The other would have the code concatenated onto a string saying "Your code is ".

Answers

  • HillChris1234HillChris1234 Posts: 27Questions: 13Answers: 2

    I figgered it out! Here's the answer:

            $('#myTable').DataTable({
                "ajax": {
                    "url": "/Brokers/loaddata",
                    "type": "GET",
                    "datatype": "json"
                },
                "columns": [
                    { "data": "Code" },
                    {
                        "data": function (row, type, val, meta) {
                            return "Your code is " + row.Code;
                        }
                    }
                ]
            });
    
This discussion has been closed.