Using PHP to query a MySQL DB within the datatable `columns: [`
Using PHP to query a MySQL DB within the datatable `columns: [`
WebCodex
Posts: 71Questions: 13Answers: 3
I'm looking for a way to query a database with a function and render data in the column based on that returned data.
It's a simple true / false switch based on some user info.
This has to be done as the table is loaded.
{ 'data': 'upvote',
"render": function ( data, type, row, meta ) {
// Query DB - return true / false - return data
if(variableFromFunction == true) {
return data;
}
else {
return data + "<i class='upvote fas fa-thumbs-up'></i>";
}
},
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Its not recommended to perform ajax requests in
columns.render
. Ajax is an async process plus it would slow down rendering the table. Can you return the desired data with your original ajax request? You don't need to display it in the table but if your DB query can return the data with the row data you can easily access it incolumns.render
.Kevin
Thanks, I should have thought of that!