asp.net mvc - How to change the background of a cell dynamically in a Kendo MVC UI Grid? -


i need change backgroundcolor of kendo grid. code looks follows :

@(html.kendo().grid<tegelcheckermodel>()             .name("grid")             .cellaction(cell =>             {                 if (cell.column.title.equals("tegelzones"))                 {                     if (cell.dataitem.tegelzones.contains("extern"))                     {                         cell.htmlattributes["style"] = "background-color: red";                     }                 }             })             .columns(columns =>             {                 columns.bound(p => p.tegelnaam);                 columns.bound(p => p.tegelactief).headerhtmlattributes(new { style = "background: #800000;" }).clienttemplate("#if(tegelactief){# ja #}else{# nee #}#");                 columns.bound(p => p.tegelzones).headerhtmlattributes(new { style = "background: #800000;" }); })              .autobind(true)             .pageable()             .sortable()             .filterable()             .datasource(datasource => datasource             .ajax() //or .server()             .read(read => read.action("gettegels", "tegelchecker")             .data("getalvnummerandvoorwie"))             )         ) 

this code doesn't change background-color of cell. missing?

i succeeded partly. means able color part of cell using following code :

if (tegeltitel == "tegelactie") {     if ($("#tegelcheckeroverzicht_klantcontrol_klantddl").klantencontrol().getklant().alvnummer == "") {         html = kendo.format("<span>" + data.tegelactie + "</span>");     }     else {         if (data.tegelactieallowed) {             if (data.tegelactie == null) {                 html = kendo.format("<span></span>");             }             else {                 html = kendo.format("<span>" + data.tegelactie + "</span>");             }         }         else {             html = kendo.format("<span  style='background: red; color: white;font-weight:bold'>" + data.tegelactie + "</span>");         }     } } 

but means background of span colored , not entire cell.

ok found solution :

function griddatabound() { var data = this._data; (var x = 0; x < data.length; x++) {     var dataitem = data[x];     var tr = $("#grid").find("[data-uid='" + dataitem.uid + "']");     if (dataitem.selected) {         $("input:first", tr).attr("checked", "checked");     }       var alvnummer = $("#tegelcheckeroverzicht_klantcontrol_klantddl").klantencontrol().getklant().alvnummer;     if (alvnummer == "")     { }     else     {         var cell = $("td:nth-child(6)", tr); // zone         if (dataitem.hascorrectzone) {          }         else {             cell.addclass("myerror");         }         cell = $("td:nth-child(7)", tr); //actie         if (!dataitem.tegelactieallowed) {             cell.addclass("myerror");         }         cell = $("td:nth-child(8)", tr); //rollen         if (!dataitem.rolcodevoldaan) {             cell.addclass("myerror");         }      } } 

}

and in grid added :

.events(e => e.databound("griddatabound ")) 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -