0

I am constructing a jqgrid with the following code:

  $(document).ready(function () {
            $("#Data").jqGrid({
                url: '/Home/LoadData',
                loadonce:true,
                datatype: "json",
                mtype: "GET",
                colNames:["ID"],
                colModel: [
            { name: "Id",index:'ID',width:800, align: "center"}
                          ],
                pager: "#Pager",
                rowNum: '10',
                rowList: [10, 20, 30],
                sortname: "ID",
                sortorder: "asc",
                height: "auto",
                gridview:true,
                sortname: "ID",
                viewrecords: true,
                caption: "My First Grid",
                loadComplete: function (data) {
    var $this = $(this),
        datatype = $this.getGridParam('datatype');

    if (datatype === "xml" || datatype === "json") {
        setTimeout(function () {
            $this.trigger("reloadGrid");
        }, 100);
    }
}
            });
        });

This is working absolutely fine. But, this is all happening in the client side. I am also using loadonce:true to the grid which means the grid loads all the data at once.

But, i am having approx 30,000 records.

 loadonce=true 

This is not an correct option. So, i need to implement server side sorting and server side paging.

I need to load records like page by page but sorting/Filtering should happen taking into consideration all the records.

Please help in this..if possible please provide code sample for C# code and Jquery script for paging and sorting..

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
Sai Avinash
  • 4,683
  • 17
  • 58
  • 96
  • You can take a look in [the old answer](http://stackoverflow.com/a/5501644/315935) and some other answers referenced in "UPDATED 2" part. – Oleg Oct 11 '13 at 08:55
  • @Oleg..i am having difficulty understanding that answer.. – Sai Avinash Oct 11 '13 at 09:35
  • I am not using Entity Framework.. – Sai Avinash Oct 11 '13 at 09:37
  • If you write that you don't use Entity Framework it gives still no information about *what* you do. In any way the referenced answer shows main steps which should be done. [Another answer](http://stackoverflow.com/a/18299182/315935) and [this one](http://stackoverflow.com/a/8480127/315935) show the main steps of the implementation in case of usage STORED PROCEDURES or any direct SQL statements. You can see that your question much more depend on the Database which you use, from the access to database which you use and from other database specific implementation details. – Oleg Oct 11 '13 at 10:15
  • @Oleg..Thanks..can you please specify what are the parameters that need to be set/send to method that fetches data to database. I mean page,sord,sidx,rows.sorry to trouble you – Sai Avinash Oct 11 '13 at 10:37
  • It's `rows` and `page` parameters which jqGrid send to the server by default. The `rows` is the number or rows which are requested (based on `rowNum` option) and 1-based the page number of the page requested. The return the first page one can use `SELECT TOP (@rows)` directly or indirectly (see [the answer](http://stackoverflow.com/a/175965/315935)). To take in the consideration `page` parameter one have many options which mostly depends on the Database which you use. The option `sord`,`sidx` need be for `ORDER BY` part of select. – Oleg Oct 11 '13 at 10:45
  • @oleg..Wow..The Stored Proc for Paging is great that you mentioed in the other post..if i come to know about the parameters that i mentioned above..i would be great on Pagination.. – Sai Avinash Oct 11 '13 at 10:45
  • To use `sord` and `sidx` in `ORDER BY` one can use `CASE` construct. See [here](http://blog.sqlauthority.com/2007/07/17/sql-server-case-statement-in-order-by-clause-order-by-using-variable/) for example. The SQL statement will be relatively long, but it will be effectively executed. – Oleg Oct 11 '13 at 10:51
  • @Oleg thanks..i will implement paging and sorting straight away.. – Sai Avinash Oct 11 '13 at 11:36

0 Answers0