[Solved] How to add { data: "c.column" } as a variable in defaultcontent:?

[Solved] How to add { data: "c.column" } as a variable in defaultcontent:?

revelnoderevelnode Posts: 5Questions: 2Answers: 0
edited November 2016 in Free community support

Hello. I am trying to figure out how to add links to the end of rows for things like "view" "edit" "delete". The Delete I will be using the Ajax method, but for view and edit, I want to have it go to a PHP URL. I am currently using CodeIgniter and the CodeIgniter DataTable Library by Paul Zepernick.

Here is my JS so far:

$(function () {
    $("#demo-dynamic-tables-2").dataTable({
        processing: true,
        serverSide: true,
        ajax: {
            "url": "/customers/dataTable",
            "type": "POST"
        },
        columns: [
            {data: "c.name"},
            {data: "c.contact"},
            {data: "c.phone"},
            {data: "c.fax"},
            {data: "c.email"},
            {data: null, defaultContent: "<span class='bg-linkedin rounded sq-24'><span class='icon icon-eye'></span></span><span class='bg-linkedin rounded sq-24'><span class='icon icon-pencil'></span></span><span class='bg-googleplus rounded sq-24'><span class='icon icon-remove'></span></span>"}
        ]
    });
});

This puts out 3 buttons at the end, an eye (for view) a pencil (for edit) and an X (for delete)
I want the view to go to /customers/view/("c.customer_id") But I have no idea how to implement it. Same for Edit, I want it to link to /customer/edit/("c.customer_id").

Now in my controller I do have the following call:

$this -> load -> library('Datatable', array('model' => 'customer_model', 'rowIdCol' => 'c.customer_id'));

So rowIdCol is already set, but how can I use it?

Answers

  • revelnoderevelnode Posts: 5Questions: 2Answers: 0
    edited November 2016

    Found my answer in the docs.... Have to use render..

    $('#example').dataTable( {
      "columnDefs": [ {
        "targets": 0,
        "data": "download_link",
        "render": function ( data, type, full, meta ) {
          return '<a href="'+data+'">Download</a>';
        }
      } ]
    } );
    
This discussion has been closed.