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的更多相关文章

  1. Easyui-Combobox多选下拉框

    因为工作需要,引入combobox多选下拉框,并且获取选择的值并以","分开. 效果如下: 代码如下: <html> <head> <title> ...

  2. Extjs4.2 多选下拉框

    //多选下拉框 Ext.define('MDM.view.custom.MultiComboBox', { extend: 'Ext.form.ComboBox', alias: 'widget.mu ...

  3. js:jquery multiSelect 多选下拉框实例

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. DropDownList单选与多选下拉框

    一.单选DropDownList传值 1.添加界面的DropDownList显示值问题 (1)在方法内添加ViewData的方法: var ad = new UnitsRepository(); Vi ...

  5. pentaho cde 自定义复选下拉框 checkbox select

    pentaho  自带的component 虽多,但是当用户需要在一个表格中查看多个组别的数据时,pentaho自带的单选框就不能实现了,所以复选下拉框势在必行,实现效果如下: 实现原理是借用了jqu ...

  6. Bootstrap3级联多选下拉框

    <!DOCTYPE html> <html> <head> <title>Bootstrap3级联多选下拉框</title> <met ...

  7. js怎么能取得多选下拉框选中的多个值?

    方法:获取多选下拉框对象数组→循环判断option选项的selected属性(true为选中,false为未选中)→使用value属性取出选中项的值.实例演示如下: 1.HTML结构 1 2 3 4 ...

  8. js多选下拉框

    1.js原生实现 1.1:引用JS文件 /*! jQuery v1.12.4 | (c) jQuery Foundation | jquery.org/license */ !function(a,b ...

  9. query多选下拉框插件 jquery-multiselect(修改)

    其实网上关于该控件的使用教程已经很多了,其中 query多选下拉框插件 jquery-multiselect Jquery多选下拉列表插件jquery multiselect功能介绍及使用 这2个的介 ...

随机推荐

  1. 移动端页面a input去除点击效果及pc端切换

    1 手机端页面a button input去除点击效果以及闪屏问题 添加: a, button, input { -webkit-tap-highlight-color: rgba(255, 0, 0 ...

  2. 【HDOJ5532】Almost Sorted Array(签到)

    题意:给定一个n个数的数列,问删掉一个数之后剩余部分是否可以单调不增或单调不减 n<=1e5,a[i]<=1e5 思路:预处理一下前后缀是否合法 #include<cstdio> ...

  3. 8大排序算法的java实现--做个人收藏

    排序算法分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因为数据量太大,一次不能容纳全部的排序记录,在排序过程中需要访问外存.这里只讨论内部排序,常见的内部排序算法有:插入排序 ...

  4. OS | 死锁

    死锁的四个条件 互斥 占用等待 非剥夺 循环等待 死锁的解决方案 死锁预防 间接预防:防止前三个条件中的任何一个的发生 直接预防:防止循环等待的发生 死锁避免 进程启动拒绝:不启动任何一个可能发生死锁 ...

  5. MariaDB主从复制、主主复制

    1.部署 10.0.0.21  MariaDB-21 10.0.0.22  MariaDB-22 cat /etc/yum.repos.d/mariadb.repo [mariadb] name=Ma ...

  6. BZOJ1457 棋盘游戏

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=1457 这题神奇一些就在于这题的胜利条件不是拿走最后一张牌了而是走到(0,0). 然后就需要 ...

  7. jersey上传文件解决办法

    这两天在使用jersey 构建的jersey JAX-RS REST服务器,在通过POST方法上传文件的时候,如果根据example来操作的话会引发如下异常: SEVERE: Missing depe ...

  8. rails 给类添加属性

    steven@ubuntu:~/RubymineProjects/OAONLINE$ rails generate migration AddPasswordToUsers password:stri ...

  9. Python学习笔记——安装

    最近打算使用下GAE,便准备学习一下python.我对python是一窍不通,因此这里将我的学习历程记录下来,方便后续复习. 安装python: 可以从如下地址:http://www.python.o ...

  10. 轻松加减你的NSDate值

    废话不多,先上github链接:https://github.com/codegefluester/CGFDateModifier 然后上使用方法代码: NSDate *oneWeekFromNow ...