I have defined following jQuery datagrid column. Users is assoc array of text and value fields.
Without template field, column is correctly displaying users's fullname from values field.
Now I need to change only displayed fullname into the link and therefore, I added template field. Problem is, that I don't know and I didn't find it in documentation, how to parse "modified_by" value into the user fullname (with using of text-value array in values field).
(new Kendo\UI\GridColumn())
->field('modified_by')
->title($t->translate('card.grid.modified_by'))
->values($users)
->filterable($filterableMulti)
->width(200)
->template('#= (modified_by == null) ? \'\' : \'<a href="' . $this->baseURL . 'profile/\'+modified_by+\'">\'+modified_by+\'</a>\' #')
->lockable(true)
Thank a lot for any help!
Hi,
From the provided information I am not sure I understand the desired result correctly. Are you trying to use additonal fields from the dataSource in the columns.template? If this is the case you could use the data object and access the other fields of the dataItem. Below is an example:
template: ({ ProductName, Category, QuantityPerUnit }) => `<i>ProductName: ${ProductName}</i><strong>; Category: ${(Category.CategoryName)}</strong>; <u>QuantityPerUnit: ${QuantityPerUnit} </u>`
Or of you are using the old syntax (non CSP templates):
template: '<i>ProductName: #=data.ProductName#</i><strong>; Category: #=data.Category.CategoryName #</strong>; <u>QuantityPerUnit: #=data.QuantityPerUnit# </u>'
Both approaches are demonstrated in the Dojo linked here - https://dojo.telerik.com/@NeliK/esOSoPoH.
In case this is not the issue and I misunderstaood the scenario, please provide more details about the expected result, so I could get a better idea of the case and advise you further.
Regards,
Neli
Hi @Neli, thanks a lot for your comment.
No, I made some changes in your example to better understand my use-case. Check the modified Dojo please: https://dojo.telerik.com/OrEKOQaK/2
I added new supplier column on line 61
Then I need to make the same, but wrapped by <a>...but here I have available only SupplierID field (not supplier name). Supplier name I must somehow get from values field (set before in the column field 'values', where is array of suppliers)</a>
Thanks a lot,
N.
Hi Nodsec,
As in the described scenario the suppliers array is not part of the dataSource, the only possible way to display data from it is to access it in the template function.
Im not able to make suppliers.find(...) { field: "SupplierID", title:"Supplier test column", width: "230px", values: suppliers, template: function(data){ var name = suppliers.find(x => x.value == data.SupplierID) return name == undefined ? '' : name.text } },
You can take a look at the following forum tread regarding how funcitons can be set in Kendo PHP Grid templates:
- https://www.telerik.com/forums/php-function-in-column-template
I hope this helps.
Regards,
Neli