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

How can I set the select url client side?

3 Answers 60 Views
ClientDataSource
This is a migrated thread and some comments may be shown as answers.
moegal
Top achievements
Rank 1
moegal asked on 05 Jul 2015, 06:37 PM

I am doing the following at the moment and it seems to work, not sure there is not a method I could use.

 
var dataSource;
        function RequestStart(sender, args) {
            dataSource = $find('<%= RadClientDataSource1.ClientID %>');
            dataSource._transport.read.url = dataSource._transport.baseUrl + "GetListProducts/3";
        };

 Thanks, Marty

 

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 08 Jul 2015, 01:54 PM
Hello,

Yes, this approach seems okay. You could use get_transport() which will also return _transport property of the ClientDataSource.
The client-side API does not expose separate methods for configuration of the URL because this is generally expected to be a static setting when you are making a request to a web service.  And additional options can be passed as parameters to the web service call in the HTTP request.
If you are using Web API to retrieve data the approach for dynamic changes of the request URL in the ClientDataSource is indeed more appropriate in this case.

Regards,
Marin
Telerik
0
moegal
Top achievements
Rank 1
answered on 09 Jul 2015, 07:45 PM

Marin,

 Thanks.  So how do I pass additional parameters to the web service in the HTTP request?

 Marty

0
Marin
Telerik team
answered on 13 Jul 2015, 10:32 AM
Hello,

Sample code of this approach is shown in this online demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-data-source-binding/defaultcs.aspx
You can handle the OnCustomParameter event of the ClientDataSource and pass the parameters there:
function ParameterMap(sender, args) {
             
            if (args.get_type() == "read / create / update... etc" && args.get_data()) {
                args.set_parameterFormat({ parameterName: parameterValue });
            }
        }

This way the ClientDataSource will make a request and send the parameters you specified in the event. Of course on the server side the service method should also expect such parameter.
public void ServiceMethod(string parameterName)
    {
        //....
    }


I hope this helps. Let me know if you have any other questions.

Regards,
Marin
Telerik
Tags
ClientDataSource
Asked by
moegal
Top achievements
Rank 1
Answers by
Marin
Telerik team
moegal
Top achievements
Rank 1
Share this question
or