CollectionBind¶
-
class
webix.
CollectionBind
()¶ Collectionbind mixin
Referenced by¶
- mixins
BindSource()
.- components
DataCollection()
.
External references¶
Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | webix.CollectionBind={
$init:function(){
this._cursor = null;
this.attachEvent("onSelectChange", function(data){
var sel = this.getSelectedId();
this.setCursor(sel?(sel.id||sel):null);
});
this.attachEvent("onAfterCursorChange", this._update_binds);
this.attachEvent("onAfterDelete", function(id){
if (id == this.getCursor())
this.setCursor(null);
});
this.data.attachEvent("onStoreUpdated", webix.bind(function(id, data, mode){
//paint - ignored
//delete - handled by onAfterDelete above
if (id && id == this.getCursor() && mode != "paint" && mode != "delete")
this._update_binds();
},this));
this.data.attachEvent("onClearAll", webix.bind(function(){
this._cursor = null;
},this));
this.data.attachEvent("onIdChange", webix.bind(function(oldid, newid){
if (this._cursor == oldid){
this._cursor = newid;
this._update_binds();
}
},this));
},
refreshCursor:function(){
if (this._cursor)
this.callEvent("onAfterCursorChange",[this._cursor]);
},
setCursor:function(id){
if (id == this._cursor || (id !== null && !this.getItem(id))) return;
this.callEvent("onBeforeCursorChange", [this._cursor]);
this._cursor = id;
this.callEvent("onAfterCursorChange",[id]);
},
getCursor:function(){
return this._cursor;
},
_bind_update:function(target, rule, format){
if (rule == "$level" && this.data.getBranch)
return (target.data || target).importData(this.data.getBranch(this.getCursor()));
var data = this.getItem(this.getCursor())|| this._settings.defaultData || null;
if (rule == "$data"){
if (typeof format === "function")
format.call(target, data, this);
else
target.data.importData(data?data[format]:[]);
target.callEvent("onBindApply", [data,rule,this]);
} else {
if (format)
data = format(data);
this._bind_update_common(target, rule, data);
}
}
};
/*
REnders single item.
Can be used for elements without datastore, or with complex custom rendering logic
@export
render
*/
|