Hi Corey,
Thanks for using Syncfusion Products.
Your requirement has been achieved by using URL Adaptor. While using URL Adaptor we need to return the data as JSON and the JSON object must contain field name as “result” with its value as dataSource and one more field name as “count” with its value as dataSource total records count. We suggest you to use Skip and Take method to perform the OnDemand paging feature.
Please find the below code snippet :
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <ej:Button ID="button" runat="server" Type="Button" Text="Button" OnClick="button_Click"></ej:Button> <ej:Grid ID="Grid" runat="server" AllowSorting="True" AllowPaging="True" AllowGrouping="true" AllowResizing="true" AllowMultiSorting="true"> <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True"></EditSettings> <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings> <Columns> <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="True" TextAlign="Right" Width="100" /> <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="100" /> <ej:Column Field="EmployeeID" HeaderText="Employee ID" TextAlign="Right" Width="100" /> <ej:Column Field="Freight" HeaderText="Freight" TextAlign="Right" Width="100" Format="{0:C}" /> <ej:Column Field="OrderDate" HeaderText="Order Date" TextAlign="Right" Width="100" Format="{0:MM/dd/yyyy}" /> <ej:Column Field="ShipCity" HeaderText="Ship City" Width="100" /> </Columns> </ej:Grid> </asp:Content> ----------------------------------------------------------------------------- public static object Data(int skip, int take) { var DataSource = OrderRepository.GetAllRecords(); DataResult ds = new DataResult(); ds.result = DataSource.Skip(skip).Take(take); ds.count = ds.count = DataSource.Count(); return ds; } public class DataResult { public IEnumerable<EditableOrder> result { get; set; } public int count { get; set; } } protected void button_Click(object Sender, ButtonEventArgs e) { this.Grid.DataManager = new DataSource(); this.Grid.DataManager.URL = "Default.aspx/Data"; this.Grid.DataManager.Adaptor = "UrlAdaptor"; this.Grid.DataBind(); } } |
For your convenience we have created a sample and sample can be downloaded from the below link :
Sample Link : http://www.syncfusion.com/downloads/support/forum/118588/Sample433455023.zip
Please get back to us if you have any further assistance,
Regards,
Prasanna Kumar N.S.V
protected void button_Click(object Sender, ButtonEventArgs e)
{
this.Grid.DataManager = new DataSource();
this.Grid.DataManager.URL = "Default.aspx/Data?customvar=" + value;
this.Grid.DataManager.Adaptor = "UrlAdaptor";
this.Grid.DataBind();
}
Then I check for httpcontext.current.request.querystring inside the web method.
protected void button_Click(object Sender, ButtonEventArgs e) { this.FlatGrid.DataManager = new DataSource(); this.FlatGrid.DataManager.URL = "Default.aspx/Data"; this.FlatGrid.DataManager.Adaptor = "WebMethodAdaptor"; this.FlatGrid.FilterSettings.FilterType = Syncfusion.JavaScript.FilterType.Menu; this.FlatGrid.DataBind(); |
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static object Data(Syncfusion.JavaScript.DataManager value) {
IEnumerable Data = OrderRepository.GetAllRecords(); DataResult ds = new DataResult(); Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations(); if (value.Sorted != null && value.Sorted.Count > 0) //Sorting { Data = operation.PerformSorting(Data, value.Sorted); } if (value.Where != null && value.Where.Count > 0) //Filtering { Data = operation.PerformWhereFilter(Data, value.Where, value.Where[0].Operator); } int count = Data.AsQueryable().Count(); if (value.Skip != 0) { Data = operation.PerformSkip(Data, value.Skip); } if (value.Take != 0) { Data = operation.PerformTake(Data, value.Take); } ds.result = Data; if (value.Where == null) ds.count = OrderRepository.GetAllRecords().Count(); else ds.count = count; return ds;
}
public class DataResult { public IEnumerable result { get; set; } public int count { get; set; } }
|