[Server Processing] [Conditional Child Rows] How can i pick Ajax Data with different items quantity?
[Server Processing] [Conditional Child Rows] How can i pick Ajax Data with different items quantity?
Hello everyone, thanks in advance for giving a hand in my question.
I'm actually trying to apply conditional child rows and server-processing load from an ajax file, that contains, for example the following data:
{
"data": [
{
{
"id_producto": "161",
"titulo": "Tira led 5630 IP20 (interior) monocromática (de un color) x 5 metros - NO INCLUYE FUENTE",
"categoria": "Tiras led, fuentes y accesorios",
"tipo": "Variante",
"stock": "-",
"costo": "-",
"mayorista": "-",
"minorista": "-",
"id_variante": "229",
"titulo_229": "Tira led 5630 IP20 (interior) monocromática (de un color) x 5 metros - NO INCLUYE FUENTE",
"stock_229": "4",
"costo_229": "0",
"mayorista_229": "890",
"minorista_229": "1190"
},
{
"id_producto": "162",
"titulo": "Tira led 5050 RGB IP65 efectos automáticos (Incluye fuente de 12v a 220V) x 5 metros",
"categoria": "Tiras led, fuentes y accesorios",
"tipo": "Standard",
"stock": "3",
"costo": "$0",
"mayorista": "$1120",
"minorista": "$1450"
},
}
]
}
I mean, which function may i use for picking the data, even if it's different in each block?
In this URL i can see a good example, but i couldn't find anything for this situation: https://datatables.net/examples/server_side/row_details.html
function format ( d ) {
return 'Full name: '+d.first_name+' '+d.last_name+'<br>'+
'Salary: '+d.salary+'<br>'+
'The child row can contain any data you wish, including links, images, inner tables etc.';
}
It must be something like a while loop, right?
On the otherside, data block #1 child info starts at "id_variante": "229", but data block #2 does not have child rows. I've been reading this topic but i couldn't imagine yet how can i apply both of this conditionals in my JS function, JS it's not my best: https://datatables.net/forums/discussion/55576/how-to-conditionally-implement-child-rows
Any help will be appreciated.
Thanks!
This question has an accepted answers - jump to answer
Answers
You can use
rows.every()to loop all the rows to choose what you want to display.Are you wanting to not display the plus sing if the
id_variantedoesn't exist? There is an example in the thread you linked but it has an error. I updated the example here:http://live.datatables.net/pifugoki/129/edit
Kevin
Thank you so much for your reply @kthorngren
http://live.datatables.net/pifugoki/129/edit -> PERFECT
rows.every() API URL it's returning 404 error, is it ok?
Thank you again!
I think it's https://datatables.net/reference/api/rows().every()
Am i right?
Yep, that's right,
rows().every().Colin
Thank you both!