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

Overriding the row generation code?

3 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 25 Mar 2013, 02:12 PM
Is it possible to override the code that generates a row in the kendo grid?
I'd like to add more features to the row model's json, without necessarily putting the field in to the model object.

Currently, I'm using a backbone datasource and model to drive my grid.  I'd ideally like to have a callback per model to add this reference.  Is it possible to do?

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 27 Mar 2013, 08:30 AM
Hi John,

Kendo Grid provides opportunity for the developer to define how the entire row will be generated through rowTemplate/altRowTemplate options (demo). It is possible to use Kendo Template (which can execute JavaScript expressions) or to write your own function.

I hope this solution will fir in your requirements.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
John
Top achievements
Rank 1
answered on 27 Mar 2013, 10:59 AM
Right, I am currently using rowTemplate/altRowTemplate.  However, it looks like Kendo will only pass in the model object for the schema as an argument.  I was hoping there was a way to add additional attributes to the JSON passed in, without necesssarily adding it to my model.
0
Alexander Valchev
Telerik team
answered on 29 Mar 2013, 08:56 AM
Hi John,

This is correct, KendoUI passes only the model as an argument. Since Kendo templates allow JavaScript execution, you are able to access any global variable inside the template. In case you do not want to expose global variables, you may use jQuery.proxy to change the template context (by default it is the window).

rowTemplate: $.proxy(kendo.template($("#tmp").html()), { foo: "bar" })

Now in the template you can reference 'foo' with 'this.foo'

<script id="tmp" type="text/x-kendo-template">
    <tr data-uid="#: uid #">  
        <td>#: this.foo #</td>
        <td>#: name #</td>
        <td>#: age #</td>
    </tr>
</script>

I hope this solution will fit in your scenario.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
John
Top achievements
Rank 1
Share this question
or