i am using kendo ui grid in MVC4 project. Below is my code
@(Html.Kendo().Grid(Model)
.Name("gridexcel")
.Columns(columns =>
{
columns.Bound(c => c.ExcelId).Title("Id").Visible(false);
columns.Bound(c => c.status).Title("Status").Width(100);
columns.Bound(c => c.report_date).Title("Report Date");
columns.Bound(c => c.code).Width(50);
and columns from 1 to 50... }
Here i want to check cells of columns from 1 to 50, whether it contains 0 or 1. if 0 then i want to change background color. please help..
Here is a a jsbin of what you described
http://jsbin.com/zusutigi/17/edit?css,js,output
To accomplish this, first hook into the DataBound event in your kendo mvc wrapper. http://docs.telerik.com/kendo-ui/api/wrappers/aspnet-mvc/kendo.mvc.ui.fluent/grideventbuilder
...
.Name("gridexcel")
.Events(events => events.DataBound(
@<text>
onDataBound
</text>
))
)
...
Then to check all cells in columns 1 - 50 for a 1 or a 0 you would add this javascript.
var containsOne = function(checkForOne) {
return checkForOne.indexOf("1") >= 0;
};
var containsZero = function(checkForZero) {
return checkForZero.indexOf("0") >= 0;
};
var addClassForOnes = function(element) {
var text = element.textContent;
if (containsOne(text)) {
$(element).addClass('has-one');
}
};
var addClassForZeros = function(element) {
var text = element.textContent;
if (containsZero(text)) {
$(element).addClass('has-zero');
}
};
var onDataBound = function() {
var $gridCells = $('[role="gridcell"]');
$gridCells.each(function(index, element) {
console.log(element);
addClassForOnes(element);
addClassForZeros(element);
});
};
Finally color the cells with the following css
.has-one {
background-color: green;
}
.has-zero {
background-color: red;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments