Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 917229 of IDBLocaleAwareKeyRange

  • Revision slug: Web/API/IDBLocaleAwareKeyRange
  • Revision title: IDBLocaleAwareKeyRange
  • Revision id: 917229
  • Created:
  • Creator: chrisdavidmills
  • Is current revision? No
  • Comment

Revision Content

{{APIRef("IndexedDB")}}{{ SeeCompatTable() }}

The IDBLocaleAwareKeyRange interface of the IndexedDB API is a Firefox-specific version of {{domxref("IDBKeyRange")}} — it functions in exactly the same fashion, and has the same properties and methods, but it is intended for use with {{domxref("IDBIndex")}} objects when the original index had a locale value specified upon its creation (see createIndex()'s optionalParameters) — that is, it has locale aware sorting enabled.

Methods

This interface inherits all the methods of it's parent interface, {{domxref("IDBKeyRange")}}.

Properties

This interface inherits all the properties of it's parent interface, {{domxref("IDBKeyRange")}}.

Bear in mind however that IDBLocaleAwareKeyRange has its own implementation of {{domxref("IDBKeyRange.bound")}}. This is because when you use bound(), it checks if lower bound < upper bound, and throws an exception if that’s not the case. With locale-aware indexes, the meaning of < depends on the locale, so for example in Lithuanian Y is sorted between I and K. The only difference between IDBKeyRange and IDBLocaleAwareKeyRange is that the latter doesn’t do the aforementioned check.

Authors should always use IDBLocaleAwareKeyRange when dealing with locale-aware indexes.

Examples

function displayData() {
  var keyRangeValue = IDBLocaleAwareKeyRange.bound("A", "F");

  var transaction = db.transaction(['fThings'], 'readonly');
  var objectStore = transaction.objectStore('fThings');

  var myIndex = objectStore.index('lName');
  myIndex.openCursor(keyRangeValue).onsuccess = function(event) {
    var cursor = event.target.result;
    if(cursor) {
      var tableRow = document.createElement('tr');
      tableRow.innerHTML =   '&lt;td&gt;' + cursor.value.id + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.lName + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.fName + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.jTitle + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.company + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.eMail + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.phone + '&lt;/td&gt;'
                           + '&lt;td&gt;' + cursor.value.age + '&lt;/td&gt;';
      tableEntry.appendChild(tableRow);  

      cursor.continue();
    } else {
      console.log('Entries all displayed.');    
    }
  };
};

Specifications

Not currently part of any specification.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatNo}} {{CompatGeckoDesktop("43.0")}}[1] {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatGeckoMobile("43.0")}}[1] 2.5[1] {{CompatNo}} {{CompatNo}} {{CompatNo}}

[1]: This feature is currently hidden behind a flag — to enable it and experiment, go to about:config and enable dom.indexedDB.experimental.

See also

  • Using IndexedDB
  • Starting transactions: {{domxref("IDBDatabase")}}
  • Using transactions: {{domxref("IDBTransaction")}}
  • Setting a range of keys: {{domxref("IDBKeyRange")}}
  • Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}
  • Using cursors: {{domxref("IDBCursor")}}
  • Reference example: To-do Notifications (view example live.)

Revision Source

<p>{{APIRef("IndexedDB")}}{{ SeeCompatTable() }}</p>

<div>
<p>The <strong><code>IDBLocaleAwareKeyRange</code></strong> interface of the <a href="/en/IndexedDB" title="en/IndexedDB">IndexedDB API</a> is a Firefox-specific version of {{domxref("IDBKeyRange")}} — it functions in exactly the same fashion, and has the same properties and methods, but it is intended for use with {{domxref("IDBIndex")}} objects when the original index had a <code>locale</code> value specified upon its creation (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#Parameters"><code>createIndex()</code>'s optionalParameters</a>) — that is, it has <a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#Locale-aware_sorting">locale aware sorting</a> enabled.</p>
</div>

<h2 id="Methods">Methods</h2>

<p><em>This interface inherits all the methods of it's parent interface, {{domxref("IDBKeyRange")}}.</em></p>

<h2 id="Properties">Properties</h2>

<p><em>This interface inherits all the properties of it's parent interface, {{domxref("IDBKeyRange")}}.</em></p>

<p>Bear in mind however that <code>IDBLocaleAwareKeyRange</code> has its own implementation of {{domxref("IDBKeyRange.bound")}}. This is because when you use <code>bound()</code>, it checks if lower bound &lt; upper bound, and throws an exception if that’s not the case. With locale-aware indexes, the meaning of &lt; depends on the locale, so for example in Lithuanian Y is sorted between I and K. The only difference between <code>IDBKeyRange</code> and <code>IDBLocaleAwareKeyRange</code> is that the latter doesn’t do the aforementioned check.</p>

<p>Authors should always use <code>IDBLocaleAwareKeyRange</code> when dealing with locale-aware indexes.</p>

<h2 id="Examples">Examples</h2>

<pre class="brush: js">
function displayData() {
  var keyRangeValue = IDBLocaleAwareKeyRange.bound("A", "F");

  var transaction = db.transaction(['fThings'], 'readonly');
  var objectStore = transaction.objectStore('fThings');

  var myIndex = objectStore.index('lName');
  myIndex.openCursor(keyRangeValue).onsuccess = function(event) {
    var cursor = event.target.result;
    if(cursor) {
      var tableRow = document.createElement('tr');
      tableRow.innerHTML =   '&amp;lt;td&amp;gt;' + cursor.value.id + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.lName + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.fName + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.jTitle + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.company + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.eMail + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.phone + '&amp;lt;/td&amp;gt;'
                           + '&amp;lt;td&amp;gt;' + cursor.value.age + '&amp;lt;/td&amp;gt;';
      tableEntry.appendChild(tableRow);  

      cursor.continue();
    } else {
      console.log('Entries all displayed.');    
    }
  };
};</pre>

<h2 id="Specifications">Specifications</h2>

<p>Not currently part of any specification.</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("43.0")}}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("43.0")}}<sup>[1]</sup></td>
   <td>2.5<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p><strong>[1]</strong>: This feature is currently hidden behind a flag — to enable it and experiment, go to <a href="about:config">about:config</a> and enable <code>dom.indexedDB.experimental</code>.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li>
 <li>Starting transactions: {{domxref("IDBDatabase")}}</li>
 <li>Using transactions: {{domxref("IDBTransaction")}}</li>
 <li>Setting a range of keys: {{domxref("IDBKeyRange")}}</li>
 <li>Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}</li>
 <li>Using cursors: {{domxref("IDBCursor")}}</li>
 <li>Reference example: <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="https://mdn.github.io/to-do-notifications/">view example live</a>.)</li>
</ul>
Revert to this revision