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. 关于微信小程序post请求数据的坑

    在post请求数据的时候,发现数据没有发送给后台,需要在请求头里加"Content-Type": "application/x-www-form-urlencoded&q ...

  2. .Net Framework 4.0: Using System.Lazy<T>

    原文发布时间为:2011-04-26 -- 来源于本人的百度文章 [由搬家工具导入] http://weblogs.asp.net/gunnarpeipman/archive/2009/05/19/n ...

  3. css sticky footer 布局 手机端

    什么是css sticky footer 布局? 通常在手机端写页面 会遇到如下情况 页面长度很短不足以撑起一屏,此时希望页脚在页面的底部 而当页面超过一屏时候,页脚会在文章的底部 ,网上有许多办法, ...

  4. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---32

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  5. 如何得知 GIC 的所有中斷

    can get the supported GIC interrupts from the below adb command, adb root adb shell cat /proc/interr ...

  6. 关于expect脚本输出的问题

    写了一个expect脚本 执行ssh命令远程登录 然后telnet另外一台机器 大致如下: #!/usr/bin/expect -f set timeout set port_type [lindex ...

  7. hdu 3061 hdu 3996 最大权闭合图 最后一斩

    hdu 3061 Battle :一看就是明显的最大权闭合图了,水提......SB题也不说边数多少....因为开始时候数组开小了,WA....后来一气之下,开到100W,A了.. hdu3996. ...

  8. nodejs后台启动

    可避免关闭窗口,程序就关闭,可在后台运行 安装forever包,一般用于服务器,调试环境可不安装 npm install forever -g 启动方式如图: 查询后台运行哪些程序 forever l ...

  9. 过滤器解决hibernate中懒加载问题

    使用过滤器解决懒加载问题需要我们对过滤器的生命周期有深刻的理解 1.浏览器发送一个请求 2.请求通过过滤器执行dofilter之前的代码 3.浏览器通过过滤器到达Servlet(注意我们这里的serv ...

  10. spring-cloud集成mybatis-plus

    mybatis-plus插件是对mybatis做出系列增强插件,后面简称MP,MP可免去开发者重复编写xml.mapper.service.entity等代码,通过MP提供的实体注解来完成单表的CRU ...