Conditionally embed text in a row within a label

Conditionally embed text in a row within a label

itsjcitsjc Posts: 8Questions: 3Answers: 0

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

This discussion has been closed.