0

Can someone tell me if what I want to do is possible (asp.net 4)

Ok I have a businesslogic object called CityBusinessObject. it has a public method called GetCities() This does a bunch of magic using EF and Linq, and returns a list of city objects into a public property. I link this up to my JQgrid by setting the datasource to the property, and it works awesomely. I can get it to page also (10 records at a time)

but this is client side, and not very efficient.

I would prefer to have a public method called GetCitiesbyPage(int skip, int take) which then gets called whenever the grid does a page.

my question is 1. how do i get the grid to call my GetCitiesbyPage method whith values for the skip and take 2. how do i get the grid to still know about all the other pages all the time without holding the data. i.e. skip(0).take(10) will effectively only have 10 rows in it, therefore the grid only "knows" about 10 rows, therefore 1 page

Crudler
  • 2,194
  • 3
  • 30
  • 57

1 Answers1

2

If you use jqGrid with the parameter url: "Url.Action("GetCitiesbyPage")" and datatype: 'json' the default behavior of jqGrid is almost like you want (see the documentation). jqGrid send to the url additional parameters string sidx, string sord, int page, int rows. So you should use rows as take parameter and use page-1 as skip. To gives jqGrid information about the total number of pages and the total number or records (items) the default format of the data returned by the controller action should be

{
    "total": 2,
    "page": 1,
    "records": 12,
    "rows": [
        ... the 10 rows of data
    ]
}

and you will see in the pager something like the following

enter image description here

See the answer for more information. In the answer or in this one you can download the demo project which shows how to implement the server side paging with EF.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks. looks exactly like what i need. demo proj is in MVC, and i am not finding those properties in the webforms version. would u know those offhand? – Crudler Mar 05 '12 at 15:40
  • i must also state that i am a serious noob at this :) – Crudler Mar 05 '12 at 15:47
  • @Crudler: jqGrid need pure data (JSON or XML) to fill the grid. MVC can bu used for example to return JSON data. You should add WFC or ASMX web service to the WebForm project and reference the WFC method or ASMX web method in the `url` of jqGrid. See [here](http://stackoverflow.com/a/3914796/315935) and [here](http://stackoverflow.com/a/3161542/315935) demo projects. – Oleg Mar 05 '12 at 15:50
  • @Crudler: By the way, in [the answer](http://stackoverflow.com/a/10871428/315935) you will find code which uses ASHX only. So it can be used in WebForm applications. The demo project can be downloaded from [here](http://www.ok-soft-gmbh.com/jqGrid/jqGridASHX.zip) – Oleg Jun 06 '12 at 10:56