Get row index and custom template char

2 Answers 458 Views
Data Source
Marco
Top achievements
Rank 2
Iron
Iron
Marco asked on 27 Apr 2022, 02:56 PM | edited on 27 Apr 2022, 07:17 PM

Hi all

Two questions:

#1
To determine if the row number of my row in datasource I had to do this:

 

    <script>
        var index = 0;
    </script>

    <script type="text/x-kendo-template" id="item-tmpl">
        #: index+1 #
        <div>
            CurrentRow: #: index #<br>
        </div>
    </script>

Is there a more elegant way?


#2
Can I replace the sharp ( "#" ) character in the templates with a custom one?

Many thanks

2 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 02 May 2022, 06:43 AM

Hello Marco,

Unfortunately, there is no built-in way to find the number of the current iteration inside the template. Having that said, following the approach from your initial post seems an appropriate option.

As per the second question, I am afraid that the Kendo jQuery templating syntax does not expose the means that would allow you to change the hash symbol to a different one.

Regards,
Veselin Tsvetanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Marco
Top achievements
Rank 2
Iron
Iron
answered on 04 Jun 2022, 09:06 PM

For the first question i do this:


    dataSource.change = function() {
        $.each(this.data(), function(index, item) {
            item.set( "index", index+1 );
        });
    }

 

Now, my index is in "index" field.

Veselin Tsvetanov
Telerik team
commented on 08 Jun 2022, 09:50 AM

Hi Marco,

Yes, iterating over the items before passing their array to the template is a viable approach for the case in question. This way you won't need a global variable holding the current index.

Tags
Data Source
Asked by
Marco
Top achievements
Rank 2
Iron
Iron
Answers by
Veselin Tsvetanov
Telerik team
Marco
Top achievements
Rank 2
Iron
Iron
Share this question
or