One hyperlink displays; one doesn't

One hyperlink displays; one doesn't

MontereyDeanMontereyDean Posts: 13Questions: 1Answers: 0

Hi! I'm using the server-side processing script, mysql and ajax. On the following page, the page link doesn't display as a link; but, the file link shows a link:

http://www.mcwd.org/service_forms.html

This is the code I'm using for those two columns:

    "columnDefs": [ {
        "targets": 2,
        "render": function ( data, type, full, meta ) {
            return '<a href=\"'+data+'\" target=\"_blank\">Visit</a>';
            },
        "targets": 4,
        "render": function ( data, type, full, meta ) {
            return '<a href=\"/'+data+'\" target=\"_blank\">View</a>';
            }
     } ]

Any idea why one works and one doesn't?

Replies

  • MontereyDeanMontereyDean Posts: 13Questions: 1Answers: 0

    Or, if I remove target 4, then target 2 works. Is it possible to have only 1 hyperlink per table?

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin

    On the page you link to (but not the code above) you have two different columnDefs properties in the initialisation object. You can't do that I'm afraid - you can only have a single columnDefs array. But simply give it multiple objects to define multiple targets. You can have as many columns with links as you want!

    Allan

  • MontereyDeanMontereyDean Posts: 13Questions: 1Answers: 0

    Yes, sorry. I tried two columnDefs when the above wouldn't work. Is there anyone who can tell me how to "simply give it multiple objects to define multiple targets"? Or point me to a page that shows me how?

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin

    What I meant was you would do something like:

    columnDefs: [
      { ... object 1 },
      { ... object 2 }
    ]
    

    where object 1 and object 2 are the column definition objects (with their own targets value).

    Allan

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin

    Based on your code above you would have something like:

    "columnDefs": [{
        "targets": 2,
        "render": function(data, type, full, meta) {
            return '<a href=\"' + data + '\" target=\"_blank\">Visit</a>';
        },
    }, {
        "targets": 4,
        "render": function(data, type, full, meta) {
            return '<a href=\"/' + data + '\" target=\"_blank\">View</a>';
        }
    }]
    

    Allan

  • MontereyDeanMontereyDean Posts: 13Questions: 1Answers: 0

    Oh, my, gosh! Thank you so much. I was missing "}, {" between the two targets.

This discussion has been closed.