TableHtmlAttributes Overwriting

4 posts, 0 answers
  1. Calvin
    Calvin avatar
    2 posts
    Member since:
    Oct 2014

    Posted 19 Nov 2014 Link to this post

    The implementation of GridBuilder<T>.TableHtmlAttributes() suggests that you should be able to call it multiple times and have the results merged:

    public GridBuilder<T> TableHtmlAttributes(IDictionary<string, object> attributes)
    {
      this.Component.TableHtmlAttributes.Clear();
      Kendo.Mvc.Extensions.DictionaryExtensions.Merge(this.Component.TableHtmlAttributes, attributes);
      return this;
    }

    However, when I try to call TableHtmlAttributes more than once on the same grid, the attributes added by the first call are removed by the second, even though the names do not conflict:

    .TableHtmlAttributes(new KeyValuePair<string, object>("k-grid-tab-new-row", null).ToDictionary())
    .TableHtmlAttributes(new KeyValuePair<string, object>("class", "custom-table-hover table table-bordered no-footer k-grid-single-line ").ToDictionary())

    How can I prevent this behavior? 

    We have several attribute-based custom functions that we have built on top of Kendo grids, and I would like to create optional extension methods for the MVC builder to add these in the grid definition, like this:

    public static GridBuilder<T> TabNewRow<T>(this GridBuilder<T> builder)where T : class
    {
        return builder.TableHtmlAttributes(new KeyValuePair<string, object>("k-grid-tab-new-row", null).ToDictionary());
    }

    The above approach is not possible if each call overwrites the previous ones.
  2. Dimo
    Admin
    Dimo avatar
    8472 posts

    Posted 21 Nov 2014 Link to this post

    Hello Calvin,

    Actually, the implementation of TableHtmlAttributes() does not allow incrementational changes - notice that the old attributes are cleared first.

    Moreover, the source code in the first snippet does not correspond to the source code that we ship - may be you have tried editing it yourself.

    Generally, there are no properties (fluent methods) of the Kendo UI widgets that can be set multiple times in the declaration.

    Regards,
    Dimo
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Calvin
    Calvin avatar
    2 posts
    Member since:
    Oct 2014

    Posted 21 Nov 2014 in reply to Dimo Link to this post

    @Dimo - You're right, I can't believe I didn't notice that!  I should have seen that the attributes are cleared.

    The source I pasted came from the disassembly from the dll that we are currently shipping with.

    Is there any way you can recommend to do what I'm trying to do?
  4. Dimo
    Admin
    Dimo avatar
    8472 posts

    Posted 25 Nov 2014 Link to this post

    Hello Calvin,

    What I can recommend is

    - use external CSS styles with appropriate selectors to target Grid rows without the need to set explicit CSS classes for them

     and / or

     - apply CSS classes with Javascript in the Grid's dataBound event, or any other suitable event, depending on your scenario

    and / or

    - set TableHtmlAttributes() once only


    Regards,
    Dimo
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top