Conditionally embed text in a row within a label
Conditionally embed text in a row within a label
I have a datatable.rb class with a data method that looks like this:
def data
text_messages.map do |text_message|
[
text_message.status.titleize,
text_message.scheduled,
text_message.message,
text_message.user.email,
text_message.updated_at,
link_to('', edit_text_message_path(text_message), class: "btn btn-primary fa fa-cog"),
link_to('', text_message_path(text_message), method: :delete, data: {confirm: "Are you sure you want to delete this text message?"}, :remote => true, class: "btn btn-danger fa fa-trash delete_text_message")
]
end
end
The text_message.status.titleize
call will return either Draft, In Queue, or Completed. I want to embed those in a label of a different color conditionally.
This is what I've tried so far:
`rowCallback: function(row, data, index) {
if (data[0]=='Draft') {
$(row).find('td:eq(0)').addClass('label label-warning')
}
}`
Basically if the data in the first column is Draft then embed in a warning label.
This does put the text inside of a label but the text gets pinned to the top left part of the screen and and line separating the first column from the second column disappears.
Please see image attached.
How do I do this without destroying the DataTable? I'm on 1.10
Thank you!
This question has an accepted answers - jump to answer
Answers
try the rendering option
http://live.datatables.net/qifusopu/1/edit
it turns the back ground color orange for old people (like me).
In you want the whole row colored, you would probably want to use the createdRow callback to add the class to the tr.
@bindrid thanks man! Do you know if there's any way to just fix the label? The alternative you proposed doesn't have rounded edges.... that's a problem lol.
Appreciate it!
you want round edges, I give you round edges http://live.datatables.net/qifusopu/2/edit
If that is not enough, about this http://live.datatables.net/qifusopu/4/edit
@bindrid HAHAHA you're the man. Appreciate you brother