How to query a local websql DB with Kendo UI

两盒软妹~` 提交于 2019-12-02 23:50:53

You can create a custom transport for the Kendo DataSource. For example in transport.read you can perform a query to your websql database and return the result:

var dataSource = new kendo.data.DataSource({
   transport: {
      read: function(options) {

        db.transaction(function(tx) {

          tx.executeSql('SELECT * from my_table', [], function(tx, result) {

             var data = [];
             // copy the rows to a regular array
             for (var i = 0; i < result.rows.length; i++) {
                data[i] = result.rows.item(i);
             }

             options.success(data); // return the data back to the data source
          });
        });
      }
   }
});

Here is a full CRUD demo: http://jsbin.com/azukin/4/edit

With JayData you can do it with just a few lines of code and it will support not only websql but indexeddb too http://jaydata.org/blog/jaydata-kendo-ui-awesomeness

You can also use PouchDB, that can store data in WebSQL. There is kendo-pouchdb adapter that connects PouchDB database with Kendo UI or Kendo Mobile widgets.

Here's demo of Kendo Grid that read and updates data in PouchDB.

P.S. I'm the author of kendo-pouchdb.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!