How would i go about getting this data into columns? - Fiddle Included
How would i go about getting this data into columns? - Fiddle Included
SamuelNZ
Posts: 62Questions: 5Answers: 2
<script>
$(document).ready(function() {
$('#example').DataTable( {
"ajax":
{
"url":"http://gaming.adduce.co.nz:8888/getPlayerKillsHistory?ids=76561198061378579",
"cache": true,
"dataSrc": function (json) {
var return_data = new Array();
for(var i=0;i< json.length; i++){
return_data.push()
}
console.log (json);
return return_data;
}
},
"columns" : [
{'data': 'PlayersKillsHistory.PlayersKillsHistory.76561198061378579.deaths.idKiller'},
{'data': 'PlayersKillsHistory.PlayersKillsHistory.76561198061378579.deaths.dateTime'},
{'data': 'PlayersKillsHistory.PlayersKillsHistory.76561198061378579.deaths.killerName'}
]
});});
</script>
<table id="example" class="display" width="100%">
<thead><tr>
<th>Killers SteamID</th><th width="200px">Name</th><th>Date/Time</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>Killers SteamID</th><th width="200px">Name</th><th>Date/Time</th>
</tr></tfoot>
</table>
Okay, So i was able to turn PlayersKillsHistory into an Array as required by DT, But now i'm having trouble getting the data into the columns. The screenshot below shows the structure:
View post on imgur.com
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Created a JSFiddle: http://jsfiddle.net/n3p0mcto/1
Fiddle doesnt really help, since the AJAX source returns no data
Hers one with a change I made, but the error being thrown is that its not finding anything from the ajax src
Hey again jLinux!
I tried your changes and now its throwing:
Lol... Thats what im saying...
Thus, your
ajax
source isnt returning anythingThat will run if you save it as HTML
Oh, Is that because its missing a question mark?
It needs to be in exactly this format:
http://gaming.adduce.co.nz:8888/getPlayerKillsHistory?ids=76561198041352960
Or it responds with bad request.
Oh, weird, ive always been able to use the
ajax.data
to pass the data.I changed the
ajax.url
back to the one you pasted above, and heres the weird part (def server side related), when I visit that URL in the browser, its all populated just fine, when I run the JSFiddle, and view the content of the AJAX request, heres the result: http://d.pr/i/qWESSo that error
Cannot read property 'length' of undefined
is because its empty, it doesnt see any content to pullEdit: Nevermind i misunderstood. I'm not sure how to fix this :/
Why is it returning empty even with a valid id?
lol, that has nothing to do with DataTables, thats totally server related. I can't see that code
The server has nothing to do with how the client is handling the data.. It will always give out the entire array.
Its blank because of something happening in that code.
http://gaming.adduce.co.nz:8888/getPlayerKillsHistory?ids=76561198041352960
Will always give out:
no matter how you ask for it, So it is something to do with data tables.
DataTables, again, is passing things into my code where i haven't asked for them:
Where is it getting &_=1447235343130 from? That shouldn't be in the request and it would be working if it wasn't doing this.
It looks like epoch time? What is epoch time doing in my request?
Edit:
Datatables is ignoring
Looks like the code on the server gets confused when the
ajax.cache
is set, I turned it off and used theajax.data
, as opposed to adding theids
on theajax.url
.You're also trying to specify the
dataSrc
outside of theajax
, keep in mind itsajax.dataSrc
, meaning it goes inside theajax
settings..Also, you're trying to return an array from the
ajax.dataSrc
, I dont think thats right... the dataSrc is supposed to be the root of where the data is pulled from, and I tried passing something likePlayersKillsHistory[0].76561198041352960.deaths
, and it didnt work (As I expected)http://jsfiddle.net/n3p0mcto/5/
Is returning the array properly and honoring cache, But still not populating the table.
So that means
Cannot read property 'length' of undefined
Isn't caused by the empty array, Hmm, i wonder whats wrong.
"Also, you're trying to return an array from the ajax.dataSrc, I dont think thats right... the dataSrc is supposed to be the root of where the data is pulled from, and I tried passing something like PlayersKillsHistory[0].76561198041352960.deaths, and it didnt work (As I expected)"
Allan is the one who suggested using dataSrc as a function.
So.. Why isn't this working.. Looks perfect to me.. The length issue is solved, the array is present, no errors.. but still "No data available in table"
See this thread where the same issue is discussed.
Allan
Thank you Allan! That worked great!
So it always was a simple task :P Knew i could expect simplicity from DT, I should have been more specific about what i was wanting to do.