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

Parameters to dataSource

1 Answer 357 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Huw
Top achievements
Rank 1
Huw asked on 25 Apr 2012, 03:46 PM
I'm evaluating this product for my organization and to be honest I'm very new to this stuff. I've been playing around with stuff for a couple of days but I appear to have become stuck on something pretty trivial.

I'm calling an ASP.NET web service using VS 2010. I'm calling it from the dataSource, and then binding the dataSource to the chart. It works fine when I don't try to pass parameters, I get the results into the chart and everything seems right. The Kendo definition of the datasource is

                    var dsprov = new kendo.data.DataSource({
                        schema: {
                            data: "d"
                        },
                        transport: {
                            read: {
                                url: "IndustryTrends.aspx/ChartData",
                                contentType: "application/json; charset=utf-8", // tells the web service to serialize JSON
                                type: "POST"
                            }
                        }
                    });


And the definition of the web service is

<WebMethod()>
    Public Shared Function ChartData() As IEnumerable(Of BolIndustryChartDataItem)
        Dim c As New List(Of BolIndustryChartDataItem)
        c.Add(New BolIndustryChartDataItem("My name", 3,4,5))
        Return c
    End Function



...this all works fine.

But now I want to add a parameter to the read function in order to be able to read the correct data. I assumed that all I had to do was change the dataSource definition to:

   var dsprov = new kendo.data.DataSource({
                        schema: {
                            data: "d"
                        },
                        transport: {
                            read: {
                                url: "IndustryTrends.aspx/ChartData",
                                contentType: "application/json; charset=utf-8", // tells the web service to serialize JSON
                                type: "POST",
data: { 
name: function() {
return "michael";
} }


                            }
                        }
                    });

....and then change the web service to 

<WebMethod()>
    Public Shared Function ChartData(byval name as string) As IEnumerable(Of BolIndustryChartDataItem)
        Dim c As New List(Of BolIndustryChartDataItem)
        c.Add(New BolIndustryChartDataItem("My name", 3,4,5))
        Return c
    End Function


....but this causes the web service to never get called. I know I missing something trivial here but I'e spend some time looking at it, tried a bunch of different things, and I can't figure out what.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Vivek
Top achievements
Rank 1
answered on 27 Apr 2012, 09:07 AM
The code to add parameters is something like this

var_remoteDataSource = new kendo.data.DataSource(
    {
        transport: {
            read: {
                type: "POST",
                url: 'yourURL.php'
            },
            parameterMap: function(data, operation){
                 return {
                         param1: "Parameter1",
                         param2: "Parameter2",
                         param3: "Parameter3",
                 }
            },
            dataType: "jsonp"
        },
        pageSize: 10,
        error: function(e){
            alert(e.responseText);
        }
    }
);


Hope this helps!
Tags
Data Source
Asked by
Huw
Top achievements
Rank 1
Answers by
Vivek
Top achievements
Rank 1
Share this question
or