Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, so currently I do this:</p> <pre><code> var iquery = GetPagedCriteria&lt;T&gt;(request, true) .SetProjection(Projections.Property("Id")); var ids = iquery.List&lt;Guid&gt;(); var index = ids.IndexOf(new Guid(request.SelectedId)); if (index &gt;= 0) request.Page = index / request.Rows + 1; </code></pre> <p>and in jqGrid setup options</p> <pre><code> url: "${Url.Href&lt;MyController&gt;(c =&gt; 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&lt;MyController&gt;(c =&gt; c.JsonIndex(null))}"}); }, loadComplete: function() { $("#grid").setSelection("${Id}"); } </code></pre> <p>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.</p> <p>And of course I always use sorting or the method won't work.</p> <p>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 ;-)</p> <p>UPDATE: hm, if I sort by id initially I'll be able to use the technique like "SELECT COUNT(*) ... WHERE id &lt; selectedid". This will eliminate the "pull ids" problem... but I'd like to sort by name initially, anyway.</p> <p>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.</p> <p>UPDATE: here's sources that include the above technique: <a href="http://sprokhorenko.blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html" rel="nofollow noreferrer">http://sprokhorenko.blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload