How to use table attributes for ajax url
How to use table attributes for ajax url
chalist
Posts: 3Questions: 1Answers: 0
I have a table:
<table data-url="test.com"></table>
and in js:
$('table').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "---------------------",
"dataSrc": "data",
"type": "POST"
},
"columns": [
{"data": "id"},
{"data": "title"},
{"data": "title_en"},
{"data": "status"},
{"data": "city"},
{"data": "html"}
]
});
I want to use each table's data-url for datatable ajax URL.
Can I do this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Seems to work:
http://live.datatables.net/haretigo/1/edit
Kevin
@kthorngren Thanks dude, but I use table tag instead of ID.
I want this: http://live.datatables.net/haretigo/2/
The Multiple Table example uses the same technique to initialize Datatables. It does state this though:
Unfortunately the way you want to init the Datatables won't work for different URLs.
Interesting idea though. Maybe someone can find a clever alternative.
Kevin
To some extent it is actually possible, but you should note that jQuery 3 changed things a little so it is no longer possible to do nested data with a double dash (e.g.
data-ajax--url="..."
). It would work if you are using jQuery 1 though.Allan
Forgot about setting the options with the data attributes. This looks like it works:
http://live.datatables.net/dupuzubu/1/edit
But I was not able to get
data-ajax--url="..."
working with jQuery 1.9.1. Looks like the jQuerydata()
method returns it like this:ajaxUrl
.Learn something new each day
Kevin
....but forget something old...
One item in multiple out
Kevin
....tell me about it....
thanks, guys. That's worked.