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

Client side Grid binding and passing params to service

7 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bullish
Top achievements
Rank 1
Bullish asked on 18 Jun 2013, 04:35 AM
I am creating a search form, where the result is displayed in the RadGrid. I'm binding the Grid to a wcf Service.

<ClientSettings>

<DataBinding SelectMethod="GetDataAndCount" Location="../Services/RecordService.svc" SortParameterType="Linq"

FilterParameterType="Linq" CountPropertyName="Count">

</DataBinding>

</ClientSettings

 

 

>

I can not send the extra search fields to the service and rebind the grid without having to do a full page post back.

My Service looks like

public ResultData<Record> GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string

 

filterExpression)

I want it to look something along these lines

public ResultData<Record> GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression, RecrodSearchCriteria

 

criteria)

Any help would be greatly appreciated. This will make or break my decision to go with Telerik controls or not.

Thanks
Bullish

 

 

 

 

 

7 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jun 2013, 06:28 AM
Hello,

Can you please try with below link?

RadGrid with WCF Rest Service

Thanks,
Jayesh Goyani
0
Bullish
Top achievements
Rank 1
answered on 18 Jun 2013, 01:38 PM
Thanks Jayesh,

I looked at your solution before I posted my question, but that seems like a work around rather than a inherent solution to the problem.
Doe the grid support passing extra parameters inherently, like the jqgrid does.

The closest I got was using the onDataBinding client side function, and setting the arguments... but I can't seem to rebind the client side grid to the service again without doing a full post back.

Thanks
Bullish
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Jun 2013, 09:34 AM
Hello,

Can you please provide your code to resolved the issue ?

Thanks, Jayesh Goyani
0
Bullish
Top achievements
Rank 1
answered on 20 Jun 2013, 05:17 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="GridTest._default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">
        <script>
            function buttonClick() {
 
                $find('<%=RadGrid1.ClientID %>').get_masterTableView().rebind();
 
        }
 
        function RadGrid1_DataBinding(sender, args) {
            var searchField = document.getElementById('<%=txtName.ClientID%>').value;
 
            var arguments = args.get_methodArguments();
            arguments.criteria = { Name: searchField };
            args.set_methodArguments(arguments);
        }
 
        </script>
    </asp:PlaceHolder>
 
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <div>
            <div>
                <label >Search Name</label><asp:TextBox runat="server" ID="txtName" />
                <br />
                <input type="button" value="Try to submit without submiting page" onclick="buttonClick();" />
                 
                <br />
                <input type="submit" value="submit page" />
            </div>
            <div>
                <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="true" EnableViewState="false" ClientSettings-DataBinding-EnableCaching="true" AllowPaging="true" PageSize="25" PagerStyle-AlwaysVisible="true"
                    AllowFilteringByColumn="true" AutoGenerateColumns="false">
                    <MasterTableView ClientDataKeyNames="Name" IsFilterItemExpanded="false">
                        <PagerStyle Mode="NextPrevAndNumeric" />
                        <Columns>
                            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"
                                DataType="System.String" SortExpression="Name" />
                            <telerik:GridBoundColumn DataField="Address" HeaderText="Address" UniqueName="Address"
                                DataType="System.String" />
                        </Columns>
                    </MasterTableView>
                    <ClientSettings>
                        <ClientEvents OnDataBinding="RadGrid1_DataBinding" />
                        <DataBinding SelectMethod="GetDataAndCount" Location="Test.svc" SortParameterType="Linq"
                            FilterParameterType="Linq" CountPropertyName="Count">
                        </DataBinding>
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
        </div>
    </form>
</body>
</html>


namespace GridTest
{
    [ServiceContract]
    public interface ITest
    {
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        ResultData<SampleData> GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression, SearchCriteria criteria);
    }
 
[DataContract]
    public class SearchCriteria
    {
        [DataMember]
        public string Name { get; set; }
    }
 
    [DataContract]
    public class SampleData
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Address { get; set; }
    }
 
    public class ResultData<T>
    {
        public ResultData()
        {
            Data = new List<T>();
        }
        public int Count { get; set; }
        public List<T> Data { get; set; }
    }
 
    public class Test : ITest
    {
        ResultData<SampleData> _data;
        public Test()
        {
            _data = new ResultData<SampleData>();
            _data.Data.Add(new SampleData { Name = "Sam", Address = "New York, USA" });
            _data.Data.Add(new SampleData { Name = "John", Address = "Virginia, USA" });
            _data.Data.Add(new SampleData { Name = "Jack", Address = "California, USA" });
 
            _data.Count = _data.Data.Count();
        }
 
        public ResultData<SampleData> GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression, SearchCriteria criteria)
        {
            ResultData<SampleData> returnVal = new ResultData<SampleData>();
 
            if (criteria != null && !string.IsNullOrWhiteSpace(criteria.Name))
            {
                returnVal.Data = _data.Data.Where(c => c.Name.ToUpper().Contains(criteria.Name.ToUpper())).ToList();
                returnVal.Count = returnVal.Data.Count();
            }
            else
            {
                returnVal = _data;
            }
 
            return returnVal;
        }
    }
}


<system.serviceModel>
   <bindings>
     <webHttpBinding>
       <binding name="RestServiceBinding" crossDomainScriptAccessEnabled="true" allowCookies="false" useDefaultWebProxy="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" hostNameComparisonMode="StrongWildcard" bypassProxyOnLocal="false" sendTimeout="00:35:00" receiveTimeout="00:35:00" openTimeout="00:35:00" closeTimeout="00:35:00">
         <readerQuotas maxNameTableCharCount="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" />
         <security mode="None" />
       </binding>
     </webHttpBinding>
   </bindings>
   <behaviors>
     <endpointBehaviors>
       <behavior name="RestEndpointBehaviour">
         <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json"
           automaticFormatSelectionEnabled="false" faultExceptionEnabled="true" />
       </behavior>
     </endpointBehaviors>
     <serviceBehaviors>
       <behavior name="CommonServiceBehaviour">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>
       <behavior name="">
         <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
       </behavior>
     </serviceBehaviors>
   </behaviors>
   <services>
     <service name="GridTest.Test" behaviorConfiguration="CommonServiceBehaviour">
       <endpoint behaviorConfiguration="RestEndpointBehaviour" bindingConfiguration="RestServiceBinding" contract="GridTest.ITest" binding="webHttpBinding" address=""></endpoint>
     </service>
   </services>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
     multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
0
Bullish
Top achievements
Rank 1
answered on 20 Jun 2013, 05:21 AM
I was able to also upload the project at  http://www.hyperfileshare.com/d/cb08b5d7
0
Bullish
Top achievements
Rank 1
answered on 20 Jun 2013, 05:26 AM
In the code I have two buttons, one does a post back which on return fills the parameters and then calls the web service to get the filtered data The first button tries to refresh the web service, which it never does.
How can I get the first button to hit the service again to get to the service, and pass the arguments the way I'm passing them in the second button.

Thanks
Bullish.
0
Kostadin
Telerik team
answered on 21 Jun 2013, 05:30 AM
Hi Bullish,

I was not able to download the project from the provided link as the download quota is exceeded. Could you please upload it again? Note that additional parameters could not be added to the service and as a workaround you could use the Jayesh's approach.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Bullish
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Bullish
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or