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

How to make tab title text update dynamically through data binding?

6 Answers 481 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Michelle
Top achievements
Rank 1
Michelle asked on 27 Feb 2016, 08:48 AM

Hi,

I have a simple tabstrip defined in AngularJS.  I have a button that when clicked, will change the name of the first item in the datasource.  I expect the tabstrip tab title to change as well after the click, but as you can see in the following example, the datasource is changed, but the tab stays the same:

http://dojo.telerik.com/AYofE

I know that you can call tabstrip.dataSource.read() to update the title, but in my case doing that will overwrite some tabs I manually appended to the tabstrip directly because they are not in the dataSource.  Is there a way to get data binding working for the tab title?

Thanks,

Michelle

6 Answers, 1 is accepted

Sort by
0
Michelle
Top achievements
Rank 1
answered on 28 Feb 2016, 06:21 PM

Another way I tried was to use AngularJS binding syntax in the text field value, like so:

http://dojo.telerik.com/AYofE/2

Please note that the first tab object has a name value of {{options}} and instead of showing the value of options, it shows the text as plain text.  How can I make the tab title compile Angular markup?

Thanks,

Michelle

0
Michelle
Top achievements
Rank 1
answered on 29 Feb 2016, 07:20 PM

I actually went ahead and debugged the Kendo source code and found that currently, when tabs are created through the dataTextField, the "encoded" option for the tab is not set to false.  Therefore, all data referenced by dataTextField will be encoded by Kendo and I suspect that is why when dataTextField returns HTML, it just displays the HTML as plain text.  Whereas, if I manually call tabstrip.append(tab) with tab.encoded = false, the HTML is rendered properly.  The other issue is that while dataContentField gets run through the angular compile service, the dataTextField does not, which might be the second part of the reason why my Angular syntax isn't being compiled.  Please provide a workaround or fix this issue.  It is a huge blocking factor to my current project.

Thanks,

Michelle

0
Michelle
Top achievements
Rank 1
answered on 01 Mar 2016, 03:16 AM

I continued to debug the kendo source code as I haven't heard from the Kendo staff at all.  I tried to trigger a change event on the dataTextField, which actually solved my problem and successfully updated the tab title.  However, the content field does not behave the same way and I have narrowed it down to this bit of code in the TabStrip.refresh function:

} else if (e.action == 'itemchange') {
                    idx = that.dataSource.view().indexOf(view[0]);
                    if (e.field === options.dataTextField) {
                        that.tabGroup.children().eq(idx).find('.k-link').text(view[0].get(e.field));
                    }
                }

It seems to only update if the field with the itemChanged event is the dataTextField.  It completely ignores the dataContentField.  Is this a bug?  How can I workaround it?

 

Thanks,

Michelle

0
Boyan Dimitrov
Telerik team
answered on 01 Mar 2016, 04:30 PM

Hello Michelle,

 

Indeed the content element should be changed explicitly just like the tab text. You can use the Kendo UI TabStrip contentElement method to get the  ContentElement and change its content.  

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Michelle
Top achievements
Rank 1
answered on 01 Mar 2016, 10:01 PM

Hi Boyan,

Your suggestion defeats the purpose of using a dataSource.  Also, I am currently relying on the tabstrip refresh/append logic to compile angular content provided in my dataContentField.  The contentElement method gets me back the actual DOM element and to change its content manually, I would also have to manually compile the Angular code before appending it to the contentElement.  That is not an acceptable solution.  I have found my own workaround for updating the content in my specific case, but I would like to point out that the tabstrip appears to be missing a lot of supporting features to make the dataSource work properly with Angular.

 

Thanks,

Michelle

0
Petyo
Telerik team
answered on 03 Mar 2016, 01:16 PM
Hello Michelle,

thank you for your feedback. We will keep that in mind in our current development effort regarding Angular. 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TabStrip
Asked by
Michelle
Top achievements
Rank 1
Answers by
Michelle
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Petyo
Telerik team
Share this question
or