Displaying different child row data based on another column
Displaying different child row data based on another column

So currently, I'm displaying a child row to display extra data that differs based on what category it is in which is pulled from a JSON file. The only thing is, I'm currently able to display the child row data for one category, but I'd like to have it to where it only displays it based on what category the parent row is in. Each parent row would have its own specific child row data, but again it would differ based on the category. There are about 9 categories, how would I go about doing this? Here is an example of my JSON data:
[{"id":"1234567fef","category":"cat1","nonce":2490,"currency":"usd","amount":1,"payoutMultiplier":0,"payout":0,"createdAt":"2020-01-19T00:07:13.930Z","updatedAt":"2020-01-19T00:07:13.930Z","stateCategory1":{"drawnNumbers":[21,37,39,8,19,10,35,11,29,12],"selectedNumbers":[6,21,10,16,26,12,36,31,1],"risk":"high"},"clientSeed":"123456"}
The data within stateCategory1 would be what I am trying to display. The data within it differs based on the category, however each category has the same number and types of data. Currently, I'm able to use this to display for a single category, but obviously I get an error thrown for parent rows that are in a different category:
function format ( d ) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td style="font-weight:bold;">Numbers Drawn:</td>'+
'<td>'+d.stateCategory1.drawnNumbers+'</td>'+
'</tr>'+
'<tr>'+
'<td style="font-weight:bold;">Selected Numbers:</td>'+
'<td>'+d.stateCategory1.selectedNumbers+'</td>'+
'</tr>'+
'<tr>'+
'<td style="font-weight:bold;">Risk Level:</td>'+
'<td>'+d.stateCategory1.risk+'</td>'+
'</tr>'+
'</table>';
}
This question has an accepted answers - jump to answer
Answers
You can do whatever you want in the format() function. You can use if statements to determine which category to return. Its more a Javascript exercise to do what you want than a Datatables. Please build an example with your data if you need further help.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
So this is what I currently have - Not sure why it's not running properly, but you can see the JS I'm using. If you could possibly help me with implementing the if/elseif statement for 2 categories, Im sure I could figure out the rest. Thanks again!
http://live.datatables.net/veciquxi/1/edit
Actually I was able to figure it out with the info you provided already
Thanks as usual Kevin