Datasource read with parameters

4 posts, 0 answers
  1. Bryan
    Bryan avatar
    28 posts
    Member since:
    Oct 2014

    Posted 20 Feb 2015 Link to this post

    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.
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 24 Feb 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Bryan
    Bryan avatar
    28 posts
    Member since:
    Oct 2014

    Posted 24 Feb 2015 in reply to Alexander Valchev Link to this post

    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([]);
        }
      }
        }),

  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 26 Feb 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready