📄 dataview.js
字号:
startIndex = startIndex || 0;
endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
for(var i = startIndex; i <= endIndex; i++){
ns[i].viewIndex = i;
}
},
/**
* Returns the store associated with this DataView.
* @return {Ext.data.Store} The store
*/
getStore : function(){
return this.store;
},
/**
* Changes the data store bound to this view and refreshes it.
* @param {Store} store The store to bind to this view
*/
setStore : function(store, initial){
if(!initial && this.store){
this.store.un("beforeload", this.onBeforeLoad, this);
this.store.un("datachanged", this.refresh, this);
this.store.un("add", this.onAdd, this);
this.store.un("remove", this.onRemove, this);
this.store.un("update", this.onUpdate, this);
this.store.un("clear", this.refresh, this);
}
if(store){
store = Ext.StoreMgr.lookup(store);
store.on("beforeload", this.onBeforeLoad, this);
store.on("datachanged", this.refresh, this);
store.on("add", this.onAdd, this);
store.on("remove", this.onRemove, this);
store.on("update", this.onUpdate, this);
store.on("clear", this.refresh, this);
}
this.store = store;
if(store){
this.refresh();
}
},
/**
* Returns the template node the passed child belongs to, or null if it doesn't belong to one.
* @param {HTMLElement} node
* @return {HTMLElement} The template node
*/
findItemFromChild : function(node){
return Ext.fly(node).findParent(this.itemSelector, this.el);
},
// private
onClick : function(e){
var item = e.getTarget(this.itemSelector, this.el);
if(item){
var index = this.indexOf(item);
if(this.onItemClick(item, index, e) !== false){
this.fireEvent("click", this, index, item, e);
}
}else{
if(this.fireEvent("containerclick", this, e) !== false){
this.clearSelections();
}
}
},
// private
onContextMenu : function(e){
var item = e.getTarget(this.itemSelector, this.el);
if(item){
this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
}
},
// private
onDblClick : function(e){
var item = e.getTarget(this.itemSelector, this.el);
if(item){
this.fireEvent("dblclick", this, this.indexOf(item), item, e);
}
},
// private
onMouseOver : function(e){
var item = e.getTarget(this.itemSelector, this.el);
if(item && item !== this.lastItem){
this.lastItem = item;
Ext.fly(item).addClass(this.overClass);
this.fireEvent("mouseenter", this, this.indexOf(item), item, e);
}
},
// private
onMouseOut : function(e){
if(this.lastItem){
if(!e.within(this.lastItem, true, true)){
Ext.fly(this.lastItem).removeClass(this.overClass);
this.fireEvent("mouseleave", this, this.indexOf(this.lastItem), this.lastItem, e);
delete this.lastItem;
}
}
},
// private
onItemClick : function(item, index, e){
if(this.fireEvent("beforeclick", this, index, item, e) === false){
return false;
}
if(this.multiSelect){
this.doMultiSelection(item, index, e);
e.preventDefault();
}else if(this.singleSelect){
this.doSingleSelection(item, index, e);
e.preventDefault();
}
return true;
},
// private
doSingleSelection : function(item, index, e){
if(e.ctrlKey && this.isSelected(index)){
this.deselect(index);
}else{
this.select(index, false);
}
},
// private
doMultiSelection : function(item, index, e){
if(e.shiftKey && this.last !== false){
var last = this.last;
this.selectRange(last, index, e.ctrlKey);
this.last = last; // reset the last
}else{
if((e.ctrlKey||this.simpleSelect) && this.isSelected(index)){
this.deselect(index);
}else{
this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect);
}
}
},
/**
* Gets the number of selected nodes.
* @return {Number} The node count
*/
getSelectionCount : function(){
return this.selected.getCount()
},
/**
* Gets the currently selected nodes.
* @return {Array} An array of HTMLElements
*/
getSelectedNodes : function(){
return this.selected.elements;
},
/**
* Gets the indexes of the selected nodes.
* @return {Array} An array of numeric indexes
*/
getSelectedIndexes : function(){
var indexes = [], s = this.selected.elements;
for(var i = 0, len = s.length; i < len; i++){
indexes.push(s[i].viewIndex);
}
return indexes;
},
/**
* Gets an array of the selected records
* @return {Array} An array of {@link Ext.data.Record} objects
*/
getSelectedRecords : function(){
var r = [], s = this.selected.elements;
for(var i = 0, len = s.length; i < len; i++){
r[r.length] = this.store.getAt(s[i].viewIndex);
}
return r;
},
/**
* Gets an array of the records from an array of nodes
* @param {Array} nodes The nodes to evaluate
* @return {Array} records The {@link Ext.data.Record} objects
*/
getRecords : function(nodes){
var r = [], s = nodes;
for(var i = 0, len = s.length; i < len; i++){
r[r.length] = this.store.getAt(s[i].viewIndex);
}
return r;
},
/**
* Gets a record from a node
* @param {HTMLElement} node The node to evaluate
* @return {Record} record The {@link Ext.data.Record} object
*/
getRecord : function(node){
return this.store.getAt(node.viewIndex);
},
/**
* Clears all selections.
* @param {Boolean} suppressEvent (optional) True to skip firing of the selectionchange event
*/
clearSelections : function(suppressEvent, skipUpdate){
if((this.multiSelect || this.singleSelect) && this.selected.getCount() > 0){
if(!skipUpdate){
this.selected.removeClass(this.selectedClass);
}
this.selected.clear();
this.last = false;
if(!suppressEvent){
this.fireEvent("selectionchange", this, this.selected.elements);
}
}
},
/**
* Returns true if the passed node is selected, else false.
* @param {HTMLElement/Number} node The node or node index to check
* @return {Boolean} True if selected, else false
*/
isSelected : function(node){
return this.selected.contains(this.getNode(node));
},
/**
* Deselects a node.
* @param {HTMLElement/Number} node The node to deselect
*/
deselect : function(node){
if(this.isSelected(node)){
node = this.getNode(node);
this.selected.removeElement(node);
if(this.last == node.viewIndex){
this.last = false;
}
Ext.fly(node).removeClass(this.selectedClass);
this.fireEvent("selectionchange", this, this.selected.elements);
}
},
/**
* Selects a set of nodes.
* @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node,
* id of a template node or an array of any of those to select
* @param {Boolean} keepExisting (optional) true to keep existing selections
* @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
*/
select : function(nodeInfo, keepExisting, suppressEvent){
if(Ext.isArray(nodeInfo)){
if(!keepExisting){
this.clearSelections(true);
}
for(var i = 0, len = nodeInfo.length; i < len; i++){
this.select(nodeInfo[i], true, true);
}
if(!suppressEvent){
this.fireEvent("selectionchange", this, this.selected.elements);
}
} else{
var node = this.getNode(nodeInfo);
if(!keepExisting){
this.clearSelections(true);
}
if(node && !this.isSelected(node)){
if(this.fireEvent("beforeselect", this, node, this.selected.elements) !== false){
Ext.fly(node).addClass(this.selectedClass);
this.selected.add(node);
this.last = node.viewIndex;
if(!suppressEvent){
this.fireEvent("selectionchange", this, this.selected.elements);
}
}
}
}
},
/**
* Selects a range of nodes. All nodes between start and end are selected.
* @param {Number} start The index of the first node in the range
* @param {Number} end The index of the last node in the range
* @param {Boolean} keepExisting (optional) True to retain existing selections
*/
selectRange : function(start, end, keepExisting){
if(!keepExisting){
this.clearSelections(true);
}
this.select(this.getNodes(start, end), true);
},
/**
* Gets a template node.
* @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
* @return {HTMLElement} The node or null if it wasn't found
*/
getNode : function(nodeInfo){
if(typeof nodeInfo == "string"){
return document.getElementById(nodeInfo);
}else if(typeof nodeInfo == "number"){
return this.all.elements[nodeInfo];
}
return nodeInfo;
},
/**
* Gets a range nodes.
* @param {Number} start (optional) The index of the first node in the range
* @param {Number} end (optional) The index of the last node in the range
* @return {Array} An array of nodes
*/
getNodes : function(start, end){
var ns = this.all.elements;
start = start || 0;
end = typeof end == "undefined" ? Math.max(ns.length - 1, 0) : end;
var nodes = [], i;
if(start <= end){
for(i = start; i <= end && ns[i]; i++){
nodes.push(ns[i]);
}
} else{
for(i = start; i >= end && ns[i]; i--){
nodes.push(ns[i]);
}
}
return nodes;
},
/**
* Finds the index of the passed node.
* @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
* @return {Number} The index of the node or -1
*/
indexOf : function(node){
node = this.getNode(node);
if(typeof node.viewIndex == "number"){
return node.viewIndex;
}
return this.all.indexOf(node);
},
// private
onBeforeLoad : function(){
if(this.loadingText){
this.clearSelections(false, true);
this.el.update('<div class="loading-indicator">'+this.loadingText+'</div>');
this.all.clear();
}
},
onDestroy : function(){
Ext.DataView.superclass.onDestroy.call(this);
this.setStore(null);
}
});
Ext.reg('dataview', Ext.DataView);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -