A
A
Alexander Kirsanov2019-04-15 13:40:21
JavaScript
Alexander Kirsanov, 2019-04-15 13:40:21

Is it possible to combine scripts for IndexedDB with w2ui table?

To create a distributed network client layout, my eye fell on:
- w2ui library (minimalism, almost all the necessary widgets with customized actions).
- NW.JS works for "desktopization". There are no questions other than the size of the final assembly.
- For assembly and testing, I was pleased with the NW.JS IDE.
- For storage - built-in IndexedDB.
The current question is how to make friends the script for writing data to the database with the script creating the grid?
Table script. In the library demo, the question of how to read the database is somehow not disclosed.

<script type="text/javascript">
$(function () {
    $('#grid').w2grid({ 
        name: 'grid', 
        method: 'GET', // need this to avoid 412 error on Safari
        columns: [                
            { field: 'pub-biblioid', caption: 'pub-biblioid', size: '30%', sortable: true },
            { field: 'pub-title', caption: 'pub-title', size: '30%', sortable: true },
        ]
    });    
    w2ui['grid'].load('data/list.json');
});
</script>

Data is written from body
<tr><td><label for="pub-biblioid" class="required">ID:<br/><span class="note">(Обязательное уникальное значение)</span></label></td><td>
<input type="text" id="pub-biblioid" name="pub-biblioid"/></td></tr>

<tr><td> <label for="pub-title" class="required">Фамилия</label></td> <td>
<input type="text" id="pub-title" name="pub-title" /></td> </tr>

The script for writing and reading is large, you probably don’t need to give the whole one. The fact that it works can be seen from F12 and in its own table. But to embed data in a grid with search, sorting and other things does not work. Help.
<script>
                (function () {
  var COMPAT_ENVS = [
    ['Firefox', ">= 16.0"],
    ['Google Chrome',
     ">= 24.0 (you may need to get Google Chrome Canary), NO Blob storage support"]
  ];
  var compat = $('#compat');
  compat.empty();
  compat.append('<ul id="compat-list"></ul>');
  COMPAT_ENVS.forEach(function(val, idx, array) {
    $('#compat-list').append('<li>' + val[0] + ': ' + val[1] + '</li>');
  });

  const DB_NAME = 'LKI DB DEMO';
  const DB_VERSION = 1; // Use a long long for this value (don't use a float)
  const DB_STORE_NAME = 'publications';

  var db;

  // Used to keep track of which view is displayed to avoid to uselessly reload it
  var current_view_pub_key;

  function openDb() {
    console.log("openDb ...");
    var req = indexedDB.open(DB_NAME, DB_VERSION);
    req.onsuccess = function (evt) {
      // Better use "this" than "req" to get the result to avoid problems with
      // garbage collection.
      // db = req.result;
      db = this.result;
      console.log("openDb DONE");
    };
    req.onerror = function (evt) {
      console.error("openDb:", evt.target.errorCode);
    };

    req.onupgradeneeded = function (evt) {
     console.log("openDb.onupgradeneeded");
     var thisDB = evt.target.result;
     if (!thisDB.objectStoreNames.contains(DB_STORE_NAME)) {
      var store = thisDB.createObjectStore(
          DB_STORE_NAME, { keyPath: 'id', autoIncrement: true });
  
        store.createIndex('biblioid', 'biblioid', { unique: false  });
        store.createIndex('title', 'title', { unique: false });
        store.createIndex('year', 'year', { unique: false });
      }
    };
  }

I would be glad if anyone can advise or is ready to partner in JS and cryptography issues on a long-term basis with a corresponding interest.
For everyone else - knock, you might get an alternative to crypto, fiat and EDO.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question