Datasource read with parameters

2 Answers 7064 Views
Data Source
Bryan
Top achievements
Rank 1
Bryan asked on 20 Feb 2015, 02:09 PM
I've got a datasource for a combobox working with a local variable passed in the read function so that whenever the variable gets changed the read is called again and the datasource is updated properly like so:

transport: {
read: function (operation) {
var url = "/api/read/Locations/"
$.getJSON(url, { guid: thisGUID }, function (json) {
operation.success(json);
});
               
I'd like to make this a little more generic, so I can include the control in various scripts and pass the parameter to the read function ala .read({ guid: thisGUID}). Also, I feel like this ought to work the same way as the call above:

read:
    url:  "/api/read/Locations/",
    data: { guid: thisGUID }

But it doesn't seem to. Do I need to declare something in the parametermap to get this to work? I can't seem to pass that local variable to the datasource in the read no matter what I do.
​
Bryan
Top achievements
Rank 1
commented on 24 Feb 2015, 02:21 PM

No, something like that works. For some reason, I couldn't get that syntax correct.
Follow up question. If the datasource is tied to a combobox, how can you pass an initial parameter on the declaration? It reads the dataSource right away, and I'm not sure how to pass a "foo:" variable that way, e.g.:

$("#testCombo").kendoComboBox({
dataTextField: "TextField",
dataValueField: "DataValue",
valuePrimitive: true,
dataSource: new kendo.data.DataSource({
  transport: {
    read: function(operation) {
      alert(operation.data.foo);
      operation.success([]);
    }
  }
    }),

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 24 Feb 2015, 08:22 AM
Hello Bryan,

You may pass parameters directly through the read method. Here is a working example:
Could you please let me know what I am missing?

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alexander Valchev
Telerik team
answered on 26 Feb 2015, 09:25 AM
Hi Bryan,

You may suppress initial dataSource read through the autoBind option:

$("#testCombo").kendoComboBox({
dataTextField: "TextField",
dataValueField: "DataValue",
valuePrimitive: true,
autoBind: false,
dataSource: new kendo.data.DataSource({
  transport: {
    read: function(operation) {
      alert(operation.data.foo);
      operation.success([]);
    }
  }
})
}).data("kendoNumericTextBox").dataSource.read({foo: "bar"});


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