This question is locked. New answers and comments are not allowed.
There is currently a bug in the GridheaderCellBuilder (Q1-2011) that overwrites the "t-header" class if you specify a custom CSS class in the HtmlHeaderAttributes in GridColumnBase.
The fix is very straightforward and involves calling Attributes(...) before you add the "t-header" class.
A unit test / fix is below:
Test:
FIX: The current Q1-2011 version first adds the cssclass and then calls Attributes(...)
A similar problem exists when rendering the Data Grid cells via javascript. If you add a css-class to the last cell in the table via HtmlAttributes in GridColumnBase. In this case the "t-last" class is not rendered and is overwritten with the custom css class.
The current implementation adds the class via javascript:
There are several ways of fixing this, I chose to modify the GridColumnSerializer class so that it'd add the "t-last" class to the serialized attributes. It wasn't obvious as to how to update the GridColumnSerializerTests to address this:
Cheers
Parker
The fix is very straightforward and involves calling Attributes(...) before you add the "t-header" class.
A unit test / fix is below:
Test:
public
class
GridHeaderCellBuilderTests
{
[Fact]
public
void
Should_apply_extra_css_classes()
{
const
string
key =
"class"
;
const
string
value =
"bar"
;
var headerAttributes =
new
Dictionary<
string
,
object
> { { key, value } };
var cell =
new
GridHeaderCellBuilder(headerAttributes,
delegate
{ }).CreateCell();
cell.Attribute(
"class"
).ShouldEqual(
"bar t-header"
);
}
}
FIX: The current Q1-2011 version first adds the cssclass and then calls Attributes(...)
public
class
GridHeaderCellBuilder : IGridCellBuilder
{
/*........ code ommitted ......*/
protected
IHtmlNode CreateContainer()
{
// call Attributes(...) first so that the subsequent calls to AddClass and Attribute do not override UIPrimitives.Header / the "scope" properties
var th =
new
HtmlElement(
"th"
).Attributes(htmlAttributes)
.AddClass(UIPrimitives.Header)
.Attribute(
"scope"
,
"col"
);
return
th;
}
}
A similar problem exists when rendering the Data Grid cells via javascript. If you add a css-class to the last cell in the table via HtmlAttributes in GridColumnBase. In this case the "t-last" class is not rendered and is overwritten with the custom css class.
The current implementation adds the class via javascript:
// File: telerik.grid.js
bindData:
function
(data, html, groups) {
/* ........ code omitted ......... */
html.cat(
'<td'
)
.cat(column.attr)
.catIf(
' class="t-last"'
, i == len - 1)
.cat(
'>'
)
.cat(s);
/* ........ code omitted ......... */
}
There are several ways of fixing this, I chose to modify the GridColumnSerializer class so that it'd add the "t-last" class to the serialized attributes. It wasn't obvious as to how to update the GridColumnSerializerTests to address this:
class
GridColumnSerializer : IGridColumnSerializer
{
/* ....... code omitted ....... */
public
virtual
IDictionary<
string
,
object
> Serialize()
{
// e need to add back the "t-last" class to the Last columns so that if the HtmlAttributes includes class, it does not overwrite "t-last"
this
.AddLastClassToHtmlAttributes(column);
/* ....... code omitted ....... */
}
private
void
AddLastClassToHtmlAttributes(IGridColumn gridColumn)
{
if
(gridColumn.IsLast)
{
object
oPreviousClass =
null
;
string
sLastClass =
null
;
if
(gridColumn.HtmlAttributes.TryGetValue(
"class"
,
out
oPreviousClass))
{
sLastClass = String.Format(
"{0} {1}"
, HttpUtility.HtmlAttributeEncode(oPreviousClass !=
null
? oPreviousClass.ToString() : String.Empty), UIPrimitives.Last);
}
else
{
sLastClass = UIPrimitives.Last;
}
gridColumn.HtmlAttributes.Merge(
new
{ @
class
= sLastClass },
true
);
}
}
}
Cheers
Parker