Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, SlickGrid does not have any built in functionality so we have to roll it ourselves. Here is one answer from stackoverflow:</p> <ul> <li><a href="https://stackoverflow.com/questions/6668613/slickgrid-ajax-data">SlickGrid AJAX data</a></li> </ul> <p>And now here is my solution, which works a treat and I think is really easy. The technology stack for this is:</p> <ul> <li>RavenDB </li> <li>NancyFX </li> <li>CoffeeScript</li> <li>SlickGrid</li> </ul> <p><strong>The CoffeeScript</strong></p> <pre><code>loadData=(grid)-&gt; take = 600 loadingGlyph = $ "&lt;img/&gt;", {class:"loading", style:"float:right;margin-top:5px", src:"/Content/img/ajax-loader.gif", alt:"loading", width:"16", height:"16"} $(".slick-pager-status").after loadingGlyph for skip in [0..viewdata.UserCount] by take $.getJSON("/users/#{skip}/#{take}") .done (users) =&gt; grid.addRows users $(".loading").hide() if users.length &lt; take $ -&gt; columns = [..your columns..] grid = [..your slick-grid..] loadData grid </code></pre> <p>First I stick in a fancy loading-glyph graphic to show the grid is busy. Note that I intend loading batches of data asynchronously. This will put the grid in a usable state very quickly (after the first batch returns) but the user needs to be told that the data is still downloading in the background.</p> <p>To batch load the data I loop in chunks whose size is determined by the value of <code>take</code> and terminating at the <code>viewData.UserCount</code> value. This has been pre-populated when the page was requested and is the total number of items available (or the maximum you wish to load).</p> <p>Finally I have made use of the <code>addRows</code> method I added to my slick-grid wrapper (not shown). This allows for the fast addition of row-batches and it looks like this:</p> <p><strong>Extend Slick-Grid</strong> </p> <pre><code>addRows:(rows)-&gt; dataView.beginUpdate() dataView.addItem row for row in rows dataView.endUpdate() </code></pre> <p>For the sake of completeness, here is the rest of process, including the RavenDB service call that does the batch data retrieval.</p> <p><strong>NancyFX Module</strong></p> <pre><code>Get["/users/{skip}/{take}"] = parameters =&gt; { var skip = (int)parameters.skip; var take = (int)parameters.take; var data = UserService.GetForGrid(Db, skip, take); return Response.AsJson(data); }; </code></pre> <p><strong>RavenDB Service</strong></p> <pre><code>public static List&lt;UserGridDTO&gt; GetForGrid(IDocumentSession db, int skip=0, int take=512) { return db.Query&lt;User&gt;() .OrderBy(u=&gt;u.Id) .Skip(skip) .Take(take) .ToList() .Select(user =&gt; new UserGridDTO { id = user.Id, Email = user.Email, Name = user.DisplayName, }) .ToList(); } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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