IDBLocaleAwareKeyRange

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

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

Instance methods

This interface inherits all the methods of its parent interface, IDBKeyRange.

Instance properties

This interface inherits all the properties of its parent interface, IDBKeyRange.

Bear in mind however that IDBLocaleAwareKeyRange has its own implementation of 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.

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

Examples

js

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

  const transaction = db.transaction(["fThings"], "readonly");
  const objectStore = transaction.objectStore("fThings");

  const myIndex = objectStore.index("lName");
  myIndex.openCursor(keyRangeValue).onsuccess = (event) => {
    const cursor = event.target.result;
    if (cursor) {
      const tableRow = document.createElement("tr");
      tableRow.innerHTML =
        `<td>${cursor.value.id}</td>` +
        `<td>${cursor.value.lName}</td>` +
        `<td>${cursor.value.fName}</td>` +
        `<td>${cursor.value.jTitle}</td>` +
        `<td>${cursor.value.company}</td>` +
        `<td>${cursor.value.eMail}</td>` +
        `<td>${cursor.value.phone}</td>` +
        `<td>${cursor.value.age}</td>`;
      tableEntry.appendChild(tableRow);

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

Specifications

Not currently part of any specification.

Browser compatibility

BCD tables only load in the browser

See also