Langsung ke konten utama

Postingan

Menampilkan postingan dengan label html

HTML Table

An HTML table is defined with the  <table>  tag. Each table row is defined with the  <tr>  tag. A table header is defined with the  <th>  tag. By default, table headings are bold and centered. A table data/cell is defined with the  <td>  tag. < table  style ="width:100%" >    < tr >      < th > Firstname < /th >      < th > Lastname < /th >        < th > Age < /th >    < /tr >    < tr >      < td > Jill < /td >      < td > Smith < /td >        < td > 50 < /td >    < /tr >    < tr >      < td > Eve < /td >      < td > Jackson < /td >        < td...

Delete indexeddb data by index

var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB; var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || { READ_WRITE: "readwrite" };; var db; var transaction, objectStore; var request = indexedDB.open("IndexedDBname", 1);         request.onsuccess = function (evt) {        db = request.result;  var deleteindex = db.transaction(["indexdbtable"], "readwrite") .objectStore("indexdbtable")                 .delete(1); // example if you want to delete index no 1 deleteindex.onsuccess = function(event) { console.log("index 1 deleted" + "indexdbtable");  // log };  };

Function to delete Indexeddb Object(table)

var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB; var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || { READ_WRITE: "readwrite" };; var db; var transaction, objectStore; // "IndexDB" is your indexed db name (database) var request = indexedDB.open("IndexDB", 1);         request.onsuccess = function (evt) {         db = request.result; //"indexobject" is your indexdb object (table) transaction = db.transaction("indexobject", "readwrite"); objectStore = transaction.objectStore("indexobject");   // clear all the data out of the object store var objectStoreRequest = objectStore.clear(); objectStoreRequest.onsuccess = function(event) {     // report the success of our clear operation console.log('clear '+"indexobject"); }; };

IndexedDB Fuzzy Search

This is how to create  key range between the search term and the search term with a 'z' letter at the final. db . transaction ([ 'table' ], 'readonly' ) . objectStore ( 'table' ) . openCursor ( IDBKeyRange . bound ( searchTerm , searchTerm + '\uffff' ), // The important part, thank Velmont to point out 'prev' ) . onsuccess = function ( e ) { e || ( e = event ); var cursor = e . target . result ; if ( cursor ) { // console.log(cursor.value.column1 + ' = ' + cursor.value.column2); cursor . continue (); } }; If you need to order the result, so I defined a array before the transaction, then we call it when we loaded all data, like this: var result = []; db . transaction ([ 'table' ], 'readonly' ) . objectStore ( 'table' ) . openCursor ( IDBKeyRange . bound ( searchTerm , searchTerm + '\uffff' ), // The important ...

Use HTML5 IndexedDB cursors to update existing records

The  HTML5   IndexedDB  is still in the working draft stage and not fully implemented in major Internet browsers yet. Nevertheless, I tried to use its asynchronous API to develop a  Google Maps  application. It took me a little while to figure out how to update an existing record in the IndexedDB  database store. This can be done by opening a read-write cursor to the record to be updated. Then call the cursor  update  method to replace it with the new record. An example Javascript code snippet is shown below. try { var objDb; //the database to update var store = 'myStore' ; //the database store to update var key = 88; //the key of the existing record to update var newRec = 'hello world' ; //the new record var objStore = null ; var objTrans = null ; var objCursor = null ; var objKeyRange = null ;   //...etc...open the database....etc... //open a read-write transaction objTrans = objDb.transaction(store,...