Please provide any example for conditional column template which highlights the iggrid's cell with background color.
http://jsfiddle.net/zLRRN/1/
$(function () { var columnSettings = [ { headerText: "Product Name", key: "ProductName" , template: "{{if ${ProductName} == 'Chai' }}one{{else}}two{{/if}}" } ]; $('#resultGrid').igGrid({ dataSource: northwindProducts, responseDataKey: "results", dataSourceType: "json", width: "100%", autoGenerateColumns: true, columns: columnSettings, features: [ { name: "Paging", type: "local", pageSize: 8 } ] }); });
Hello Renganathan,
Thank you for posting in our forum.
In the way that you are trying to set some style, directly in the columnSettings Template, you can set only for example the text color, not the cell background color too. You can set text color when wrap the cell content in a div element with specified style. If you set a background color to the div you will set the background color only for the div element, not for the entire cell. Here is the code that I use to set some text color within a cell:
If you want to set a cell background, based on a cell value, this is a different story. My suggestion is to handle igGrid pagerRendered event and in there to manage your requirements. For example in the code below you will see how I loop through all visible grid rows, get the cell value for the specific column and based on the cell value, apply some cell style.
Here you can find online sample implementing my suggestions, and also I am attaching you an html sample too.
http://jsfiddle.net/zLRRN/4/
Please have a look and if you have any further questions regarding this, do not hesitate to contact me.
Hi,
I am using .cshtml file so we need C#/Jquery vesrion for this HTML code
I am having an issue getting this to work. When I attempt to execute grid.getCellValue() I get error : "The record with the specified id could not be found in the data view: 0"
in the ui.grid.framework.js
//CODE
$.ajax({
type: 'POST',
url: '../../../webservices/FeeScheduleWebService.asmx/GetAllNonRPSFeeSchedules',
dataType: 'json',
global: false,
contentType: 'application/json; charset=UTF-8',
success: function (result) {
$("#grid").igGrid({
rendered: function (evt, ui) {
$('#loading').igLoading("hide");
indicatorLoading.hide();
$('.t-area').find('h1').text($('#grid').igGrid('option', 'dataSource').length + ' Fee Schedule(s)');
$('#grid').show();
},
dataSourceType: "json",
primaryKey: "FeeScheduleId",
responseContentType: "application/json; charset=utf-8",
width: "100%",
dataSource: result.d,
autoGenerateColumns: true,
features: [
{
name: "Paging",
type: "local",
pageSize: 8,
pagerRendered: function (evt, ui) {
var grid = ui.owner.grid;
for (var i = 0; i < grid.rows().length; i++) {
var value = grid.getCellValue(i, "ScheduleTypeName");
var columnIndex = $("#" + grid.id() + "_" + "IsDefault").data("columnIndex");
if (value === 'Business Acquisition and Consulting Services Fees' || value === 'Additional Fees') {
$(grid.cellAt(columnIndex, i)).css('background-color', 'yellow');
}
]
});