This is a migrated thread and some comments may be shown as answers.

GridColumnSettings and HtmlAttributes

15 Answers 260 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jerry
Top achievements
Rank 1
Jerry asked on 09 May 2011, 03:44 AM
Hi there,


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

Sort by
0
Atanas Korchev
Telerik team
answered on 09 May 2011, 07:48 AM
Hi Jerry,

 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" }}
}

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry
Top achievements
Rank 1
answered on 09 May 2011, 10:06 PM
Hi Atanas,


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.
0
Jerry
Top achievements
Rank 1
answered on 10 May 2011, 06:18 AM
One more question

How to set "FooterTemplate" in GridColumnSettings, I cannot see this attribute.

If it is not available, is anyway to set it somewhere??? Thank you
0
Atanas Korchev
Telerik team
answered on 10 May 2011, 06:27 AM
Hi Jerry,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry
Top achievements
Rank 1
answered on 11 May 2011, 02:58 AM
Thank you for your reply Atanas. Really appreciated...


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.
0
Jerry
Top achievements
Rank 1
answered on 11 May 2011, 07:17 AM
Sorry, just had another problem with FooterTemplate.
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();

0
Atanas Korchev
Telerik team
answered on 11 May 2011, 09:29 AM
Hello Jerry,

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.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry
Top achievements
Rank 1
answered on 13 May 2011, 03:21 AM
Thank you Atanas.

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
0
Atanas Korchev
Telerik team
answered on 13 May 2011, 07:23 AM
Hello 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.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry
Top achievements
Rank 1
answered on 13 May 2011, 07:53 AM
Really appreciated your help, Atanas.


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
0
Atanas Korchev
Telerik team
answered on 13 May 2011, 07:54 AM
Hello Jerry,

 Our sorting example shows exactly that.

Greetings,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry
Top achievements
Rank 1
answered on 13 May 2011, 07:58 AM
This example only shows whether or not to sort by this column. I want ot define something like sort the column in ascending or dsending order.

Is there anyway to do that? I'm sorry if I overlooked the example.


regards
Jerry
0
Atanas Korchev
Telerik team
answered on 13 May 2011, 08:06 AM
Hi Jerry,

 Perhaps you didn't see the description which shows this code:

<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Sortable(sorting => sorting
            .OrderBy(sortOrder => sortOrder.Add(o => o.OrderID).Descending())
        )
 %>

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry
Top achievements
Rank 1
answered on 17 May 2011, 04:50 AM
Thank you Atanas!!!

really appreciated your time and help...
0
Deepika
Top achievements
Rank 1
answered on 08 Jun 2013, 12:13 PM
Hi Atanas, 
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.



Tags
Grid
Asked by
Jerry
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jerry
Top achievements
Rank 1
Deepika
Top achievements
Rank 1
Share this question
or