Ajax and custom html ?
Ajax and custom html ?
![Alexol](https://secure.gravatar.com/avatar/9b0ac30128b75fa4b41862f141fca046/?default=https%3A%2F%2Fvanillicon.com%2F9b0ac30128b75fa4b41862f141fca046_200.png&rating=g&size=120)
Hello, pardon my english. I'm newbie in datatables and I ask you a question :
$('#example').DataTable( {
serverSide: true,
ajax: '/data-source'
} );
Imagine data source return this JSON :
{
"draw": 1,
"recordsTotal": 2,
"recordsFiltered": 2,
"data": [
[
"1",
"Google",
"www.google.fr"
],
[
"2",
"Blabla",
"www.blabla.fr"
]
]
}
I want put this data in my html that (no indented, but sample):
<tr><td>1</td><td><a href="www.google.fr">Google</a></td></tr>
<tr><td>2</td><td><a href="www.blabla.fr">Blabla</a></td></tr>
Thank you for your answer
This question has an accepted answers - jump to answer
Answers
You would use
columns.render
to build the links. The docs have an example.Kevin
Thank you,
I have an another problem with Flask Jinja 2 (if you know...)...
Obsiousvly, Jinja transform before Javascript working, beacause url is: http://127.0.0.1/book/+data+
How can I change this ? Thank you
Bad edit in my previous post
I would write this :
return '<a href="{{ url_for('bp.book', pk_book='+data+') }}"> '+data+'</a>';
UP
I'm not familiar with the
url_for
function of Flask but you probably need to escape some of the single quotes with back slashes, for example:This way the single quotes are apart of the string.
Kevin
Ok, but the problem is url_for working before javascript, so, the variable in pk_book is... "+data+"...
url_for is a simple function which return a link.
Sounds like you need to have Flask evaluate that function before the Javascript is executed. I think you'd probably need to ask in a Flask forum for how to do that.
Allan