Server Side Pagination, Sorting and Filtering

Hi

I want use DataAdapter for send the current parameters of grid to server. 

What class can I use in a controller for mapping parameters for pagination, sorting and filtering?

Thanks.


3 Replies

PS Pavithra Subramaniyam Syncfusion Team March 23, 2018 12:47 PM UTC

Hi Kabanets, 

We have checked your query and For Essential JavaScript 2 Grid server-side filtering , paging and sorting actions , you can use the `DataManager` class object on the controller action to receive the parameters from the client.  Please refer to the code example and sample link below. 

[index.chtml] 
@Html.EJS().Grid("Grid").DataSource(dataManger => 
   { 
       dataManger.Url("/Home/DataSource").CrossDomain(true).Adaptor("UrlAdaptor"); 
   }).Columns(col => 
{ 
.   .   .     
}).AllowPaging().AllowFiltering().Height("280").Render() 

[HomeController.cs] 
    public class HomeController : Controller 
    {       
        public ActionResult DataSource(DataManager dm) 
        { 
            var DataSource = OrderRepository.GetAllRecords(); 
            DataResult result = new DataResult(); 
            var Data = DataSource.ToList(); 
            int count = DataSource.Count(); 
            if (dm.where != null && dm.where.Count > 0) 
            { 
                .   .   . 
                    count = Data.Count; 
                } 
            } 
            return dm.requiresCounts ? Json(new { result = Data.Skip(dm.Skip).Take(dm.Take), count = count }) : Json(Data); 
        } 
    } 
} 
public class DataManager 
{ 
// for Paging 
    public int Skip { get; set; } 
 
    public int Take { get; set; } 
// for sorting 
    public List<Sort> Sorted { get; set; } 
 
    public bool requiresCounts { get; set; } 
//for filtering 
 
    public List<Wheres> where { get; set; } 
 
    public List<Search> search { get; set; } 
 
} 
 
public class Wheres 
{ 
    public List<Predicates> predicates { get; set; } 
    public string field { get; set; } 
    public bool ignoreCase { get; set; } 
 
    public bool isComplex { get; set; } 
 
    public string value { get; set; } 
    public string Operator { get; set; } 
 
} 
public class Sort 
{ 
    public string name { get; set; } 
    public string direction { get; set; } 
 
} 


Regards, 
Pavithra S. 



KA Kabanets March 23, 2018 12:58 PM UTC

Hi.

Thank you for the answer.
I think it would be nice to put this class in the framework. Aren't you?

Best regards,
Andrey.


PS Pavithra Subramaniyam Syncfusion Team March 26, 2018 12:50 PM UTC

Hi Kabanets, 

We have already planned to include the support for DataManager class in Essential JavaScript 2 component and logged a report for the same. This support will be available in our Essential Studio Volume 2 , 2018 release which will be rolled out at end of May, 2018 

Regards, 
Pavithra S. 


Loader.
Up arrow icon