2016-08-06 242 views
0

是否可以設置django-tables2中列的背景顏色?我的行由2個不同的對象數據組成,所以我必須讓user簡單地區分它們。爲列設置背景顏色

例如通過更改該列的css類。

class AdminPairTable(tables.Table): 
    reservation_1_destination_from = tables.TemplateColumn("""{{ record.0.destination_from }}""") 
    reservation_1_destination_to = tables.TemplateColumn("""{{ record.0.destination_to }}""") 
    reservation_1_date_departure = tables.TemplateColumn("""{{record.0.date_departure}}""") 
    reservation_1_time_departure = tables.TemplateColumn("""{{record.0.time_departure}}""") 
    reservation_1_specification = tables.TemplateColumn("""{{record.0.specification}}""") 
    reservation_2_destination_from = tables.TemplateColumn("""{{ record.1.destination_from }}""") 
    reservation_2_destination_to = tables.TemplateColumn("""{{ record.1.destination_to }}""") 
    reservation_2_date_arrival = tables.TemplateColumn("""{{record.1.date_arrival}}""") 
    reservation_2_time_arrival = tables.TemplateColumn("""{{record.1.time_arrival}}""") 
    reservation_2_specification = tables.TemplateColumn("""{{record.1.specification}}""") 
    confirm_pair = tables.TemplateColumn("""<button class="btn btn-success">Zaradiť pár</button>""") 

它在我腦海中的唯一方法就是使用JQuery,但它不是一個最好的辦法。

回答

0

您可以在創建列時設置column attributes

不知道爲什麼你使用TemplateColumn只呈現一個值,只是Column將在這裏工作過(除了當然confirm_pair)。