Working with grid using remote data binding way

Hello, I am trying to work with grid using server side mode. I made it work with OData, But I am having some problems. Could you help?

1 - Is it possible to use grid remote data binding without use OData? I saw the WebApiAdaptor but I don't know how do I use it. In WebApiAdaptor way, which properties that the grid send to the server? Do you have any example, with asp.net core?

2 - I am doing some filters using querybuilder, but every time that I change the page, the filters and the order of columns is lost. I am trying filter doing this:
 

Ps. If you have an example of remote grid with filters and order by, selecting columns both on front-end and back-end would help A LOT.

Thank you very much

3 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team January 29, 2021 05:55 AM UTC

Hi Rafael, 
 
Greetings from Syncfusion support. 
 
We checked your query and would like to let you know that when Web API adaptor is used for binding data to the Grid, the request will be sent to server for every action like filtering, sorting, searching, CRUD in Grid. Based on the query string you need to handle the actions in your controller page as there is no inbuilt classes to perform sever side actions. So in Web API the Grid sends only the query request from client to server side and in server side you need to perform the corresponding operations and return back the response to the Grid. 
 
As per Web API standard the Grid sends the Http request as GET for data fetching, Grid actions and POST, PUT, DELETE request for CRUD actions in server side . 
 
The response JSON object should contain properties - ‘Items’ (current view records as JSON format) and ‘Count’ (total number of records in your database). The Grid renders the page navigation items based on Count. 
 
We have demonstrated handling the Grid paging, filtering and sorting actions for Web API adaptor in the server-side in the below code snippet, 
 
// GET: api/Home 
[HttpGet] 
public object Get() 
    { 
        var queryString = HttpContext.Request.Query; 
        int skip = Convert.ToInt32(queryString["$skip"]); //paging 
        int take = Convert.ToInt32(queryString["$top"]); 
        string filter = queryString["$filter"]; // filtering query 
        string sort = queryString["$orderby"]; // sorting query 
        var data = OrdersDetails.GetAllRecords(); 
        List<OrdersDetails> Datae = new List<OrdersDetails>(); 
        List<OrdersDetails> Datase = new List<OrdersDetails>(); 
        if (sort != null) //Sorting 
        { 
            switch (sort) 
            { 
                case "OrderID": 
                    data = data.OrderBy(x => x.OrderID).ToList(); 
                    break; 
                case "OrderID desc": 
                    data = data.OrderByDescending(x => x.OrderID).ToList(); 
                    break; 
                case "EmployeeID": 
                    data = data.OrderBy(x => x.EmployeeID).ToList(); 
                    break; 
                case "EmployeeID desc": 
                    data = data.OrderByDescending(x => x.EmployeeID).ToList(); 
                    break; 
            } 
        } 
        if (filter != null) 
        { 
            var newData = data; 
            var newfiltersplits = filter; 
            var multipleFilters = newfiltersplits.Split("and"); 
            var count = 0; 
            while (count < multipleFilters.Length) { 
                multipleFilters[count] = (multipleFilters[count][0] == ' ') ? multipleFilters[count].Substring(1, multipleFilters[count].Length - 1) : multipleFilters[count]; 
                multipleFilters[count] = (multipleFilters[count][multipleFilters[count].Length - 1] == ' ') ? multipleFilters[count].Substring(0, multipleFilters[count].Length - 1) : multipleFilters[count]; 
                var filtersplits = multipleFilters[count].Split('(', ')', ' '); 
                var filterfield = filtersplits[1]; 
                var filtervalue = filtersplits[3]; 
                if (filtersplits.Length != 5) 
                { 
                    filterfield = multipleFilters[count].Split('(', ')', '\'')[3]; 
                    filtervalue = multipleFilters[count].Split('(', ')', '\'')[5]; 
                } 
                switch (filterfield) 
                { 
                    case "OrderID": 
                        Datae = (from cust in newData where cust.OrderID.ToString() == filtervalue.ToString() select cust).ToList(); 
                        break; 
                    case "EmployeeID": 
                        Datae = (from cust in newData cust.EmployeeID.ToString() == filtervalue.ToString() select cust).ToList(); 
                        break; 
                } 
                newData = Datae; 
                count++; 
            } 
            data = Datae; 
        } 
        return new 
        { 
            Items = data.Skip(skip).Take(take), 
            Count = data.Count() 
        }; 
} 
 
We have prepared an Asp.Net Core with angular sample application based on this for your reference. You can download it from the following link, 
 
 
Note: You can run this sample by opening the project in Visual Studio, restoring the packages and node modules for it and then launch the application. 
 
If you need to use in-built classes for handling the server-side actions in the Grid, then we suggest you to use the URL adaptor for binding data to the Grid. With this you can perform the Grid actions using the in-built DataOperations class provided in the EJ2 Base library package. More details on the URL adaptor can be checked in the below documentation link, 
 
 
We have also prepared an Asp.Net Core with angular sample application of Grid with URL adaptor for your reference. You can download it from the following link, 
 
 
Note: You can run this sample by opening the project in Visual Studio, restoring the packages and node modules for it and then launch the application. 
 
The other available remote data adaptors can be checked in the below documentation link, 
 
 
You can use the adaptor which best suits your requirement for binding data and performing grid actions(Sort, Page, Filter, etc. ) from the server. 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Marked as answer

RA Rafael February 9, 2021 02:14 PM UTC

Hello,

I am sorry for the delay to answer... We are trying to make it work here.

Thank you very much


SM Shalini Maragathavel Syncfusion Team February 11, 2021 04:45 AM UTC

Hi Rafael, 

Thanks for the update. 

We will wait to hear from you. 

Regards, 
Shalini M. 
 


Loader.
Up arrow icon