Could you give me an example of how to use the HtmlAttributes, FooterHtmlAttributes member of GridColumnSettings to set the grid columns in the controller?
I'm trying to set by use the following code, then it shows me that HtmlAttributes and FooterHtmlAttributes are read only field.
var columns = new[]
{
new GridColumnSettings
{
Member = "ProductName",
Title="title",
HtmlAttributes="",
Hidden=true,
ClientTemplate="dd",
FooterHtmlAttributes="sdff"
}
};
Well, basically, what I want to do is the save grid column preference, such as columns width, columns order, sorting preferences, etc.
Could you provide me an example? Really appreciated your help. Thank you.
regards
Jerry
15 Answers, 1 is accepted
Both settings are IDictionary<string, object> thus you can set their values like this:
new
GridColumnSettings
{
Member =
"ProductName"
,
Width =
"200px"
,
HtmlAttributes = { {
"title"
,
"tooltip"
} , {
"style"
,
"background:red"
}}
}
Atanas Korchev
the Telerik team
Thank you for the response.Well, basically, what I want to do is the save grid column preference, such as columns width, columns order, sorting preferences, etc.
Could you provide me an example? Really appreciated your help. Thank you.
How to set "FooterTemplate" in GridColumnSettings, I cannot see this attribute.
If it is not available, is anyway to set it somewhere??? Thank you
No, FooterTemplate is not currently exposed in the GridColumnSettings. We currently don't have an example for saving the column settings as this is not something supported out of the box. However it should not be hard to either persist them in a database or serialize them as XML and save them in some file. Have in mind though that some things (such as templates which are actually executable code) cannot be persisted.
Regards,Atanas Korchev
the Telerik team
Just encountered another problem.
Could you tell me how to set ButtonType in GridCommandColumnSettings???
I am trying to set delete command's button type to image. Could you provide me an example for that?
following are part of my code.
var columnSettings = new[]
{
new GridCommandColumnSettings
{
Commands = {(new GridDeleteActionCommand())},
Width="30px",
HtmlAttributes = {{"class", "delete-command-button"}}
//TODO: GirdButtonType --->image
}
}
Thank you, really appreciated your help.
If I load column settings like the following, how do I set FooterTemplate for a specified column?
Also, if I have a predefined column sorting preference. How can I set it if a column setting is in use?
Thank you
Html.Telerik().Grid((IEnumerable<
OneTimesheet.Models.UserTimecodeModel
>)ViewData.Model)
.Name("admingrid").HtmlAttributes(new { @class = "admingrid", style = "font-size:12px;font-family:Calibri;" })
.Columns(columns => columns.LoadSettings((IEnumerable<
GridColumnSettings
>)ViewData["adminGridColumns"]))
.DataBinding(databinding => { databinding.Ajax().Select("_selectAdmin", "Home", new { source = "ADMIN" }); })
.ClientEvents(events => events.OnRowSelect("onFavRowSelect"))
.Selectable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Scrollable(scrolling=>scrolling.Enabled(true).Height(415))
.Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn)
.OrderBy(sortOrder =>
{
sortOrder.Add(o => o.AltRef2).Ascending();
sortOrder.Add(o => o.Description).Ascending();
}))
.Render();
The FooterTemplate is not currently exposed from the column settings and as a result you can't currently use it. I will add it so you can use it in our next internal build.
ButtonType is a property of GridDeleteActionCommand thus you can set it like this:
new GridDeleteActionCommand
{
ButtonType = GridButtonType.Image
}
You can not specify a column as sorted which means that you cannot use the ColumnSetting for this purpose. Sorting is specified via the Sortable() configuration only and accepts a C# expression for configuring it.
Atanas Korchev
the Telerik team
Could you let me know once the FooterTemplate is available in the internal build?
About sorting preference, I managed to get the sorting string via grid.orderBy. I was wondering when I pass the sorting string back, how can I apply that to the grid data? Another request?
regards
Jerry
The internal build is ready and you should be able to use that.
I am afraid that implementing the second request is not currently possible. As I said before you cannot pass a string to the order by setting of the grid as it requires a c# expression. If you however just perform a redirect and add the orderby value in the URL the grid would read it from there an apply the sorting.
Atanas Korchev
the Telerik team
I will try the internal build. Thank you
For the sorting, could you show me an example of how to use c# expression for sorting?
regards
Jerry
Our sorting example shows exactly that.
Greetings,Atanas Korchev
the Telerik team
Is there anyway to do that? I'm sorry if I overlooked the example.
regards
Jerry
Perhaps you didn't see the description which shows this code:
<%= Html.Telerik().Grid(Model)Regards,
.Name("Grid")
.Sortable(sorting => sorting
.OrderBy(sortOrder => sortOrder.Add(o => o.OrderID).Descending())
)
%>
Atanas Korchev
the Telerik team
really appreciated your time and help...
How to set "FooterTemplate" in GridColumnSettings, I can see this attribute as read only from controller.
Please let me know whether this support on any version of telerik controls for mvc grid.
How can i set footer template when binding columns runtime using GridColumnSetting.
I want to add this column from my view.
columns.Bound(c => c.CHARGE_TOTAL).Title("Charge Total")
.FooterTemplate(
@<text>
Total:@string.Format("{0:c}", ViewBag.TotalChargeTotal)
</text>
)
.Width(100);
to controller
new GridColumnSettings
{
Member = "CHARGE_TOTAL",
Width = "100px",
Format = "{0:c}",
FooterTemplate = ?
FooterHtmlAttributes = ?
}
Please help it's urgent.
Many thanks in advance,
Deepika.