How to render Hyperlink with JSON data

How to render Hyperlink with JSON data

karthiktrml14karthiktrml14 Posts: 2Questions: 1Answers: 0
edited February 2016 in Free community support

Hi, I am new to Datatables and really liked the plugin very much. I want to render hyper link for a column in the datatable. I have read the documentation on mRender and still not able to figure it out. Please find my JQuery and JSON data.

{
 "model": "Forms.schememodel",
        "pk": 6,
        "fields": {
            "scheme_name": "Test Scheme 002",
            "as_date": "2016-02-16",
            "dept_name": 1,
            "admin_sanction_number": "AS Number",
            "admin_sanction_amount": 5468465,
            "budget": "PLAN",
            "head_of_account": "EE",
            "mode_of_payment": "PAO",
            "created_on": "2016-02-04T04:56:04.803Z",

}

Jquery used to render the DataTables:


var table_data; $(document).ready(function() { $.ajax({ url: '{{ ajaxURL }}', success: function(data){ table_data = data; console.log(table_data) console.log(" The Data has been Loaded !") $('#data-table').dataTable({ "aaData": table_data, "aoColumns": [ { "mDataProp": "fields.scheme_name", "fnRender": function(oObj){ return '<a href="google.com"></a>' } }, { "mDataProp": "fields.admin_sanction_number" }, { "mDataProp": "fields.as_id" }, { "mDataProp": "fields.budget" }, { "mDataProp": "fields.head_of_account" }, { "mDataProp": "fields.mode_of_payment" }, { "mDataProp": "fields.created_on" } ] }); } }); } );

I want to make the scheme_name to href using the pk value.

Any help would be very much appreciated.

Thanks

This question has an accepted answers - jump to answer

Answers

  • karthiktrml14karthiktrml14 Posts: 2Questions: 1Answers: 0
    edited February 2016

    Solved the error. Using mRender:

    $('#data-table').dataTable({
                            "aaData": table_data,
                            "aoColumns": [
                                { "mDataProp": "fields.scheme_name",
                                                "mRender": function(oObj){
                                                    return '<a href=""></a>'
                                                }
     
                                },
                                { "mDataProp": "fields.admin_sanction_number" },
                                { "mDataProp": "fields.as_id" },
                                { "mDataProp": "fields.budget" },
                                { "mDataProp": "fields.head_of_account" },
                                { "mDataProp": "fields.mode_of_payment" },
                                { "mDataProp": "fields.created_on" }
        ]               });
    
  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Feedback: mDataProp is a very old property. I would suggest using columns.data and columns.render. The full lsit of current optinos can be found in the reference.

    Allan

This discussion has been closed.