Render a URL link on column in Editor datatable

Render a URL link on column in Editor datatable

webpointzwebpointz Posts: 126Questions: 30Answers: 4
edited December 2015 in Editor

In my datatable in the first column, I want to make the first column text a link to another file and pass the database table "id" in the url path.

I tried the following code, however, I'm not sure how to access the "id" column in the database:

"columnDefs": [ {
                        "targets": 0,
                        "data": null,
                        "render": function ( data, type, full, row ) {
                            return '<a href="addkititems.php?id=' + full + '">' + data + '</a>';
                            }
                        } ] 

When I run the file, I get "[object Object]" in the url.

Here are the JS and PHP coded files:

JS File:

/*
 * Editor client script for DB table table_addresses
 * Created by http://editor.datatables.net/generator
 */

(function($){

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        "ajax": "php/table.newkits.php",
        "table": "#newkits",
        
        "i18n": {
            "edit": {
            "button": "Edit Kit Type",
            "title":  "Update Kit Type",
            "submit": "Update Kit Type"
            },
            "create": {
            "button": "Add Kit Type",
            "title":  "Add Kit Type",
            "submit": "Add Kit Type"
            }},         
        
        "fields": [

            {
                "label": "Kit Name",
                "name": "kitname"
            },
            {
                "label": "Comments",
                "name": "comments"
            }
        ]
    } );

    $('#newkits').DataTable( {
        "dom": "Tfrtip",
        "ajax": "php/table.newkits.php",
        "columns": [
            {
                "data": "kitname"
            },
            {
                "data": "comments" 
            }
        ],  
        
        "tableTools": {
            "sRowSelect": "os",
            "aButtons": [
                { "sExtends": "editor_create", "editor": editor },
                { "sExtends": "editor_edit",   "editor": editor }
            ]
        }
    } );
} );

}(jQuery));

PHP File:

<?php

/*
 * Editor server script for DB table newkits
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;


// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'newkits', 'id')
    ->fields(
        Field::inst( 'kitname' )
            ->validator( 'Validate::notEmpty' )
            ->validator( 'Validate::unique' ),
        Field::inst( 'comments' )
    )
    ->process( $_POST )
    ->json();

This question has an accepted answers - jump to answer

Answers

  • webpointzwebpointz Posts: 126Questions: 30Answers: 4
    Answer ✓

    Hi

    Resolved my issue by adding the following:

    Field::inst( 'id' ),
    

    to my PHP file and then referenced using " + full.id + " in the URL

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yes - that's the way to do it.

    Allan

This discussion has been closed.