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

  • SEARCH
  • Home
  • 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 6531895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:56:02+00:00 2026-05-25T09:56:02+00:00

jqGrid takes the following JSON format: { total: 5, page: 2, records: 55, rows

  • 0

jqGrid takes the following JSON format:

{ 
  "total": "5", 
  "page": "2", 
  "records": "55",
  "rows" : [
    {"id" :"21", "cell" :["cell11", "cell12", "cell13"]},
    {"id" :"22", "cell" :["cell21", "cell22", "cell23"]},
      ...
    {"id" :"30", "cell" :["cell31", "cell32", "cell33"]},
  ]
}

I’m trying to make a method as reusable as possible to pass data back through AJAX to the jqGrid.

var result = new
{
    total = (int) Math.Ceiling((double) totalCount/PageSize),
    page = PageIndex,
    records = totalCount,
    rows = data.Select((d, id) => new {id, cell = d.SerializeGridParameters()}).ToArray()
};

As you can see, currently I managed to add the index without extra effort, but I’m having trouble with the field data.

So far, I managed to deal with it by using an interface:

public interface IGridParameterListable
{
    List<string> SerializeGridParameters();
}

For my data (which is an IEnumerable<T> where T : IGridParameterListable).
Thing is I’d much rather have a generic method that just blindly converts objects property values to a List<string>..

Doesn’t sound too cute, I know, I’m open to other ideas.
I want to avoid as much as possible repeating the data structure for a grid on both the client and server sides.

  • 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-25T09:56:02+00:00Added an answer on May 25, 2026 at 9:56 am

    This might be a better option.

    public string SerializeQuery<T>(IQueryable<T> query, Func<T, List<string>> select)
    {
        // stuff ...
    
        var result = new
        {
            total = (int)Math.Ceiling((double)totalCount / PageSize),
            page = PageIndex,
            records = totalCount,
            rows = data.Select((d, id) => new { id, cell = select(d) }).ToArray()
        };
    
        // stuff ...
    }
    

    I eliminate the need of an interface, and move the conversion to the implementation of the query for each particular grid. In this example:

    [WebMethod]
    [ScriptMethod]
        public string GetData(GridSettings grid)
        {
            var query = new FakeComputersRepository().Computers();
            var response = grid.SerializeQuery(query, d => new List<string>
            {
                d.ID.ToString(),
                d.IsOnline.ToString(),
                d.Name,
                d.IP,
                d.User
            });
    
            return response;
        }
    

    A tad better, I think.
    Any other ideas, to further expand on this?

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

Sidebar

Related Questions

the rownum property of jqgrid by default takes 20. now i have json data
jqGrid is powered by remote json data in ASP .NET MVC2 application. On page
I have a jqGrid on a page and users can click a button to
I have a jqGrid with which users will select records. A large number of
jqgrid is used to show stock status from server. Data is retrieved in json
JQgrid outputs this html for a left aligned cell - but it is too
jqGrid tree nodes are read from server using json data. Click in node reads
My jqGrid gets its JSON data from a URL. It shows every columnt right
I'm using jQuery Grid 3.7.2 to load data in 'loadonce' mode, i.e. jqGrid takes
I have a jqgrid where the database table has a few thousand rows, but

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.