質問

I have the following issue when using KendoUI Grid with a column template:

My data for a row looks like this (simplified):

{ Name: 'name', Statuses: [ {Name: 'StatusA', Value: 'ValueA'} , {Name:'StatusB', Value: 'ValueB'}] }

So on each row data I have a list of name-value collection for statuses. I have a number of columns (one for each status) named with the status name: StatusA, StatusB, etc.

In the column template I want to put the value of the status depending on the column name. I can access data.Statuses in the template and get the status values, but the template is not aware for which column is being rendered.

Is there any way to access the column name in the template or send it as a parameter?

Any help is appreciated!

役に立ちましたか?

解決

You can include a javascript function in the template like this:

{title:"StatusA", field:"Status1", template: "#= formatStatus(data.Statuses[0]) #" },
{title:"StatusB", field:"Status2", template: "#= formatStatus(data.Statuses[1]) #"}

Here is the article that helped me discover this:

http://www.kendoui.com/forums/ui/grid/grid-cell-template-for-image-with-javascript-selector.aspx

他のヒント

Unfortunately, you can't. I've been looking for this off and on for weeks. I finally got smart and did a console.log( this ) in JS within the template execution and can see the template function signature. The only parameter is "data", which contains your entire data model for the row.

Telerik's suggestion is to create a row template. This means that if you allow hiding or reordering of columns, it becomes your responsibility to handle them in the row template, whereas a column template doesn't have to be concerned with such. You also have to provide an alternate row template (which may differ only by the class/style) if you want alternate row styling; again something that column templates need not worry about.

IMHO, this is an oversight on Telerik's part.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top