The Webix library allows using Webix components with FireBase.
The sources for integration of Webix with FireBase are not included into the Webix library package. You can take them from the GitHub repository
According to the Firebase site:
When data change, apps built with Firebase update instantly across every device - web or mobile.
Firebase-powered apps work offline. Data are synchronized instantly when your app regains connectivity.
<!-- Webix -->
<script type="text/javascript" src="http://cdn.webix.com/edge/webix.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.webix.com/edge/webix.css">
<!-- Webix-Firebase adapter -->
<script type="text/javascript" src="../codebase/webix-firebase.js"></script>
<!-- FireBase -->
<script src="https://www.gstatic.com/firebasejs/3.6.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.2/firebase-database.js"></script>
firebase.initializeApp({
databaseURL: "https://webix-demo.firebaseio.com/"
});
// create FireBase connection, and assign it to Webix
webix.firebase = firebase.database();
Use firebase->{reference} as data URL
webix.ui({
id:"dtable",
view:"datatable",
editable:true, editaction:"dblclick",
columns:[{
id:"name", editor:"text", fillspace:1
},{
id:"author", editor:"text", fillspace:1
}],
//load data from /books
url: "firebase->books",
//save data to /books
save:"firebase->books"
})
Adding the "url" property will enable data loading and automatic updates of component when data change in the FireBase.
Adding the "save" property ensures that all changes in the datatable will be saved to the Firebase.
Instead of using text URL, you can use FireBase references directly:
firebase.initializeApp({
databaseURL: "https://webix-demo.firebaseio.com/"
});
var db = firebase.database();
var proxy = webix.proxy("firebase", db.ref("books"));
webix.ui({
view:"list",
url: proxy,
save: proxy
})
You can use the "load" command to (re)load data in the component.
$$("dtable").load("firebase->books");
or
$$("dtable").load( webix.proxy("firebase", ref));
Webix components have native sync API to sync data between components. The same API can be used with FireBase:
firebase.initializeApp({
databaseURL: "https://webix-demo.firebaseio.com/"
});
webix.firebase = firebase.database();
var ref = webix.firebase.ref("books");
$$("dtable").sync(ref);
Similar to data views, you can use the "load" and "save" API while working with Forms:
//form
$$("form").load("books/4");
...
$$("form").save();
//template
$$("template").load("books/4")
In some cases, it makes sense not to load data directly, but to bind form (template) to some other view or data collection:
var data = new webix.DataCollection({
url:"firebase->books",
save:"firebase->books"
})
form.bind(data);
data.waitData.then(function(){
//you need to use setCursor API to load some record from collection into a form
data.setCursor("4");
})
or, the same for the datatable:
webix.ui({
view:"datatable", autoConfig:true, id:"d1", select:true,
url:"firebase->books",
save:"firebase->books"
});
form.bind("d1"); //selected row will be shown in a form
You can find more samples on GitHub
Back to top