CsvStore is a simple read-only store provided by Dojo and contained in the DojoX project. CsvStore is a read interface that works with CSV formated data files. The CSV file format is commonly known to folks who work regularly with spread sheet data. Like ItemFileReadStore, CsvStore reads the contents from an http endpoint or a JavaScript Data object that contains CSV formatted data. The following is an example of a CSV data source:
Title, Year, Producer City of God, 2002, Katia Lund Rain,, Christine Jeffs 2001: A Space Odyssey, , Stanley Kubrick "This is a ""fake"" movie title", 1957, Sidney Lumet Alien, 1979 , Ridley Scott "The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott "Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"
Note that in the above data, the first row is always assumed to be the column names. Those are what get assigned as the attribute names for the CSV items. Each row in the CSV data is treated as a single item.
The following dojo.data APIs are implemented by CsvStore
The constructor for CsvStore takes three possible parameters in its keyword arguments as defined in the following list:
The fetch method query syntax for CsvStore is simple and straightforward. It allows a list of attributes to match against in an AND fashion, just like ItemFileReadStore. For example, a query object that looks like the following example will locate all items that have attributes of those names that match both of those values:
{ foo:"bar", bit:"bite"}
Note that CsvStore supports the use of wild cards (multi-character * and single character ?) in its attribute value matching.
To find all items with attribute foo that start with bar, the query would be:
{ foo:"bar*"}
To find all items with attribute foo the value of which ends with ar and ignoring only the first character, the query would be:
{ foo:"?ar"}
NOTE: Other stores should follow the same semantics in how it defines its queries for consistency.
Assume a data source as defined by the example data format in this page.
Ridley Scottvar store = new dojox.data.CsvStore({url: "movies.csv", label: "Title"});
var gotMovies = function(items, request){
for (var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located movie: " + store.getLabel(item);
}
}
var request = store.fetch({query: {Producer:"Ridley Scott"}, onComplete: gotMovies});
var store = new dojo.data.ItemFileReadStore({url: "movies.csv", label: "Title"});
var gotTitles= function(items, request){
for (var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located name that started with A: " + store.getLabel(item);
}
}
var request = store.fetch({query: {Title:"A*"}, queryOptions: {ignoreCase: true}, onComplete: gotTitles});
For further examples refer to the test cases provided in dojox.data.tests.