[#113,docs/tutorial][l]: tutorial-basics written giving introduction to dataset and associated functionality.
* Minor corrections to several other parts of docs.
This commit is contained in:
@@ -50,57 +50,21 @@ root: ../
|
||||
likely be useful in understanding the details of these tutorials.</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4><a href="tutorial-basics.html">Dataset Basics - Creating, Querying, Using</a></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4><a href="tutorial-backends.html">Backends and loading data from Google Docs, Local CSV, DataHub and more</a></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4><a href="tutorial-views.html">Views Quickstart - Grids, Graphs, Maps and more</a></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4><a href="tutorial-backends.html">Loading from difference sources: Google Docs, Local CSV, DataHub</a></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Twitter Example</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Customing Display and Import using Fields</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Listening to events</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Setting and Getting State</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3>Extending Recline</h3>
|
||||
<div class="row">
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Create a new View</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Create a new Backend</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<div class="well">
|
||||
<h4>Create a Custom Record Object</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ holding summary information about a Field (or multiple Fields).
|
||||
All the models are Backbone models, that is they extend Backbone.Model. Note,
|
||||
however that they do not 'sync' (load/save) like normal Backbone models.
|
||||
|
||||
## Dataset
|
||||
<h2 id="dataset">Dataset</h2>
|
||||
|
||||
A Dataset is *the* central object in Recline. Standard usage is:
|
||||
|
||||
@@ -159,7 +159,6 @@ field's value (if any) and the current record. It's signature and behaviour is
|
||||
the same as for renderer.
|
||||
|
||||
|
||||
|
||||
<h2 id="query">Query</h2>
|
||||
|
||||
Query instances encapsulate a query to the backend (see <a
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
layout: container
|
||||
title: Library - Example - Loading data from different sources using Backends
|
||||
title: Tutorial - Backends - Loading data from different sources using Backends
|
||||
recline-deps: true
|
||||
root: ../
|
||||
---
|
||||
@@ -8,20 +8,17 @@ root: ../
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
Loading data from different sources using Backends
|
||||
<br />
|
||||
<small>These set of examples will show you how you can load data from different
|
||||
sources such as Google Docs or the DataHub using Recline</small>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
These set of examples will show you how you can load data from different
|
||||
sources such as Google Docs or the DataHub using Recline.
|
||||
|
||||
<div class="alert alert-info">
|
||||
<p><strong>Note</strong>: often you are loading data from a given source in
|
||||
order to display it using the various Recline views. However, you can also
|
||||
happily use this data with your own code and app and this is a very common
|
||||
use-case.</p>
|
||||
<p>Moreover, Recline is designed so you need <strong>only</strong> include the
|
||||
backend and its dependencies without needing to include any of the dependencies
|
||||
for the view portion of the Recline library.</p>
|
||||
order to load it into a Recline Dataset and display it in a View. However, you can also
|
||||
happily use a Backend to load data on its own without using any other part of the Recline library as all the Backends are designed to have no dependency on other parts of Recline.</p>
|
||||
</div>
|
||||
|
||||
## Overview
|
||||
@@ -61,7 +58,7 @@ Backend not on this list that you would like to see? It's very easy to write a n
|
||||
|
||||
## Preparing your app
|
||||
|
||||
This is as per the [quickstart](example-quickstart.html) but the set of files is much more limited if you are just using a Backend. Specifically:
|
||||
This is as per the [quickstart](tutorial-views.html) but the set of files is much more limited if you are just using a Backend. Specifically:
|
||||
|
||||
{% highlight html %}
|
||||
<!-- 3rd party dependencies -->
|
||||
|
||||
170
docs/tutorial-basics.markdown
Normal file
170
docs/tutorial-basics.markdown
Normal file
@@ -0,0 +1,170 @@
|
||||
---
|
||||
layout: container
|
||||
title: Tutorial - Dataset Basics
|
||||
recline-deps: true
|
||||
root: ../
|
||||
---
|
||||
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
Getting Started with Datasets
|
||||
<br />
|
||||
<small>This step-by-step tutorial will quickly get you started withthe central Recline object: a Dataset</small>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
## Preparations
|
||||
|
||||
1. [Download ReclineJS]({{page.root}}download.html) and relevant dependencies.
|
||||
|
||||
2. Include the core dependencies for the Dataset model
|
||||
|
||||
{% highlight html %}<!-- 3rd party dependencies -->
|
||||
<script type="text/javascript" src="vendor/jquery/1.7.1/jquery.js"></script>
|
||||
<script type="text/javascript" src="vendor/underscore/1.1.6/underscore.js"></script>
|
||||
<script type="text/javascript" src="vendor/backbone/0.5.1/backbone.js"></script>
|
||||
<!-- Recline -->
|
||||
<script type="text/javascript" src="dist/recline.js"></script>{% endhighlight %}
|
||||
|
||||
## Creating a Dataset
|
||||
|
||||
Here's the example data We are going to work with:
|
||||
|
||||
{% highlight javascript %}
|
||||
{% include data.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
In this data we have 6 records / rows. Each record is a javascript object
|
||||
containing keys and values (values can be 'simple' e.g. a string or float or arrays or hashes - e.g. the geo value here).
|
||||
|
||||
<div class="alert alert-info">In this tutorial we are creating datasets with
|
||||
"local" JS data. However, Recline has a variety of Backends that make it easy
|
||||
to create Datasets from a variety of online sources and local sources including
|
||||
Google Spreadsheets, CSV files, etc. See the <a
|
||||
href="tutorial-backends.html">Backend tutorial</a> for more.</div>
|
||||
|
||||
We can now create a recline Dataset object from this raw data:
|
||||
|
||||
{% highlight javascript %}
|
||||
var dataset = new recline.Model.Dataset({
|
||||
records: data
|
||||
});
|
||||
{% endhighlight %}
|
||||
|
||||
<script type="text/javascript">
|
||||
{% include data.js %}
|
||||
var dataset = new recline.Model.Dataset({
|
||||
records: data
|
||||
});
|
||||
</script>
|
||||
|
||||
## Records, Fields and more
|
||||
|
||||
Now that we have created a Dataset, we can use it.
|
||||
|
||||
For example, let's display some information about the Dataset and its records:
|
||||
|
||||
<div class="alert alert-info">You can find out more about Dataset and Records in the <a href="models.html">reference documentation</a></div>
|
||||
|
||||
{% highlight javascript %}
|
||||
{% include tutorial-basics-ex-1.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
Here's the output:
|
||||
|
||||
<div class="ex-1 well"> </div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('.ex-1').html('');
|
||||
{% include tutorial-basics-ex-1.js %}
|
||||
</script>
|
||||
|
||||
Note how the last geo attribute just rendered as `[object Object]`. This is because the Dataset is treating that field value as a string. Let's now take a look at the Dataset fields in more detail.
|
||||
|
||||
### Fields
|
||||
|
||||
In addition to Records, a Dataset has <a href="models.html#field">Fields</a> stored in the `fields` attribute. Fields provide information about the fields/columns in the Dataset, for example their id (key name in record), label, type etc.
|
||||
|
||||
The Dataset's fields will be automatically computed from records or provided by the backend but they can also be explicitly provided and configured. Let's take a look at the fields on the dataset at present using the following code:
|
||||
|
||||
{% highlight javascript %}
|
||||
{% include tutorial-basics-ex-fields.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
Running this results in the following:
|
||||
|
||||
<div class="ex-fields well"> </div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('.ex-fields').html('');
|
||||
{% include tutorial-basics-ex-fields.js %}
|
||||
</script>
|
||||
|
||||
As can be seen all fields have the default type of 'string'. Let's change the geo field to have type geo\_point and see what affect that has on displaying of the dataset (for good measure we'll also set the label):
|
||||
|
||||
{% highlight javascript %}
|
||||
{% include tutorial-basics-ex-fields-2.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
<div class="ex-fields-2 well"> </div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('.ex-fields-2').html('');
|
||||
{% include tutorial-basics-ex-fields-2.js %}
|
||||
</script>
|
||||
|
||||
As can be seen the rendering of the field has changed. This is because the `recordSummary` method uses the Record.getFieldValue function which in turn renders a record field using the Field's renderer function. This function varies depending on the type and can also be customized (see the <a href="models.html#field">Field documentation</a>).
|
||||
|
||||
|
||||
## Querying
|
||||
|
||||
The basic thing we want to do with Datasets is query and filter them. This is very easy to do:
|
||||
|
||||
{% highlight javascript %}
|
||||
{% include tutorial-basics-ex-2.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
This results in the following. Note how recordCount is now 3 (the total number of records matched by the query) but that currentRecords only contains 2 records as we restricted number of returned records using the size attribute.
|
||||
|
||||
<div class="ex-2 well"> </div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('.ex-2').html('');
|
||||
{% include tutorial-basics-ex-2.js %}
|
||||
</script>
|
||||
|
||||
Full details of the <a href="models.html#query">query structure and its options can be found in the reference documentation</a>.
|
||||
|
||||
Also worth noting is that the last run query is stored as a <a href="models.html#query">Query instance</a> in the `queryState` attribute of the Dataset object. Modifying `queryState` will also resulting in a query being run. This is useful when building views that want to display or manage the query state (see, for example, <a href="src/widget.queryeditor.html">Query Editor</a> or <a href="src/widget.filtereditor.html">Filter Editor</a> widgets).
|
||||
|
||||
|
||||
## Listening for Events
|
||||
|
||||
Often you'll want to listen to events on Datasets and its associated objects rather than have to explicitly notify. This is easy to do thanks to the use of Backbone model objects which have a [standard set of events](http://backbonejs.org/#FAQ-events).
|
||||
|
||||
Here's an example to illustrate:
|
||||
|
||||
{% highlight javascript %}
|
||||
{% include tutorial-basics-ex-events.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
<div class="ex-events well"> </div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('.ex-events').html('');
|
||||
{% include tutorial-basics-ex-events.js %}
|
||||
</script>
|
||||
|
||||
Here's a summary of the main objects and their events:
|
||||
|
||||
* Dataset:
|
||||
|
||||
* Standard Backbone events for changes to attributes (note that this will **not** include changes to records)
|
||||
* *query:start / query:end* called at start and completion of a query
|
||||
|
||||
* Dataset.currentRecords: Backbone.Collection of "current" records (i.e. those resulting from latest query) with standard Backbone set of events: *add, reset, remove*
|
||||
|
||||
* Dataset.queryState: queryState is a Query object with standard Backbone Model set of events
|
||||
|
||||
* Dataset.fields: Backbone Collection of Fields.
|
||||
|
||||
@@ -17,7 +17,7 @@ root: ../
|
||||
|
||||
Before writing any code with Recline, you need to do the following preparation steps on your page:
|
||||
|
||||
1. [Download ReclineJS](download.html) and relevant dependencies.
|
||||
1. [Download ReclineJS]({{page.root}}download.html) and relevant dependencies.
|
||||
2. Include the relevant CSS in the head section of your document:
|
||||
{% highlight html %}
|
||||
<!-- you do not have to use bootstrap but we use it by default -->
|
||||
@@ -34,7 +34,6 @@ Before writing any code with Recline, you need to do the following preparation s
|
||||
<script type="text/javascript" src="vendor/bootstrap/2.0.2/bootstrap.js"></script>
|
||||
<!-- note that we could include individual components rather than whole of recline e.g.
|
||||
<script type="text/javascript" src="src/model.js"></script>
|
||||
<script type="text/javascript" src="src/backend/base.js"></script>
|
||||
<script type="text/javascript" src="src/backend/memory.js"></script>
|
||||
<script type="text/javascript" src="src/view-grid.js"></script>
|
||||
-->
|
||||
|
||||
Reference in New Issue
Block a user