HtmlTableStore
is a simple read-only store provided by Dojo and contained in the DojoX project. HtmlTableStore
is a read interface to work with HTML tables with a generally set format. HTML tables are common ways for Web data to be displayed and they can be extremely useful as an alternate representation of data that is displayed in a charting or gauge widget. This store was created so that widgets, that can use dojo.data data stores, can read their input from HTML table data islands in the current page or in a remote page URL. This store implements both dojo.data.api.Read
and dojo.data.api.Identity
.
The following example shows an HTML table that this store can read:
Books2.html
isbn | title | author |
---|---|---|
A9B57C | Title of 1 | Author of 1 |
A9B57F | Title of 2 | Author of 2 |
A9B577 | Title of 3 | Author of 3 |
A9B574 | Title of 4 | Author of 4 |
A9B5CC | Title of 5 | Author of 5 |
Note that the table rows in the
The constructor for
The fetch method query syntax for Note that To find all items with attribute To find all items with attribute NOTE: Other stores should follow the same semantics in defining queries for consistency. For these examples, we'll assume a data source as defined by the example data format in this page. For further examples, refer to the test cases provided in tag are the items. The
tag is used for defining the attribute name for each column in the table row for an item.
Constructor Parameters
HtmlTableStore
takes the following possible parameters in its keyword arguments:
id
of the HTML tag that contains the table to read from, in either a remote page (if the URL was passed) or in the current HTML DOM if the url
parameter is null. This is required.Query Syntax
HtmlTableStore
is simple and straightforward. It allows for a list of attributes to match against in an AND fashion, just like ItemFileReadStore
. For example, the following query object will locate all items that have attributes of those names that match both values:{ foo:"bar", bit:"bite"}
HtmlTableStore
supports the use of wild cards (multi-character * and single character ?) in its attribute value matching.Examples
foo
that start with bar
, the query would be:{ foo:"bar*"}
foo
that value ends with ar
and ignoring only the first character, the query would be: { foo:"?ar"}
Usage Examples
Example 1: Query for all books that start with ISBN: A9B57
var store = new dojox.data.HtmlTableStore({tableId: "books2"});
var gotBooks = function(items, request){
for (var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located book: " + store.getValue(item, "title"));
}
}
var request = store.fetch({query: {isbn:"A9B57*"}, onComplete: gotBooks});
Example 2: Query for all books that start with ISBN: A9B57 Case insensitively
var store = new dojox.data.HtmlTableStore({tableId: "books2"});
var gotBooks = function(items, request){
for (var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located book: " + store.getValue(item, "title");
}
}
var request = store.fetch({query: {isbn:"a9b57*"}, queryOptions: {ignoreCase: true}, onComplete: gotBooks});
Further Examples
dojox.data.tests
.