Combining a URL with ID

Combining a URL with ID

mrgogomrgogo Posts: 5Questions: 1Answers: 0

How to do

MY Codes:

var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        "ajax": "staff.php",
        "table": "#example",
        "fields": [ {
                label: "First name:",
                name: "first_name"
            }, {
                label: "Last name:",
                name: "last_name"
            }, {
                label: "Position:",
                name: "position"
            }, {
                label: "Office:",
                name: "office"
            }, {
                label: "Extension:",
                name: "extn"
            }, {
                label: "Start date:",
                name: "start_date",
                type: "datetime",
                def:   function () { return new Date(); },
                format: 'DD.MM.YYYY HH:mm'
            }, {
                label: "Salary:",
                name: "salary"
            }
        ]
    } );
    
 
    var table = $('#example').DataTable( {
        lengthChange: false,
        ajax: {
            url: "xxx.php",
            type: "POST"
        },
        dom: "<'row'<'col-sm-6'><'col-sm-6'f>>" +"<'row'<'col-sm-12'tr>>" +"<'row'<'col-sm-5'li><'col-sm-7'p>>",
        processing: true,
        serverSide: true,
        columns: [
            { data: "first_name" },
            { data: "last_name" },
            { data: "position" },
            { data: "office" },
            { data: "start_date"},
            { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
        ],
        select: true,

1rd try :/

"columnDefs": [ {
    "targets": 1,
    "data": "first_name",
    "render": function ( data, type, row, meta ) {
      return '<a href="URL\test.php?ID='+data.ID+'">'+data+'</a>';     }
 }
]

this is returning http://URL/test.php?ID=undefined

2rd try :(

"columnDefs": [ {
    "targets": 1,
    "data": "first_name",
    "render": function ( data, type, row, meta ) {
      return '<a href="URL\test.php?ID='+data.RowID+'">'+data+'</a>';     }
 }
]

this is returning http://URL/test.php?ID=undefined

3rd try :s

"columnDefs": [ {
    "targets": 1,
    "data": "first_name",
    "render": function ( data, type, row, meta ) {
      return '<a href="URL\test.php?ID='+data.DT_RowID+'">'+data+'</a>';     }
 }
]

this is returning http://URL/test.php?ID=undefined

4rd try :'(

"columnDefs": [ {
    "targets": 1,
    "data": "id",
    "render": function ( data, type, row, meta ) {
      return '<a href="URL\test.php?ID='+data+'">'+data+'</a>';     }
 }
]

this is returning http://URL/test.php?ID=undefined

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Option 5 it is then :):

    "columnDefs": [ {
        "targets": 1,
        "data": "first_name",
        "render": function ( data, type, row, meta ) {
          return '<a href="URL\test.php?ID='+row.DT_RowId.replace('row_', '')+'">'+data+'</a>';     }
     }
    ]
    

    I'm assuming here that you are using the Editor PHP libraries? The row id is stored in DT_RowId and the replace is used since a prefix of row_ is added by default (to make it a valid HTML_4_ ID).

    Note also the use of row rather than data. The data property will point to whatever the first_name value is in this case (e.g. what columns.data points to).

    Allan

  • mrgogomrgogo Posts: 5Questions: 1Answers: 0

    Thank you very much for your help.

This discussion has been closed.