Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3362128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:14:10+00:00 2026-05-18T03:14:10+00:00

I have a jqgrid where the database table has a few thousand rows, but

  • 0

I have a jqgrid where the database table has a few thousand rows, but the jqrid shows only 15 at a time.

It should be displaying very quickly (it doesnt take long to query 15 rows). But instead it takes 10 – 20 seconds, which indicates to that it is retrieving the entire table each time.

The grid is defined like this:

$("#Products").jqGrid({
url: url, mtype: "get", datatype: "json", jsonReader: {
    root: "Rows", page: "Page", total: "Total", records: "Records", repeatitems: false,
    userdata: "UserData",id: "Id"},
colNames: ["Product Id","Product Code", ... etc ],
colModel: [{ name: "Id", ... etc}],
viewrecords: true, height: 400, width: 800, pager: $("#jqgPager"),
rowNum: 15, rowList: [50, 100, 200], 
autowidth: true, multiselect: false

And the server side (MVC2 action) does this:

var model = (from p in products
    select new
    {
    p.Id, p.ProductCode, p.ProductDescription,
    AllocatedQty = p.WarehouseProducts.Sum(wp => wp.AllocatedQuantity),
    QtyOnHand = p.WarehouseProducts.Sum(wp => wp.OnHandQuantity)
    }).AsQueryable();

    JsonResult json = Json(model.ToGridData(
        page, rows, orderBy, "", 
        new[] { "Id", "ProductCode", "ProductDescription", "AllocatedQty", "QtyOnHand" }),
            JsonRequestBehavior.AllowGet);

And finally the model.ToGridData extension method does this:

var data =_service.GetAll(); 
var page = data.Skip((index) * pageSize).Take(pageSize);
list.Add(page.AsEnumerable);

And I’m a bit lost as to where the problem lies:

  • Have I set the jqgrid paging options incorrectly?
  • Have I written bad Linq that pulls all rows regardless?
    eg does the Sum() cause all rows to be read?
  • Have I done the .Skip().Take() incorrectly?
  • Have I missed something else entirely?

EDIT

When comparing my code to the example posted by Oleg I can see that I do things in this order:

  1. getAll
  2. select model fields
  3. page

Wheras Olegs sample seems to be in this order:

  1. getAll
  2. page
  3. select model fields

So I’ve changed to this much simpler implementation:

public ActionResult GetProductList(int page, int rows, string sidx, string sord, 
string searchOper, string searchField, string searchString)
{
        List<Product> products = _productService.GetAllProducts();
        int totalRecords = products.Count();

        var pagedData = products.Skip((page > 0 ? page - 1 : 0) * rows).Take(rows);

        var model = (from p in pagedData
                    select new
                    {
                        p.Id, p.ProductCode, p.ProductDescription,
                        Barcode = string.Empty, UnitOfMeasure = string.Empty,
                        p.PackSize, AllocatedQty = string.Empty,
                        QtyOnHand = string.Empty }).ToList();

        var jsonData = new
        {
            total = page, records = totalRecords,
            page = (totalRecords + rows - 1) / rows, rows = model
        };

        return Json(jsonData, JsonRequestBehavior.AllowGet);
}

However this has a new problem:

A circular reference was detected while serializing an object of type
'System.Data.Entity.DynamicProxies.Product_FA935D3899E2...

The only difference I can see now with Oleg’s sample is that his getAll returns IQueryable where mine is just List.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:14:10+00:00Added an answer on May 18, 2026 at 3:14 am

    You should post more full code. The model.ToGridData is not defined in the current code for example. How you caclulate index from the imput patrameters and so on are also unclear. Only having model.ToGridData() one can say whether the output which your program produce are correspond to the jsonReader which you define.

    I recommend you to look this old answer, where both paging and sorting are used. In one more answer you will find more references to code examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.