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

Pass additional data to Read method of datasource

4 Answers 1634 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cool Breeze
Top achievements
Rank 1
Cool Breeze asked on 06 Apr 2014, 08:08 PM
I have a form to edit a catalog item. The initial list of catalog items is a Kendo grid and the editor is a popup using a custom template for a catalog item. When the popup is opened, I want to have a grid within this window which will have a list of all of the images attached to this item. I want to set this grid up in such a way that if new images are uploaded from within this window it can be refreshed by going back to the controller and re-querying to get the updated list. My issue is that I am unable to pass the ID of the item that I am currently editing into the controller method. I have tried the following:
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("GetItemImages", "CatalogItemMaintenance", new { itemId = Model.ItemId})))

But Model.ItemId is always null (along with every other property on the model). I believe this is because the template is being accessed from a grid which isn't explicitly passing the model in to the editor template, so I'm unable to use "Model.property" to get access to the values. So, how do I pass the ID of the object I am working with in the editor template to a method in a the controller in order to pull additional data?

Thanks!


4 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 08 Apr 2014, 03:07 PM
Hi Cool Breeze,

You are correct, the Model is used only for its metadata, thus all properties are null and cannot be used for passing additional data. You could however, specify a JavaScript function (through the Data method), which will attach the additional data to the request. For example: 
.Read(read => read.Action("GetItemImages", "CatalogItemMaintenance").Data("onRead"))
...
 
function onRead(o) {
    return {
        itemId: $("#itemID").val(); //get the ID from a HTML element or a variable
    };
}


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeff
Top achievements
Rank 1
answered on 02 Oct 2014, 06:20 PM
Hi - I'm looking to do the same thing with the JSP wrappers, but I can't find the syntax for the "data" hook.  I tried the following, but my getCriteria javascript method is never invoked.   Do you know what the syntax is for JSP UI?   Thanks! 

<kendo:dataSource-transport-read url="${readUrl}" data="getCriteria" type="POST"
    contentType="application/json" />
0
Alexander Popov
Telerik team
answered on 06 Oct 2014, 07:41 AM
Hi Jeff,

In JSP this is done through the dataSource-transport-read-data tag, as explained in the API reference.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeff
Top achievements
Rank 1
answered on 08 Oct 2014, 08:48 PM
Thanks Alexander!
Tags
Grid
Asked by
Cool Breeze
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or