Using a object data source to page and sort

I am looking at using syncfusion to update an existing project.  Our current application uses all server side paging and sorting with object data sources.  I would like to duplicate this functionality with you product.  Do you have a sample that shows how this would work?
Sample 
        public IList<ClientPO> GetAllClientPO(decimal JobNumber, string Filter, string alphaFilter, int maximumRows, int startRowIndex,
                                              string sortExpression)
public int ClientPOVirtualCount


5 Replies

IR Isuriya Rajan Syncfusion Team April 4, 2018 11:25 AM UTC

Hi Dave Nixon, 

Thanks for contacting Syncfusion support, 

For server side operation you can use UrlAdaptor and it will send appropriate parameters on each actions.  

Please find the below table for the request and response parameter ,which we are used in server side. 
 
Request params 
 
skip 
skip for sending the starting index of data 
take 
Take  for sending  ending index of data 
sortBy 
sortBy for sending for sort order details 
search 
Search for send search key 
where 
Where send the table name 
group 
Group sent the group details 
 
Response 
 
result 
Processed data 
count 
Return data count 


Find the below code example for urlAdaptor 

  @Html.EJS().Grid("Grid").DataSource(dataManger => { dataManger.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).Columns(col => 
{ 
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = true }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
 
).Render() 


Refer server side code example  : 

  public ActionResult UrlDatasource(Data dm) 
        { 
 
            var order = OrdersDetails.GetAllRecords(); 
            var Data = order.ToList(); 
            int count = order.Count(); 
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            { 
                switch (dm.Sorted[0].Name) 
                { 
 
 
                    case "OrderID": 
                        if (dm.Sorted[0].Direction == "ascending") 
                            Data = Data.OrderBy(x => x.OrderID).ToList(); 
                        else 
                            Data = Data.OrderByDescending(x => x.OrderID).ToList(); 
                        break; 
                    case "CustomerID": 
                        if (dm.Sorted[0].Direction == "ascending") 
                            Data = Data.OrderBy(x => x.CustomerID).ToList(); 
                        else 
                            Data = Data.OrderByDescending(x => x.CustomerID).ToList(); 
                        break; 
                    case "ShipCountry": 
                        if (dm.Sorted[0].Direction == "ascending") 
                            Data = Data.OrderBy(x => x.ShipCountry).ToList(); 
                        else 
                            Data = Data.OrderByDescending(x => x.ShipCountry).ToList(); 
                        break; 
                } 
 
            } 
 
           return dm.requiresCounts ? Json(new { result = Data.Skip(dm.skip).Take(dm.take), count = count }) : Json(Data); //skip and take will return the particular count of data 
        } 

Refer below attached sample: 



Regards, 
Isuriya R 



DN Dave Nixon April 5, 2018 09:41 PM UTC

I have tried adding Syncfusion.EJ2.MVC5 to application using NUGET and putting sample code.

    @Html.EJS().Grid("Grid").DataSource(dataManger => { dataManger.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).Columns(col =>
    {
        col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = true }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
        col.Field("CustomerID").HeaderText("Customer Name").Width("150").ValidationRules(new { required = true, minLength = 3 }).Add();
        col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").Add();
    }).Load("begin").AllowPaging().Locale("es-AR").PageSettings(page => page.PageSize(8)).AllowSorting(true).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()

in and I get


HtmlHelper<dynamic>' does not contain a definition for 'EJS' and no extension method 'EJS' accepting a first argument of type 'HtmlHelper<dynamic>
I am sure it is something stupid I am doing but I can't figure it out.



IR Isuriya Rajan Syncfusion Team April 6, 2018 10:10 AM UTC

Hi Dave Nixon, 
 
We suspect that the Syncfusion.EJ2 namespace has not been added in the web.config file. To resolve this issue, please follow the below documentation steps for how to install Nuget package. 
 
 
 
Follow the above steps and render your grid in cshtml file. 
 
Regards, 
Isuriya R 



DN Dave Nixon April 10, 2018 02:15 PM UTC

Thanks I uninstalled and re-installed.


IR Isuriya Rajan Syncfusion Team April 11, 2018 12:15 PM UTC

Hi Dave Nixon, 
 
Thanks for the update. 
 
please let us know whether you need any assistance 
 
Regards, 
Isuriya R 


Loader.
Up arrow icon