Dojo's Industrial-Strength Grid Widget
So far, the examples demonstrated here are using ItemFileReadStore or ItemFileWriteStore, which necessarily implies that your data set is small enough that it's practical to load it into the client. In other words, we've been dodging the issue of having such a large data set (say, millions of records) that it can't all be loaded into the client. Let's put together a final example that demonstrates the grid at work using a server-backed store, such as the dojox.data.QueryReadStore. The markup for defining the DataGrid should look familiar enough. Note that because the QueryReadStore implements only the Read and Identity APIs, trying to make cells editable would have no effect. It's totally possible, however, to extend the QueryReadStore with Write and Notification support or attach a store, such as the dojox.data.JsonRestStore, that implements all four dojo.data APIs to produce an editable interface:
<body class="tundra">
<!--Fetch data from a store as usual.
This time, it just happens to be a QueryReadStore -->
<span dojoType="dojox.data.QueryReadStore"
jsId="gridStore"
url="/data">
</span>
<!-- Define the grid directly in markup and allow the parser
to take care of the rest -->
<table id="gridNode"
dojoType="dojox.grid.DataGrid" store="gridStore">
<thead>
<tr>
<th width="50%" field="id">ID</th>
<th width="50%" field="label">Label</th>
</tr>
</thead>
</table>
</body>
To try out the example, however, you need a basic server implementation that returns pages of data whenever the QueryReadStore requests them. A minimalistic server written in CherryPy is shown in Listing 4.

Figure 5. Given a server-backed store, the DataGrid can render arbitrary numbers of rows—all without pagination!
Listing 4. An ultra-simple Web server that provides slices of a very large (mock) data source for a dojox.grid.Grid client that uses a dojox.data.QueryReadStore to page the data on demand.
import cherrypy #do an "easy_install cherrypy" to get it
from cherrypy.lib.static import serve_file
import demjson #do an "easy_install demjson" to get it
import os
from random import randint #for building up mock data
json = demjson.JSON(compactly=False)
jsonify = json.encode
NUM_ITEMS = 1000000
class Content:
def __init__(self):
"""
Maybe you would call out to a db with some sql to get some
data based on the query string that comes into /data. For
now, we'll build up some static data to use.
"""
self.items = []
possible_item_labels = ["foo", "bar", "baz", "qux"]
id=0
for i in xrange(NUM_ITEMS):
self.items.append({
'id' : id,
'label' : possible_item_labels[randint(0,3)]
})
id +=1
#keep track of sort order b/c sorting is expensive...
self.current_sort_order = ""
@cherrypy.expose
def data(self, **kw):
"""
Serve up the data via http://localhost:8000/data
kw will contain whatever is in your store's query.
By default the query string will come across as
something like:
?name=*&start=0&count=20 to populate the table
Note: you may get into trouble if you have multiple users
trying to access this url and changing the sort order of
items all at the same time (but relax, this is just
a little demo.)
"""
#sorting the items by values for a given dictionary key...
if kw.get('sort') and self.current_sort_order != kw.get('sort'):
if kw['sort'][0] == '-': #descending order, slice off the -
self.items.sort(lambda m,n:cmp(m.get(kw['sort'][1:]), \
n.get(kw['sort'][1:])),reverse=True)
else: #ascending order
self.items.sort(lambda m,n:cmp(m.get(kw['sort']), \
n.get(kw['sort'])))
self.current_sort_order = kw['sort']
#slicing the data...
start = int(kw['start'])
end = start + int(kw['count'])
#serving up the slice of interest as well as the total size
return jsonify({
'numRows':NUM_ITEMS,
'items':self.items[start:end],
'identifier' : 'id'
})
@cherrypy.expose
def index(self, **kw):
"""
Serve up the web page through http://localhost:8000/
"""
return serve_file(os.path.join(os.getcwd(), 'page.html'))
#the page containing the grid
cherrypy.server.socket_port = 8000
cherrypy.quickstart(Content(),'/')
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Web Development News
Developer Poll
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- RSS Feeds
- What's the tweeting protocol?
- Trying to Tame the Tablet
- Validate an E-Mail Address with PHP, the Right Way
- New Products
- Drupal is an Awesome CMS and a Crappy development framework
37 min 46 sec ago - IT industry leaders
3 hours 18 sec ago - Reply to comment | Linux Journal
19 hours 48 min ago - Reply to comment | Linux Journal
22 hours 21 min ago - Reply to comment | Linux Journal
23 hours 38 min ago - great post
1 day 13 min ago - Google Docs
1 day 35 min ago - Reply to comment | Linux Journal
1 day 5 hours ago - Reply to comment | Linux Journal
1 day 6 hours ago - Web Hosting IQ
1 day 7 hours ago








Comments
Excellent article
Excellent article .