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 507561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:49:01+00:00 2026-05-13T06:49:01+00:00

I use jqGrid to display data which is retrieved using NHibernate. jqGrid does paging

  • 0

I use jqGrid to display data which is retrieved using NHibernate. jqGrid does paging for me, I just tell NHibernate to get “count” rows starting from “n”.

Also, I would like to highlight specific record. For example, in list of employees I’d like a specific employee (id) to be shown and pre-selected in table.

The problem is that this employee may be on non-current page. E.g. I display 20 rows from 0, but “highlighted” employee is #25 and is on second page.

It is possible to pass initial page to jqGrid, so, if I somehow use NHibernate to find what page the “highlighted” employee is on, it will just navigate to that page and then I’ll use .setSelection(id) method of jqGrid.

So, the problem is narrowed down to this one: given specific search query like the one below, how do I tell NHibernate to calculate the page where the “highlighted” employee is?

A sample query (simplified):

var query = Session.CreateCriteria<T>();
foreach (var sr in request.SearchFields)
   query = query.Add(Expression.Like(sr.Key, "%" + sr.Value + "%"));
query.SetFirstResult((request.Page - 1) * request.Rows)
query.SetMaxResults(request.Rows)

Here, I need to alter (calculate) request.Page so that it points to the page where request.SelectedId is.

Also, one interesting thing is, if sort order is not defined, will I get the same results when I run the search query twice? I’d say that SQL Server may optimize query because order is not defined… in which case I’ll only get predictable result if I pull ALL query data once, and then will programmatically in C# slice the specified portion of query results – so that no second query occur. But it will be much slower, of course.

Or, is there another way?

  • 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-13T06:49:01+00:00Added an answer on May 13, 2026 at 6:49 am

    OK, so currently I do this:

        var iquery = GetPagedCriteria<T>(request, true)
                        .SetProjection(Projections.Property("Id"));
        var ids = iquery.List<Guid>();
        var index = ids.IndexOf(new Guid(request.SelectedId));
        if (index >= 0)
           request.Page = index / request.Rows + 1;
    

    and in jqGrid setup options

           url: "${Url.Href<MyController>(c => c.JsonIndex(null))}?_SelectedId=${Id}",
           // remove _SelectedId from url once loaded because we only need to find its page once
           gridComplete: function() { 
              $("#grid").setGridParam({url: "${Url.Href<MyController>(c => c.JsonIndex(null))}"}); 
           },
           loadComplete: function() {
              $("#grid").setSelection("${Id}");
           }
    

    That is, in request I lookup for index of id and set page if found (jqGrid even understands to display the appropriate page number in the pager because I return the page number to in in json data). In grid setup, I setup url to include the lookup id first, but after grid is loaded I remove it from url so that prev/next buttons work. However I always try to highlight the selected id in the grid.

    And of course I always use sorting or the method won’t work.

    One problem still exists is that I pull all ids from db which is a bit of performance hit. If someone can tell how to find index of the id in the filtered/sorted query I’d accept the answer (since that’s the real problem); if no then I’ll accept my own answer 😉

    UPDATE: hm, if I sort by id initially I’ll be able to use the technique like “SELECT COUNT(*) … WHERE id < selectedid”. This will eliminate the “pull ids” problem… but I’d like to sort by name initially, anyway.

    UPDATE: after implemented, I’ve found a neat side-effect of this technique… when sorting, the active/selected item is preserved 😉 This works if _SelectedId is reset only when page is changed, not when grid is loaded.

    UPDATE: here’s sources that include the above technique: http://sprokhorenko.blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html

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

Sidebar

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.