locked
Server-side Paging,Filtering & Sorting using MVC6 grid inside my asp.net mvc core RRS feed

  • Question

  • User-540818677 posted

    Inside my Asp.net Core MVC i added the MVC6 grid from this url @ https://mvc6-grid.azurewebsites.net/. but i have noted that the paging and filtering will be done on the client side, so each time we filter,sort or paging the whole records will be retrived. so can i force the MVC6 Grid to do the filter,sort and paging on the server-side instead?

    Here is my Action Method:-

    public async Task<IActionResult> Index()
            {
    
                var results = await _context.Doctor.ToListAsync();
                return View(results);
    
            }

    and here is the view:-

    @model IEnumerable<LandingPageFinal3.Models.Doctor>
    
    @(Html
        .Grid(Model)
        .Build(columns =>
        {
            columns.Add(model => model.PhysicianFirstName).Titled("Name");
            columns.Add(model => model.PhysicianLastName).Titled("Surname");
            columns.Add(model => model.Phone).Titled("Phone");
        })
        .Using(GridFilterMode.Header)
        .Empty("No data found")
        .Filterable()
        .Sortable()
        .Pageable()
    )

    any advice on this please?

    Thanks

    Friday, May 8, 2020 12:28 AM

Answers

  • User-474980206 posted

    no.  because the grid helper in the view (still server side) will does the paging, filtering and sorting (server side), you need to pass a IQueryable to the grid, if you want it done in the database. while generally not recommend to pass a IQueryable to a view, the grid requires it. see the docs:

                var results = await _context.Doctor.Set<Doctor>();
                return View(results);

    the grid appears to not support async processing of the queries, so you could see performance scaling issues.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 8, 2020 8:30 PM
  • User-474980206 posted

    it means the sql query is running in the view, so the view needs the error handling. also any iteration (foreach, count(), etc) runs the sql query.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 10, 2020 1:37 AM

All replies

  • User-474980206 posted

    It’s a server side grid. Paging, filter and sort is a post back and done on the server.

    Friday, May 8, 2020 2:38 PM
  • User-540818677 posted

    It’s a server side grid. Paging, filter and sort is a post back and done on the server.

    but when ever i page,filter or sort all the records from the database will be get, also inside the my action methods i am getting all the records using :-

    var results = await _context.Doctor.ToListAsync();
                return View(results);

    is this correct? so not sure how in my case i will get server-side filtering,sorting and paging?

    Friday, May 8, 2020 5:21 PM
  • User-474980206 posted

    no.  because the grid helper in the view (still server side) will does the paging, filtering and sorting (server side), you need to pass a IQueryable to the grid, if you want it done in the database. while generally not recommend to pass a IQueryable to a view, the grid requires it. see the docs:

                var results = await _context.Doctor.Set<Doctor>();
                return View(results);

    the grid appears to not support async processing of the queries, so you could see performance scaling issues.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 8, 2020 8:30 PM
  • User-540818677 posted

    no.  because the grid helper in the view (still server side) will does the paging, filtering and sorting (server side), you need to pass a IQueryable to the grid, if you want it done in the database. while generally not recommend to pass a IQueryable to a view, the grid requires it. see the docs:

                var results = await _context.Doctor.Set<Doctor>();
                return View(results);

    the grid appears to not support async processing of the queries, so you could see performance scaling issues.

    ok so i changed the action method as follow:-

     public IActionResult Index()
            {
                
                var results = _context.Doctor;
                return View(results);
    
            }
    

    and the view as follow:-

    @model IQueryable<LandingPageFinal3.Models.Doctor>
    

    now i can see that the paging is been done on the server. so are my above modifications valid?

    second question, why it is not recommended to pass IQueryable to the view?

    Friday, May 8, 2020 8:56 PM
  • User-474980206 posted

    it means the sql query is running in the view, so the view needs the error handling. also any iteration (foreach, count(), etc) runs the sql query.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 10, 2020 1:37 AM