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

HtmlAttributes append attributes

0 Answers 101 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.
Chris Neave
Top achievements
Rank 1
Chris Neave asked on 22 May 2012, 03:46 PM

Is there a way to add extra html attributes via the GridBuilder without removing any attributes already added?

I have some common custom attributes I add to grids so I wrapped up the code into some extension methods like this:

public static GridBuilder<T> CustomFilterBehaviour<T>(this GridBuilder<T> gridBuilder, string message = null) where T : class
{
    return gridBuilder.HtmlAttributes(new {my_customFilter = (message ?? "")});
}

public static GridBuilder<T> CustomRowCountBehaviour<T>(this GridBuilder<T> gridBuilder, string message = null) where T : class
{
    return gridBuilder.HtmlAttributes(new {my_customRowCount = (message ?? "")});
}

my JS routines then pick up on grid elements with these decorators to implement the behaviour.  The trouble is the HtmlAttributes call overwrites any attributes already set, so if I declare a grid like this:

@(Html.Telerik().Grid<Typology>()
    .Name("gridTypologies")
                              
    // custom behaviours
    .CustomFilterBehaviour()
    .CustomRowCountBehaviour()

The call to .CustomRowCountBehaviour() overwrites the attribute set by the call to .CustomFilterBehaviour(), so the "my_customFilter" decorator is lost and not output!! What I really want to do inside the extension methods is add an extra Html attribute to anything that is already present.

Any suggestions? Thanks
Tags
Grid
Asked by
Chris Neave
Top achievements
Rank 1
Share this question
or