Can I have a link in cell but display different text?

Can I have a link in cell but display different text?

MickBMickB Posts: 103Questions: 25Answers: 2

At the moment, I am doing this:

                    {
                        "targets": {{$hyperlink_column}}, // the column to add it to
                        "data": "hyperlink",//the field to be used for the link - report_id

                        "render": function ( data, type, full, meta ) {
                            return '<a href="/showReport?report_id='+data+'"> **link **</a>';
                        }
                    }

Ideally, I would like to display a field, instead of link, or just the data value.

I know that I could use the full and get data from another field, by referring to another column number.
Is there any way I reference a field by it's name to retrieve the data?

The reason for this, is that I use this Datatable in a reporting system, to display the results of several different queries. I therefore use it multiple times, with differing fields and numbers of columns

Thanks,

Mick

This question has an accepted answers - jump to answer

Answers

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

    Is there any way I reference a field by it's name to retrieve the data?

    Is the "name" different from what you would find in the full parameter? Can you just use '+ full.myFieldName +' or similar?

    Allan

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    The columns.render documentation shows various ways to use the function.
    You will need to use "data.fieldname" to refer to a specific item in the row.

    https://datatables.net/reference/option/columns.render

  • MickBMickB Posts: 103Questions: 25Answers: 2
    edited July 2017

    full looks like this

    {0: "mysql", 2: "mick", hyperlink: "54"}
    

    Should that have the field names in?

    Looking at your example, you have:

    Object" emp_age": "66"emp_id: "333"emp_name: "cccc"__proto__: Object
    

    Hmmmm, why don't I have the field names....

    debug code: iqerip

  • MickBMickB Posts: 103Questions: 25Answers: 2

    One of my other Datatables gives this for full:

    {id: 52, name: "gfdsgfd", sql: "select * from reports;", area: "utilitytest", report_type: "datatable"}
    

    but I can't see what is different.

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin
    Answer ✓

    Should that have the field names in?

    It will depend totally on how you are populating the DataTable. The full parameter is giving you the original data object for the table - that might be an array or an object. It depends how you initialise the table. This section of the manual explains more about the underlying data.

    Allan

  • MickBMickB Posts: 103Questions: 25Answers: 2

    In this case, I create a HTML table, then just do this:

    var table = $('#lookupTable').DataTable({
    
  • MickBMickB Posts: 103Questions: 25Answers: 2
  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin

    If your table data is being read from HTML and you don't use columns.data, it will be read into an array - one element for each column.

    Allan

This discussion has been closed.