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

Adding custom data attrubutes

3 Answers 2339 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 02 Aug 2017, 05:43 PM

Is there a way to add a custom data attribute to a field and give it the value of another field?

Something like this:

$("#treelist").kendoTreeList({
               
                columns: [
                    {
                        field: "Index",
                        attributes: {
                            "data-WorkpaperGuid": data.WorkpaperGuid
                        }
                    },
                    { field: "Name" }
                ],
                dataSource: dataSource
            });

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 04 Aug 2017, 10:41 AM
Hello Steven,

The desired result can be achieved using the columns.template property. This will allow setting a custom element in the cell and modifying its attributes and their values:

http://docs.telerik.com/kendo-ui/api/javascript/ui/treelist#configuration-columns.template

http://dojo.telerik.com/UgIni

The result is:



I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Steven
Top achievements
Rank 1
answered on 04 Aug 2017, 01:08 PM
This does not solve my problem. I don't want to add additional elements. The templates only seem to modify what is within the tag. I want to add an attribute to the Index tag and give it a value that is not fixed but the value of another property field.
0
Stefan
Telerik team
answered on 08 Aug 2017, 07:08 AM
Hello Steven,

Currently, the Kendo UI TreeList supports add dynamic values using the template property.

Custom attributes can be added to the cells directly, but this will allow setting only static values as that property does not have access to the row data as the template does:

http://docs.telerik.com/kendo-ui/api/javascript/ui/treelist#configuration-columns.attributes

Still, I can suggest another custom approach to add a custom class, and then on the dataBound event to select all elements using jQuery and to append the desired custom attribute to them:

http://docs.telerik.com/kendo-ui/api/javascript/ui/treelist#events-dataBound

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-view

Please refer to the runnable example demonstrating this:

http://dojo.telerik.com/eLOte

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeList
Asked by
Steven
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Steven
Top achievements
Rank 1
Share this question
or