Is it possible to swap the end of a URL from .xml to .html in the columnDefs area?

Is it possible to swap the end of a URL from .xml to .html in the columnDefs area?

redroosterdesignredroosterdesign Posts: 19Questions: 3Answers: 0

I want to change the URL being pulled in from JSON from a .xml to a .html. Is that possible?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,993Questions: 26Answers: 4,887

    You can use columns.render to modify the data.

    Kevin

  • redroosterdesignredroosterdesign Posts: 19Questions: 3Answers: 0

    I've tried all kinds of options with no luck. Not sure this is even a dataTables issue as much as a script issue. This is what I'm using:

    {
    "targets": [7],
    "data": "url",
    "render": function ( data, type, row, meta ) {
    return '<a class="catalog-link" href="'+data+'">'+'View in Catalog'+'</a>';
    },
    }

    Would I add code here to change the end of the URL from .xml to .html? I can't figure out how to change what's in the +data+ area. Or if this is even the correct place to do it.

  • kthorngrenkthorngren Posts: 20,993Questions: 26Answers: 4,887
    edited July 19 Answer ✓

    I don't know what value data contains but if you want to replace text then use a Javascript text replace method like replace(). For example:

    return '<a class="catalog-link" href="' + data.replace(".xml", ".html") + '">'+'View in Catalog'+'</a>';
    

    Kevin

  • redroosterdesignredroosterdesign Posts: 19Questions: 3Answers: 0

    That worked! I didn't know I could put the javascript directly attached to the data. Thank you so much!

Sign In or Register to comment.