Chnage the content of a non-database column based on a database field
Chnage the content of a non-database column based on a database field
I have a table with a few fields. I then added a column with three Action button that do stuff. Everything works fine. I use the following code
{
data: null,
defaultContent: '<div class=\"btn-group\"><a id=\"edit-button\" data-toggle=\"tooltip\" title=\"Επεξεργασία\" class=\"btn btn-xs btn-default editor_edit\"><i class=\"fa fa-pencil\"></i></a><a id=\"delete-button\" data-toggle=\"tooltip"\ title=\"Διαγραφή\" class=\"btn btn-xs btn-danger editor_remove\"><i class=\"fa fa-times\"></i></a><a id=\"change-status-button\" data-toggle=\"tooltip\" title=\"Delete\" class=\"btn btn-xs btn-stop editor_change\"><i class=\"fa fa-stop\"></i></a></div>',
className: 'center'
}
My next crazy idea that I need tips on is as follows:
Depending on the value of another field named status I want to alter the defaultContent. E.g. If a user's status is set to "Inactive" which is a value of 0 in my db the defaultContent should be
defaultContent: '<div class=\"btn-group\"><a id=\"edit-button\" data-toggle=\"tooltip\" title=\"Επεξεργασία\" class=\"btn btn-xs btn-default editor_edit\"><i class=\"fa fa-pencil\"></i></a><a id=\"delete-button\" data-toggle=\"tooltip"\ title=\"Διαγραφή\" class=\"btn btn-xs btn-danger editor_remove\"><i class=\"fa fa-times\"></i></a><a id=\"change-status-button\" data-toggle=\"tooltip\" title=\"Delete\" class=\"btn btn-xs btn-stop editor_change\"><i class=\"fa fa-play\"></i></a></div>'
All I did was change fa fa-stop to fa fa-play here. Any ideas?
This question has an accepted answers - jump to answer
Answers
columns.defaultContent
is only suitable for static content. You need to usecolumns.render
if you want the output to be dynamic based on the data in the row. See the renderers section in the manual.Allan
Solved with a renderer. I should of thought of that since I had used them before I just forgot that data actually hold that data for a whole row so I did