JSON Grid View

Get the best of CGridView with a client/server JSON communication

When dealing with lots of records, we found that the AJAX requests in Yii's standard format was quite slow. The reason is that the AJAX response returns the full page when the programmer does not make use of renderPartial on its views and also, even with the use of that method, the response returns the full HTML source.

We thought that we could speed up the server response if we just return a bunch of JSON objects that will be later on rendered on the client. Also, we thought that if we could somehow stored the results on the client we could reduce the amount of requests to the server... and we think we did it.

The TbJsonGridView allows the use of localStorage (degrades to in-memory cache for non-HTML5 browsers) for caching results and avoid the use of repetitive AJAX requests, and makes use of jqote2 javascript template engine to render the JSON objects.

For correct functioning of the grid, it's example usage has to be on separate page. Go to basic example page for TbJsonGridView to watch Json Grid View in action.

Here's all configuration properties which you can set for TbEditableView widget.

Property Description
boolean json = null Will be set to true if its an AJAX request. The grid will respond automatically with a JSON object when that occurs.
integer cacheTTL = 1 The number of seconds, minutes of hours we keep server responses on cache.
string cacheTTLType = "s" The type of cache duration s (seconds), m (minutes) or h (hours)
boolean localCache = true Whether to use local cache or not.

JSON specific columns

In order to work with TbJsonGridView, there are certain classes to be used with this special component. Without them, the grid won't work as expected.

All of the examples will be on separate pages.