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

TableHtmlAttributes Overwriting

3 Answers 431 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Calvin
Top achievements
Rank 1
Calvin asked on 19 Nov 2014, 08:14 PM
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.

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 21 Nov 2014, 12:44 PM
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.

 
0
Calvin
Top achievements
Rank 1
answered on 21 Nov 2014, 02:43 PM
@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?
0
Dimo
Telerik team
answered on 25 Nov 2014, 09:23 AM
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.

 
Tags
Grid
Asked by
Calvin
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Calvin
Top achievements
Rank 1
Share this question
or