ExtJs5.1多选下拉框CheckComb
ExtJs这么多个版本号了。可就是不提供多选下拉框,老外不用这个玩意吗?
5都出来这么久了,新写的项目就用5吧,把曾经Extjs4.2的时搜到前人的CheckComb改巴改巴。能用了就赶紧贴上来,没有细致測试各种情况。
Ext.define('Ext.ux.CheckCombo', {
extend : 'Ext.form.field.ComboBox',
alias : 'widget.checkcombo',
multiSelect : true,
allSelector : false,
noData : true,
noDataText : 'No combo data',
addAllSelector : false,
allSelectorHidden : false,
enableKeyEvents : true,
afterExpandCheck : false,
allText : 'All',
oldValue : '',
listeners : {
/*
* uncomment if you want to reload store on every combo expand
* beforequery: function(qe) { this.store.removeAll(); delete
* qe.combo.lastQuery; },
*/
focus : function(cpt) {
cpt.oldValue = cpt.getValue();
}
},
createPicker : function() {
var me = this, picker, menuCls = Ext.baseCSSPrefix + 'menu', opts = Ext
.apply({
pickerField : me,
selectionModel : me.pickerSelectionModel,
floating : true,
hidden : true,
ownerCt : me.ownerCt,
cls : me.el.up('.' + menuCls) ? menuCls : '',
store : me.getPickerStore(),
displayField : me.displayField,
preserveScrollOnRefresh : true,
pageSize : me.pageSize,
tpl : [
'<tpl for=".">',
'<div class="x-boundlist-item" role="option"><span class="x-combo-checker"> </span> {'
+ me.displayField + '}</div>', '</tpl>']
}, me.listConfig, me.defaultListConfig); picker = me.picker = Ext.create('Ext.view.BoundList', opts);
if (me.pageSize) {
picker.pagingToolbar.on('beforechange', me.onPageChange, me);
} // We limit the height of the picker to fit in the space above
// or below this field unless the picker has its own ideas about that.
if (!picker.initialConfig.maxHeight) {
picker.on({
beforeshow : me.onBeforePickerShow,
scope : me
});
}
picker.getSelectionModel().on({
beforeselect : me.onBeforeSelect,
beforedeselect : me.onBeforeDeselect,
scope : me
}); picker.getNavigationModel().navigateOnSpace = false; me.store.on('load', function(store) {
if (store.getTotalCount() == 0) {
me.allSelectorHidden = true;
if (me.allSelector != false)
me.allSelector.setStyle('display', 'none');
if (me.noData != false)
me.noData.setStyle('display', 'block');
} else {
me.allSelectorHidden = false;
if (me.allSelector != false)
me.allSelector.setStyle('display', 'block');
if (me.noData != false)
me.noData.setStyle('display', 'none');
}
});
return picker;
},
reset : function() {
var me = this; me.setValue('');
},
setValue : function(value) {
this.value = value;
if (!value) {
if (this.allSelector != false)
this.allSelector.removeCls('x-boundlist-selected');
return this.callParent(arguments);
} if (typeof value == 'string') {
var me = this, records = [], vals = value.split(','); if (value == '') {
if (me.allSelector != false)
me.allSelector.removeCls('x-boundlist-selected');
} else {
if (vals.length == me.store.getCount() && vals.length != 0) {
if (me.allSelector != false)
me.allSelector.addCls('x-boundlist-selected');
else
me.afterExpandCheck = true;
}
} Ext.each(vals, function(val) {
var record = me.store.getById(parseInt(val));
if (record)
records.push(record);
}); return me.setValue(records);
} else
return this.callParent(arguments);
},
getValue : function() {
if (typeof this.value == 'object')
return this.value.join(',');
else
return this.value;
},
getSubmitValue : function() {
return this.getValue();
},
expand : function() {
var me = this, bodyEl, picker, doc, collapseIf; if (me.rendered && !me.isExpanded && !me.isDestroyed) {
bodyEl = me.bodyEl;
picker = me.getPicker();
doc = Ext.getDoc();
collapseIf = me.collapseIf;
picker.setMaxHeight(picker.initialConfig.maxHeight); if (me.matchFieldWidth) {
picker.width = me.bodyEl.getWidth();
} // Show the picker and set isExpanded flag. alignPicker only works
// if isExpanded.
picker.show();
me.isExpanded = true;
me.alignPicker();
bodyEl.addCls(me.openCls);
if (me.noData == false)
me.noData = picker.getEl().down('.x-boundlist-list-ct')
.insertHtml(
'beforeBegin',
'<div class="x-boundlist-item" role="option">'
+ me.noDataText + '</div>', true);
if (me.addAllSelector == true && me.allSelector == false) {
me.allSelector = picker
.getEl()
.down('.x-boundlist-list-ct')
.insertHtml(
'beforeBegin',
'<div class="x-boundlist-item" role="option"><span class="x-combo-checker"> </span> '
+ me.allText + '</div>', true);
me.allSelector.on('click', function(e) {
if (me.allSelector.hasCls('x-boundlist-selected')) {
me.allSelector
.removeCls('x-boundlist-selected');
me.setValue('');
me.fireEvent('select', me, []);
} else {
var records = [];
me.store.each(function(record) {
records.push(record);
});
me.allSelector.addCls('x-boundlist-selected');
me.select(records);
me.fireEvent('select', me, records);
}
}); if (me.allSelectorHidden == true)
me.allSelector.hide();
else
me.allSelector.show(); if (me.afterExpandCheck == true) {
me.allSelector.addCls('x-boundlist-selected');
me.afterExpandCheck = false;
}
} // Collapse on touch outside this component tree.
// Because touch platforms do not focus document.body on touch
// so no focusleave would occur to trigger a collapse.
me.touchListeners = doc.on({
// Do not translate on non-touch platforms.
// mousedown will blur the field.
translate : false,
touchstart : me.collapseIf,
scope : me,
delegated : false,
destroyable : true
}); // Scrolling of anything which causes this field to move should
// collapse
me.scrollListeners = Ext.on({
scroll : me.onGlobalScroll,
scope : me,
destroyable : true
}); // monitor touch and mousewheel
me.hideListeners = doc.on({
mousewheel : me.collapseIf,
touchstart : me.collapseIf,
scope : me,
delegated : false,
destroyable : true
}); // Buffer is used to allow any layouts to complete before we align
Ext.on('resize', me.alignPicker, me, {
buffer : 1
});
me.fireEvent('expand', me);
me.onExpand();
} else {
me.fireEvent('expand', me);
me.onExpand();
}
},
onListSelectionChange : function(list, selectedRecords) {
var me = this, isMulti = me.multiSelect, hasRecords = selectedRecords.length > 0;
// Only react to selection if it is not called from setValue, and if our
// list is
// expanded (ignores changes to the selection model triggered elsewhere)
if (!me.ignoreSelection && me.isExpanded) {
if (!isMulti) {
Ext.defer(me.collapse, 1, me);
}
/*
* Only set the value here if we're in multi selection mode or we
* have a selection. Otherwise setValue will be called with an empty
* value which will cause the change event to fire twice.
*/
if (isMulti || hasRecords) {
me.setValue(selectedRecords, false);
}
if (hasRecords) {
me.fireEvent('select', me, selectedRecords);
}
me.inputEl.focus(); if (me.addAllSelector == true && me.allSelector != false) {
if (selectedRecords.length == me.store.getTotalCount())
me.allSelector.addCls('x-boundlist-selected');
else
me.allSelector.removeCls('x-boundlist-selected');
}
}
}
});
还有相关的css啊,图片就自己找吧。我是把4里面的图片copy过来的:
/*ext多选下拉框样式,未选*/
.x-combo-checker {
background-position: 50% -2px;
margin-left: 1px;
background-color: transparent;
background-image:url(../thirdjs/extjs513/ext-theme-classic/images/unchecked.gif);
background-position: -1px -1px;
background-repeat: no-repeat;
height: 14px;
width: 14px;
display: inline-block;
} /*ext多选下拉框样式,已选*/
.x-boundlist-selected .x-combo-checker {
background-image:url(../thirdjs/extjs513/ext-theme-classic/images/checked.gif);
}
ExtJs5.1多选下拉框CheckComb的更多相关文章
- Easyui-Combobox多选下拉框
因为工作需要,引入combobox多选下拉框,并且获取选择的值并以","分开. 效果如下: 代码如下: <html> <head> <title> ...
- Extjs4.2 多选下拉框
//多选下拉框 Ext.define('MDM.view.custom.MultiComboBox', { extend: 'Ext.form.ComboBox', alias: 'widget.mu ...
- js:jquery multiSelect 多选下拉框实例
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- DropDownList单选与多选下拉框
一.单选DropDownList传值 1.添加界面的DropDownList显示值问题 (1)在方法内添加ViewData的方法: var ad = new UnitsRepository(); Vi ...
- pentaho cde 自定义复选下拉框 checkbox select
pentaho 自带的component 虽多,但是当用户需要在一个表格中查看多个组别的数据时,pentaho自带的单选框就不能实现了,所以复选下拉框势在必行,实现效果如下: 实现原理是借用了jqu ...
- Bootstrap3级联多选下拉框
<!DOCTYPE html> <html> <head> <title>Bootstrap3级联多选下拉框</title> <met ...
- js怎么能取得多选下拉框选中的多个值?
方法:获取多选下拉框对象数组→循环判断option选项的selected属性(true为选中,false为未选中)→使用value属性取出选中项的值.实例演示如下: 1.HTML结构 1 2 3 4 ...
- js多选下拉框
1.js原生实现 1.1:引用JS文件 /*! jQuery v1.12.4 | (c) jQuery Foundation | jquery.org/license */ !function(a,b ...
- query多选下拉框插件 jquery-multiselect(修改)
其实网上关于该控件的使用教程已经很多了,其中 query多选下拉框插件 jquery-multiselect Jquery多选下拉列表插件jquery multiselect功能介绍及使用 这2个的介 ...
随机推荐
- nodeJS学习(7)--- WS开发 NodeJS 项目-节2 <安装&设置&启动 mongodb 数据库++遇到的问题>
本文系统 win7 参考:http://lib.csdn.net/article/mongodb/58097 http://www.cnblogs.com/lzrabbit/p/3682510.ht ...
- 【jetty】jetty服务器的使用
1.下载jetty服务器: http://www.eclipse.org/jetty/previousversions.html 2.下载后解压:
- CentOS下VNC使用
1. 介绍 本文主要介绍了VNC Server的配置和使用 2. 安装 CentOS中默认就有安装VNC,可以通过命令rpm查看 [Jerry@localhost ~]$ rpm -qa | grep ...
- selenium题
一.selenium中如何判断元素是否存在? 首先selenium里面是没有这个方法的,判断元素存在需要自己写一个方法了. 元素存在有几种形式,一种是页面有多个元素属性重复的,这种直接操作会报错的:还 ...
- hdu 4989(水题)
Summary Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- mysql查询练习题
建库建表 a.建立一个公司数据库(gongsi) CREATE DATABASE gongsi b.建立一张部门表(部门编号b_id,部门名称b_name) , 其中b_ ...
- HDU 5997 rausen loves cakes(启发式合并 + 树状数组统计答案)
题目链接 rausen loves cakes 题意 给出一个序列和若干次修改和查询.修改为把序列中所有颜色为$x$的修改为$y$, 查询为询问当前$[x, y]$对应的区间中有多少连续颜色段. ...
- 洛谷——P2205 [USACO13JAN]画栅栏Painting the Fence
题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of t ...
- ES6十大特性
本文主要针对ES6做一个简要介绍. 主要译自: http://webapplog.com/ES6/comment-page-1/.也许你还不知道ES6是什么, 实际上, 它是一种新的javascri ...
- Win7下搭建外网环境的SVN服务器
最近想跟一帮朋友做点东西,由于几个朋友都身处异地,要想实现版本控制,只能自己搭建一个小的服务器,通过互联网环境来实现版本控制了.本来也在网上找了好多资料,但是总是缺少一些必要的信息,导致最后连接不上服 ...