I have acheived this by modifying the source code in the GridRenderer and GridColumn classes. The change in GridColumn is to add the following function:
public object GetRawValue(T instance)
{
if (!_cellCondition(instance))
{
return null;
}
var value = _columnValueFunc(instance);
return value;
}
Then the change in GridRenderer is in the RenderItem function to be changed as follows:
protected virtual void RenderItem(GridRowViewData<T> rowData)
{
BaseRenderRowStart(rowData);
HtmlHelper<T> html = new HtmlHelper<T>(Context, new ViewPage());
foreach (var column in VisibleColumns())
{
//A custom item section has been specified - render it and continue to the next iteration.
if (column.CustomItemRenderer != null)
{
column.CustomItemRenderer(new RenderingContext(Writer, Context, _engines), rowData.Item);
continue;
}
RenderStartCell(column, rowData);
var cellValue = column.GetRawValue(rowData.Item);
if (cellValue != null)
{
//RenderText(cellValue.ToString());
MvcHtmlString value = html.DisplayFor<T, object>(m => cellValue);
string str = (value.ToString() == string.Empty) ? cellValue.ToString() : value.ToString();
if (column.HtmlEncode == true)
{
str = (value.ToString() == string.Empty) ? HttpUtility.HtmlEncode(cellValue.ToString()) : value.ToHtmlString();
}
RenderText(str);
}
RenderEndCell();
}
BaseRenderRowEnd(rowData);
}
Once you do this the grid will use the templates found. I have only tested with DisplayTemplates as this is all I need but it should also work for EditorTemplates with a slight change.