Filter only specific data from Json source Data tables
Filter only specific data from Json source Data tables

Here is the data
https://api.myjson.com/bins/198yru?pretty=1
I want to only display those fields in my datatable
where condition game is dice
"game": "dice"
Currently i am showing my data as this
var table;
table = $('#data-table').DataTable({
"data" : data,
columns : [
{"data" : "id"},
{"data" : "amount"},
{"data" : "currency"},
{"data" : "stateDice.condition"},
{"data" : "payoutMultiplier",
render: function ( data, type, row ) {
return (data).toFixed(2) + "x";
}},
{"data" : "stateDice.result",
render: function ( data, type, row ) {
return (data).toFixed(2) + "";
} },
{"data" : "nonce"}
]
});
This is good for json source having all data with game dice. but if json source has other data also like json url mentioned above it gives errors.
any way i can only filter data with game dice.
This discussion has been closed.
Answers
What are the errors?
The best place to filter the data, if you can, is at the server with the server only returning the data you want. Since you are using
"data" : data,
then this suggests you already have the data as a Javascript variable. You can use a Javascript looping mechanism to build a new array with thedice
game objects you want and use something like"data" : newData,
.Kevin
@kthorngren
DataTables warning: table id=data-table - Requested unknown parameter 'stateDice.condition' for row 1, column 3.
As only
dice
game objects havestateDice
parameter others games don't have thatwill look into that any head up how i can do that i don't know much.
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
@colin Sorry didn't knew about those rules. will create some test cases and update here
@colin can you have a look at this ? link
you can test with 2 url's in getJSON
1. https://api.myjson.com/bins/ql2i2?pretty=1 (Json with only
game : dice
)2. https://api.myjson.com/bins/xsex6?pretty=1 (JSON with mix game types)
As @kthorngren said above i need to use some loop mechanism.
But i don't know how i can process data after pulling it from json source.
any references to manuals is welcomed.
Hope now you all have some clear view on my problem .
use a Javascript for loop. I took your data to show an example:
http://live.datatables.net/nucojado/1/edit
Kevin