绑定jQuery网格?

Say I have a jquery grid ( plugin).

Ofcourse it has the option to get data from an ajax source or from other source(client source).

Now lets say that when a page loads , I should display initial data( well not much data because I have a pager and from the second page and so on, the request paged got as an ajax result)

HOW should I bind the initial data (design POV)

options I have :

  • In - ASP.net / PHP ( on server code ) register a startup client script which will run after the page loads(this script will fetch data by ajax)

( cons: it will actually do 1 more request to the server (to fetch the data))

  • I could write (with the initial response ) a hidden field which will hold the json data (still) by register client startup script - and in <Script> - read data from the hidden field.

  • other option ?

what is the correct way of doing it ?

p.s. I dont want to put the bind in document.ready because I believe it is better to bind data a lot sooner.

I prefer the first approach where the view UI is completely separate from the data source even though it results in a second response from the server.

This allows the view to be cached entirely; though there are caching options for fragments on some platforms (like ASP.NET) so with a bit of configuration embedded data is probably not that much of a big deal.

If you want to limit callbacks then the same exact code responsible for generating JSON replies (for paging or server side filtering service calls necessary for the grid to function) is used to provide the first page of data embedded within the page itself upon request.

As an aside DataTables supports this functionality (embedded data with subsequent requests satisfied by AJAX calls).