This question is locked. New answers and comments are not allowed.
Hi, I am having a problem getting CellAction to work for me, most likely due to some confusion on my part.
I have the following grid defined
I have also defined the following CellAction
So far this works by setting the background colour of the cell titled 'Access'. However, the background colour does not stay set when I page the grid, the setting is lost. That is my first problem.
As well as setting the background colour I also need to change the Html.ActionLink but I cannot work out what I need to set within the CellAction and also get this to persist over pageing of the grid.
I need to change this
to something like this
But I am just getting myself into a tyerrible mess.
Can anyone help point me in the correct direction?
I have the following grid defined
<%= Html.Telerik().Grid(Model.BinaryDataList)
.Name(
"BinaryData"
)
.Columns(columns =>
{
columns.Bound(o => o.BinaryDataId).Format(Html.ActionLink(
"View"
,
"View"
,
"Home"
,
new
{
id =
"{0}"
},
new
{@
class
=
"t-link action-edit"
}).
ToString()).Title(
"Access"
).Encoded(
false
).Width(50)
.Sortable(
false
)
.Filterable(
false
)
.HtmlAttributes(
new
{@style =
"text-align:center"
});
columns.Bound(o => o.BinaryDataDate).Format(
"{0:dd MMM yyyy}"
).Title(
"Date"
).Width(100).Filterable(
true
);
columns.Bound(o => o.BinaryDataKey).Title(
"Key"
).Width(50).Filterable(
true
);
columns.Bound(o => o.BinaryDataVersion).Title(
"Version"
).Width(50).Filterable(
false
);
columns.Bound(o => o.BinaryDataFilename).Title(
"Filename"
).Width(250);
columns.Bound(o => o.BinaryDataDescription).Title(
"Description"
).Filterable(
false
);
columns.Bound(o => o.BinaryDataFileType).Title(
"File Type"
).Width(75);
columns.Bound(o => o.BinaryDataFolderName).Title(
"Folder"
).Width(75);
columns.Bound(o => o.BinaryDataContentType).Title(
"Content Type"
).Width(200);
})
.DataBinding(dataBinding => dataBinding.Ajax().Select(
"AjaxBinaryData"
,
"Home"
,
new
{ treatmentId = Model.BinaryData.BinaryDataTreatmentId }))
.Pageable(paging => paging.PageSize(10))
.Sortable()
.Filterable()
%>
I have also defined the following CellAction
.CellAction(cell =>
{
if
(cell.Column.Title !=
"Access"
)
return
;
if
(cell.DataItem.BinaryDataFileType.Trim() ==
".swf"
)
{
cell.HtmlAttributes[
"style"
] =
"background:red;"
;
}
})
So far this works by setting the background colour of the cell titled 'Access'. However, the background colour does not stay set when I page the grid, the setting is lost. That is my first problem.
As well as setting the background colour I also need to change the Html.ActionLink but I cannot work out what I need to set within the CellAction and also get this to persist over pageing of the grid.
I need to change this
columns.Bound(o => o.BinaryDataId).Format(Html.ActionLink(
"View"
,
"View"
,
"Home"
,
new
{
id =
"{0}"
},
new
{@
class
=
"t-link action-edit"
}).
ToString()).Title(
"Access"
).Encoded(
false
).Width(50)
.Sortable(
false
)
.Filterable(
false
)
.HtmlAttributes(
new
{@style =
"text-align:center"
});
to something like this
.CellAction(cell =>
{
if
(cell.Column.Title !=
"Access"
)
return
;
if
(cell.DataItem.BinaryDataFileType.Trim() ==
".swf"
)
{
cell.HtmlAttributes[
"style"
] =
"background:red;"
;
cell.Text =
string
.Format(Html.ActionLink(
"Play"
,
"Play"
,
"Home"
,
new
{
id =
"{0}"
},
new
{@
class
=
"t-link action-edit"
}).
ToString());
}
})
But I am just getting myself into a tyerrible mess.
Can anyone help point me in the correct direction?